Custom Party Resolution BizTalk Server 2006: Resolve party by POP3.From and square brackets

Posted: March 28, 2009  |  Categories: BizTalk Uncategorized

Recently I wrote a BizTalk Server 2006 custom pipeline component to resolve a custom party on the POP3.From context value when an email was received. I was surprised to find some unusual behaviour if the POP3.From context value contained square brackets like “HEWHOCARES [WORLD]” < HEWHOCARES@world.com >. I describe the behaviour and why it occurs below because it took me by surprise.

The base example for the custom pipeline component is based on http://msdn.microsoft.com/en-us/library/aa559134.aspx . The code fragment below shows the important changes;

/// This function gets called after the entire stream of the message has been read, guaranteeing that all promoted properties
        /// from the message have been populated to the message context.
        /// </summary>
        internal void EndOfStream()
        {
            string FromEmail = null;
            BizTalkParty party;

            //obtain the FromEmail string from the message
            FromEmail = (string)mBaseMessage.Context.Read(“From”, “
http://schemas.microsoft.com/BizTalk/2003/pop3-properties”);

            if (FromEmail != null)
            {
                PartyResolver pr = new PartyResolver();
                party = pr.GetPartyFromAlias(“FromEmail”, “FromEmailName”, FromEmail);

                mBaseMessage.Context.Promote(“SourcePartyID”, “http://schemas.microsoft.com/BizTalk/2003/system-properties”, party.SID);
                mBaseMessage.Context.Promote(“PartyName”, “
http://schemas.microsoft.com/BizTalk/2003/messagetracking-properties”, party.Name);
            }
        }

I set up my party like; parties

On testing this pipeline component with an email from “HEWHOCARES” < HEWHOCARES@world.com >   it resolves the party to ThePeopleWhoCare. Now if I change the party value to “HEWHOCARES [WORLD]” < HEWHOCARES@world.com > and send an email from the same email address then it resolves to Guest not ThePeopleWhocare. What is going on? If you dig a bit further you find that to resolve the party this stored procedure is used;

USE [BizTalkMgmtDb]
GO
/****** Object:  StoredProcedure [dbo].[admsvr_GetPartyByAliasNameValue]    Script Date: 03/24/2009 21:16:03 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[admsvr_GetPartyByAliasNameValue]
@nvcAliasName nvarchar(256),
@nvcAliasQualifier nvarchar(64),
@nvcAliasValue nvarchar(256),
@nvcSID nvarchar(256) OUTPUT,
@nvcName nvarchar(256) OUTPUT
AS
SELECT      @nvcSID = bts_party.nvcSID,
            @nvcName = bts_party.nvcName
FROM bts_party, bts_party_alias
WHERE       UPPER(bts_party_alias.nvcName) = UPPER(@nvcAliasName) AND
            UPPER(bts_party_alias.nvcQualifier) = UPPER(@nvcAliasQualifier) AND
           bts_party_alias.nvcValue LIKE @nvcAliasValue  AND
           bts_party_alias.nPartyID = bts_party.nID

The WHERE clause uses a LIKE statement for the criteria based on the passed POP3.FROM context value.  [] in a like statement is evaluated as any single character within the specified range. Thus in our case we try find a party with an FromEmail value of “HEWHOCARES W” < HEWHOCARES@world.com > (or where W” is O”, R”, L” or D”). Indeed if I now change the party value to “HEWHOCARES W” < HEWHOCARES@world.com > then “HEWHOCARES [WORLD]” < HEWHOCARES@world.com > resolves to ThePeopleWhoCare once again.

turbo360

Back to Top