示例#1
0
文件: Sink.cs 项目: dblock/domainmail
        void IMailTransportSubmission.OnMessageSubmission(
            MailMsg message,
            IMailTransportNotify notify,
            IntPtr context)
        {
            try
            {
                Message Msg = new Message(message);

                if (Debug)
                {
                    EventLog.WriteEntry(
                     Assembly.GetExecutingAssembly().FullName,
                     "Checking message " + Msg.Rfc822MsgId + " with subject \"" + Msg.Rfc822MsgSubject + "\".",
                     EventLogEntryType.Information);
                }

                RecipsAdd NewRecipients = Msg.AllocNewList();
                bool fReRouted = false;

                foreach (Recip Recipient in Msg.Recips)
                {
                    try
                    {
                        fReRouted |= ReRoute(Recipient, Msg, NewRecipients);
                    }
                    catch (Exception ex)
                    {
                        EventLog.WriteEntry(
                         Assembly.GetExecutingAssembly().FullName,
                         "Error routing message " + Msg.Rfc822MsgId + " to " + Recipient.SMTPAddress + "." + ex.Message,
                         EventLogEntryType.Error);
                    }
                }

                if (fReRouted)
                {
                    Msg.WriteList(NewRecipients);
                }

            }
            catch (Exception ex)
            {
                EventLog.WriteEntry(
                  Assembly.GetExecutingAssembly().FullName,
                  ex.Message + "\n" + ex.StackTrace.ToString(),
                  EventLogEntryType.Error);
            }
            finally
            {
                if (null != message)
                    Marshal.ReleaseComObject(message);
            }
        }
示例#2
0
文件: Sink.cs 项目: dblock/sncore
        //static void s_ConfigurationChangeWatcher_Changed(object sender, FileSystemEventArgs e)
        //{
        //    Configure(e.FullPath);
        //}

        void IMailTransportSubmission.OnMessageSubmission(
             MailMsg mailmsg,
             IMailTransportNotify notify,
             IntPtr context)
        {
            LogDebug("Invoking mail sink message submission callback.");

            try
            {
                Message message = new Message(mailmsg);
                LogDebug(string.Format("Processing message \"{0}\" ({1} byte(s)).", message.Rfc822MsgSubject, message.GetContentSize()));
                byte[] content = message.ReadContent(0, message.GetContentSize());
                string filename = s_QueuePath + "\\" + message.Rfc822MsgId;
                filename = filename.Replace("<", "_").Replace(">", "_").Replace(" ", "_");
                LogDebug(string.Format("Dumping message \"{0}\" to {1}.", message.Rfc822MsgSubject, filename));
                File.WriteAllBytes(filename, content);
            }
            catch (Exception ex)
            {
                LogError(ex.Message + "\n" + ex.StackTrace.ToString());
            }
            finally
            {
                if (null != mailmsg)
                {
                    Marshal.ReleaseComObject(mailmsg);
                }
            }
        }
示例#3
0
 public RecipEnumerator(Message msg)
 {
     m_msg = msg;
 }
示例#4
0
 internal RecipCollection(Message msg)
 {
     this.msg = msg;
 }
示例#5
0
 public void RebindAfterFork(
     Message msgOrig,
     object storeDriver)
 {
     pMsg.RebindAfterFork(
         (MailMsg) msgOrig.pMsg,
         storeDriver);
 }
示例#6
0
        public void ForkForRecipients(
            out Message msgNew,
            out RecipsAdd recipsAddNew)
        {
            MailMsg pMsgNew;
            IMailMsgRecipientsAdd pRecipsAddNew;

            pMsg.ForkForRecipients(
                out pMsgNew,
                out pRecipsAddNew);

            msgNew = new Message(pMsgNew);
            recipsAddNew = new RecipsAdd(this, pRecipsAddNew);
        }
示例#7
0
 internal RecipsAdd(
     Message msg,
     IMailMsgRecipientsAdd pRecipsAdd)
 {
     this.msg = msg;
     this.pRecipsAdd = pRecipsAdd;
 }
示例#8
0
文件: Sink.cs 项目: dblock/domainmail
        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;
        }