Example #1
0
        private Recip AddSecondary(
            string strAddr,
            uint dwAddrProp,
            Recip sourceRecip)
        {
            uint dwNewIdx;

            try
            {
                pRecipsAdd.AddSecondary(
                    1,
                    ref strAddr,
                    ref dwAddrProp,
                    out dwNewIdx,
                    (sourceRecip == null) ? null : sourceRecip.pRecips,
                    (sourceRecip == null) ? 0 : sourceRecip.dwRecipIdx);
            }
            catch (COMException e)
            {
                if (e.ErrorCode != Constants.MAILMSG_E_DUPLICATE)
                {
                    throw;
                }
                throw new DuplicateRecipientException(
                          dwAddrProp,
                          strAddr);
            }

            return(msg.CreateRecipInternal(pRecipsAdd, dwNewIdx));
        }
Example #2
0
 //
 // Add a new (secondary) recipient via their SMTP address.
 // Throws a DuplicateRecipientException if the recipient address
 // is already in mailmsg.
 // Copy over all non-address properties from an existing recipient
 // if sourceRecip is non-null.
 //
 public Recip AddSMTPRecipientSecondary(
     string strSMTPAddress,
     Recip sourceRecip)
 {
     return(AddSecondary(
                strSMTPAddress,
                (uint)IMMPID_RP_ENUM.IMMPID_RP_ADDRESS_SMTP,
                sourceRecip));
 }
Example #3
0
            public bool MoveNext()
            {
                Recip nextRecip = m_msg.GetRecip(m_nPos);

                if (nextRecip != null)
                {
                    m_currentRecip = nextRecip;
                    m_nPos++;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Example #4
0
        //
        // Add a recipient to mailmsg.
        //
        private Recip AddPrimary(
            string strAddr,
            uint dwAddrProp,
            Recip sourceRecip)
        {
            uint dwNewIdx;

            pRecipsAdd.AddPrimary(
                1,
                ref strAddr,
                ref dwAddrProp,
                out dwNewIdx,
                (sourceRecip == null) ? null : sourceRecip.pRecips,
                (sourceRecip == null) ? 0 : sourceRecip.dwRecipIdx);

            return(msg.CreateRecipInternal(pRecipsAdd, dwNewIdx));
        }
Example #5
0
 public bool MoveNext()
 {
     Recip nextRecip = m_msg.GetRecip(m_nPos);
     if(nextRecip != null)
     {
         m_currentRecip = nextRecip;
         m_nPos++;
         return true;
     }
     else
     {
         return false;
     }
 }
Example #6
0
        private Recip AddSecondary(
            string strAddr,
            uint dwAddrProp,
            Recip sourceRecip)
        {
            uint dwNewIdx;

            try
            {
                pRecipsAdd.AddSecondary(
                    1,
                    ref strAddr,
                    ref dwAddrProp,
                    out dwNewIdx,
                    (sourceRecip == null) ? null : sourceRecip.pRecips,
                    (sourceRecip == null) ? 0 : sourceRecip.dwRecipIdx);
            }
            catch(COMException e)
            {
                if(e.ErrorCode != Constants.MAILMSG_E_DUPLICATE)
                    throw;
                throw new DuplicateRecipientException(
                    dwAddrProp,
                    strAddr);
            }

            return msg.CreateRecipInternal(pRecipsAdd, dwNewIdx);
        }
Example #7
0
        //
        // Add a recipient to mailmsg.
        //
        private Recip AddPrimary(
            string strAddr,
            uint dwAddrProp,
            Recip sourceRecip)
        {
            uint dwNewIdx;

            pRecipsAdd.AddPrimary(
                1,
                ref strAddr,
                ref dwAddrProp,
                out dwNewIdx,
                (sourceRecip == null) ? null : sourceRecip.pRecips,
                (sourceRecip == null) ? 0 : sourceRecip.dwRecipIdx);

            return msg.CreateRecipInternal(pRecipsAdd, dwNewIdx);
        }
Example #8
0
 //
 // Add a new (secondary) recipient via their SMTP address.
 // Throws a DuplicateRecipientException if the recipient address
 // is already in mailmsg.
 // Copy over all non-address properties from an existing recipient
 // if sourceRecip is non-null.
 //
 public Recip AddSMTPRecipientSecondary(
     string strSMTPAddress,
     Recip sourceRecip)
 {
     return AddSecondary(
         strSMTPAddress,
         (uint) IMMPID_RP_ENUM.IMMPID_RP_ADDRESS_SMTP,
         sourceRecip);
 }
Example #9
0
        private bool ReRoute(Recip Recipient, Message Msg, RecipsAdd NewRecipients)
        {
            ActiveDirectory Directory = new ActiveDirectory();

            // TODO: verbose logging
            // Console.WriteLine("Searching for " + proxyAddress + " in " + Directory.UsersLDAPPath.ToString() + ".");

            string[] SearcherPropertiesToLoad = {
                "cn",
                "mail",
                "proxyAddresses"
            };

            DirectorySearcher Searcher = new DirectorySearcher(
             new DirectoryEntry(Directory.UsersLDAPPath),
             "(&(objectCategory=person)(objectClass=user)(| (proxyAddresses=*smtp:@" + Recipient.SMTPAddressDomain.ToLower() + "*)(proxyAddresses=*smtp:" + Recipient.SMTPAddress + "*)))",
             SearcherPropertiesToLoad);

            SearchResultCollection SearchResults = Searcher.FindAll();

            if (SearchResults.Count == 0)
                return false;

            foreach (SearchResult SearchResult in SearchResults)
            {
                foreach (string ProxyAddressProperty in SearchResult.Properties["proxyAddresses"])
                {
                    string ProxyAddress = ProxyAddressProperty.ToLower();
                    if ("smtp:" + Recipient.SMTPAddress.ToLower() == ProxyAddress)
                    {
                        // there's an address that matches exactly, add him to the re-routing
                        // list because there might be other recipients that don't match and
                        // will require routing
                        NewRecipients.AddSMTPRecipient(Recipient.SMTPAddress, null);
                        return false;
                    }
                }
            }

            foreach (SearchResult SearchResult in SearchResults)
            {
                foreach (string ProxyAddressProperty in SearchResult.Properties["proxyAddresses"])
                {
                    string ProxyAddress = ProxyAddressProperty.ToLower();

                    // this is necessary to avoid matching @foo.com with @foo.com.bar
                    if ("smtp:@" + Recipient.SMTPAddressDomain.ToLower() == ProxyAddress)
                    {
                        string RoutedSMTPAddress = SearchResult.Properties["mail"][0].ToString();

                        EventLog.WriteEntry(
                         Assembly.GetExecutingAssembly().FullName,
                         "Routing message " + Msg.Rfc822MsgId + " from " + Recipient.SMTPAddress + " to " + RoutedSMTPAddress + ".",
                         EventLogEntryType.Information);

                        NewRecipients.AddSMTPRecipient(RoutedSMTPAddress, null);
                        return true;
                    }
                }
            }

            return false;
        }