private void OnResolvedMessageHandler(ResolvedMessageEventSource source,
                                       QueuedMessageEventArgs e)
 {
     Logger.Debug("[GenericTransportAgent] RoutingAgent - OnResolvedMessage fired...");
     _config.RoutingAgentConfig.OnResolvedMessage.ToList().ForEach(
         x => { try { x.Execute(new EmailItem(e.MailItem)); } catch (Exception ex) { Logger.Error(ex, @"Error Executing ""OnResolvedMessage"""); } });
 }
        private void OnResolvedMessageHandler(ResolvedMessageEventSource source,
                                              QueuedMessageEventArgs e)
        {
            Logger.Debug("[GenericExchangeTransportagent] [RoutingAgent] OnResolvedMessage fired...");
            var emailItem = new EmailItem(e.MailItem);
            _config.RoutingAgentConfig.OnResolvedMessage.ToList().ForEach(
                x => { try { x.Execute(emailItem); } catch (Exception ex) { Logger.Error(ex, @"Error Executing ""OnResolvedMessage"""); } });

            if (emailItem.ShouldBeDeletedFromQueue)
            {
                source.Delete();
            }
        }
예제 #3
0
        private void OnResolvedMessageHandler(ResolvedMessageEventSource source,
                                              QueuedMessageEventArgs e)
        {
            Logger.Debug("[GenericExchangeTransportagent] [RoutingAgent] OnResolvedMessage fired...");
            var emailItem = new EmailItem(e.MailItem);

            _config.RoutingAgentConfig.OnResolvedMessage.ToList().ForEach(
                x => { try { x.Execute(emailItem); } catch (Exception ex) { Logger.Error(ex, @"Error Executing ""OnResolvedMessage"""); } });

            if (emailItem.ShouldBeDeletedFromQueue)
            {
                source.Delete();
            }
        }
예제 #4
0
        private void OnResolvedMessageHandler(ResolvedMessageEventSource source, QueuedMessageEventArgs e)
        {
            Logger.Debug("[GenericTransportAgent] RoutingAgent - OnResolvedMessage fired...");
            var emailItem = new EmailItem(e.MailItem);

            foreach (var x in Configuration.Config.RoutingAgentConfig.OnResolvedMessage)
            {
                try
                {
                    x.Execute(emailItem);
                }
                catch (Exception ex)
                {
                    Logger.Error(ex, @"Error Executing ""OnResolvedMessage""");
                }
            }

            if (emailItem.ShouldBeDeletedFromQueue)
            {
                source.Delete();
            }
        }
예제 #5
0
        void SCPRoutingAgent_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs e)
        {
            try
            {
                WriteLine("Start SCPRoutingAgent_OnResolvedMessage");

                WriteLine("\tFromAddress: " + e.MailItem.FromAddress.ToString());
                WriteLine("\tSubject: " + e.MailItem.Message.Subject.ToString());
                WriteLine("\tMapiMessageClass: " + e.MailItem.Message.MapiMessageClass.ToString());

                MimeDocument mdMimeDoc    = e.MailItem.Message.MimeDocument;
                HeaderList   hlHeaderlist = mdMimeDoc.RootPart.Headers;
                Header       mhProcHeader = hlHeaderlist.FindFirst("X-SCP");

                if (mhProcHeader == null)
                {
                    WriteLine("\tTouched: " + "No");

                    if (!e.MailItem.Message.IsSystemMessage)
                    {
                        bool touched = false;

                        if (e.MailItem.FromAddress.DomainPart != null)
                        {
                            foreach (EnvelopeRecipient recp in e.MailItem.Recipients)
                            {
                                WriteLine("\t\tFrom: " + e.MailItem.Message.From.SmtpAddress.ToString().ToLower());
                                WriteLine("\t\tTo: " + recp.Address.ToString().ToLower());
                                string[] tmpFrom = e.MailItem.Message.From.SmtpAddress.Split('@');
                                string[] tmpTo   = recp.Address.ToString().Split('@');
                                if (IsMessageBetweenTenants(tmpFrom[1].ToLower(), tmpTo[1].ToLower()))
                                {
                                    WriteLine("\t\tMessage routed to domain: " + tmpTo[1].ToLower() + routingDomain);
                                    RoutingDomain   myRoutingDomain   = new RoutingDomain(tmpTo[1].ToLower() + routingDomain);
                                    RoutingOverride myRoutingOverride = new RoutingOverride(myRoutingDomain, DeliveryQueueDomain.UseOverrideDomain);
                                    source.SetRoutingOverride(recp, myRoutingOverride);
                                    touched = true;
                                }
                            }
                        }
                        else
                        {
                            if ((e.MailItem.Message.MapiMessageClass.ToString() == "IPM.Note.Rules.OofTemplate.Microsoft") &
                                blockInternalInterTenantOOF)
                            {
                                WriteLine("\t\tOOF From: " + e.MailItem.Message.From.SmtpAddress);
                                if (e.MailItem.Message.From.SmtpAddress.Contains("@"))
                                {
                                    string[] tmpFrom = e.MailItem.Message.From.SmtpAddress.Split('@');
                                    foreach (EnvelopeRecipient recp in e.MailItem.Recipients)
                                    {
                                        WriteLine("\t\tTo: " + recp.Address.ToString().ToLower());
                                        string[] tmpTo = recp.Address.ToString().Split('@');
                                        if (IsMessageBetweenTenants(tmpFrom[1].ToLower(), tmpTo[1].ToLower()))
                                        {
                                            WriteLine("\t\tRemove: " + tmpTo[1].ToLower());
                                            e.MailItem.Recipients.Remove(recp);
                                        }
                                    }
                                }
                            }
                        }

                        if (touched)
                        {
                            MimeNode   lhLasterHeader = hlHeaderlist.LastChild;
                            TextHeader nhNewHeader    = new TextHeader("X-SCP", "Logged00");
                            hlHeaderlist.InsertBefore(nhNewHeader, lhLasterHeader);
                        }
                    }
                    else
                    {
                        WriteLine("\tSystem Message");
                    }
                }
                else
                {
                    WriteLine("\tTouched: " + "Yes");
                }
            }

            catch (Exception ex)
            {
                WriteLine("\t[Error] Error :" + ex.Message);
                LogErrorToEventLog("[Error] [OnResolvedMessage] Error :" + ex.Message);
            }

            WriteLine("End SCPRoutingAgent_OnResolvedMessage");
        }
예제 #6
0
        void RvScopiaMeeting_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs args){
            this.emailMessage = args.MailItem.Message;

            if (this.emailMessage == null || this.emailMessage.TnefPart == null) {
                return;
            }

            long now = DateTime.UtcNow.Ticks;
            SchedulingInfo schedulingInfo = new SchedulingInfo();
            schedulingInfo.subject = args.MailItem.Message.Subject;
            schedulingInfo.delegatorEmailAddr = args.MailItem.Message.From.NativeAddress;
            RvLogger.DebugWrite("Enter transport agent, from: " + schedulingInfo.delegatorEmailAddr + ", subject: " + schedulingInfo.subject);

            try
            {
                this.agentAsyncContext = this.GetAgentAsyncContext();
                schedulingInfo.requestType = this.getRequestType(this.emailMessage.MapiMessageClass);
                //Reject all meeting type except request and cancel.
                if (RequestType.Other == schedulingInfo.requestType)
                {
                    RvLogger.DebugWrite("Reject other request type: " + this.emailMessage.MapiMessageClass);
                    return;
                }
                RvMailParser parser = new RvMailParser(this);
                try
                {
                    parser.parseTnefSimple(args.MailItem, schedulingInfo);
                }
                catch (Exception exceptionParseMail)
                {
                    RvLogger.DebugWrite("Fail to parse mail.");
                    RvLogger.DebugWrite(exceptionParseMail.Message);
                    RvLogger.DebugWrite(exceptionParseMail.StackTrace);
                    return;
                }
                
                //Reject forwarded appointment
                if (!string.IsNullOrEmpty(schedulingInfo.subjectPrefix) && "FW:".Equals(schedulingInfo.subjectPrefix))
                {
                    RvLogger.DebugWrite("Reject forward request type");
                    return;
                }

                if (schedulingInfo.recurrencePattern != null){
                    schedulingInfo.recurrenceHashInfo = RvScopiaMeeting.getHashString4Str(schedulingInfo.recurrencePattern.getStringForHash());
                    schedulingInfo.recurrencePattern.startDate = schedulingInfo.startDate;
                    schedulingInfo.recurrencePattern.endDate = schedulingInfo.endDate;
                }

                if (null == schedulingInfo.emailMessage) {
                    RvLogger.DebugWrite("null == schedulingInfo.emailMessage================================================");
                    return; 
                }

                if (!isScopia(schedulingInfo))
                {
                    RvLogger.DebugWrite("This is not a SCOPIA meeting");
                    return;
                }

                parseRecipentsChanged(schedulingInfo);
                if (schedulingInfo.isRecipentsChanged)
                    if (schedulingInfo.requestType == RequestType.CancelMeeting)
                    {
                        schedulingInfo.requestType = RequestType.CreateMeeting;
                        schedulingInfo.isAddRecipents = false;
                        schedulingInfo.subject = schedulingInfo.subject.Substring(schedulingInfo.subjectPrefix.Length + 1);
                        Thread.Sleep(HOW_MANY_SECONDS_WAIT_FOR_FOLLOWING_REQUEST * 1000);
                    }else
                        schedulingInfo.isAddRecipents = true;

                if (RvScopiaMeeting.SERVER_ACCOUNT.Equals(schedulingInfo.senderEmailAddr))
                {
                    RvLogger.DebugWrite("Send a email back to notify the sender this mail is failed to send out.");
                    return;
                }

                //when modify a recurrence, to make sure the modified ocurrence request is later than the recurrence request.
                if (schedulingInfo.meetingType == MeetingType.Ocurrence)
                    Thread.Sleep(HOW_MANY_SECONDS_WAIT_FOR_FOLLOWING_REQUEST * 1000);

                icm.XmlApi.scheduleReportType result = changeMail(source, args, schedulingInfo, now);
                if (null != result && result.Success && isCreateMeetingRequest(schedulingInfo))
                {
                    Dictionary<string, byte[]> attachmentsdata = null;
                    if (this.emailMessage.Attachments.Count > 0)
                    {
                        attachmentsdata = new Dictionary<string, byte[]>(this.emailMessage.Attachments.Count);
                        for (int i = 0; i < this.emailMessage.Attachments.Count; i++)
                        {
                            Attachment attachment = this.emailMessage.Attachments[i];
                            Stream readStream = attachment.GetContentReadStream();
                            byte[] bytes = null;
                            if (readStream.Length > 0) {
                                bytes = new byte[readStream.Length];
                                readStream.Read(bytes, 0, bytes.Length);
                            } else
                                bytes = Encoding.ASCII.GetBytes(" ");
                            attachmentsdata.Add(attachment.FileName, bytes);
                        }
                    }
                    
                    parser.changeBodyOfTnef(args.MailItem.Message.TnefPart, schedulingInfo);

                    if (attachmentsdata != null)
                    {
                        foreach (KeyValuePair<string, byte[]> attachmentdata in attachmentsdata)
                        {
                            Attachment attachment = this.emailMessage.Attachments.Add(attachmentdata.Key);
                            Stream attachmentStream = attachment.GetContentWriteStream();
                            attachmentStream.Write(attachmentdata.Value, 0, attachmentdata.Value.Length);
                            attachmentStream.Flush();
                            attachmentStream.Close();
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                RvLogger.DebugWrite(ex.Message);
                RvLogger.DebugWrite(ex.StackTrace);
                string baseFailCode = ex.Message;
                sendBackAMail(source, schedulingInfo, baseFailCode);
            }
            finally
            {
                RvLogger.DebugWrite("Start to agentAsyncContext.Complete()================================================");
                agentAsyncContext.Complete();
                RvLogger.DebugWrite("Complete agentAsyncContext.Complete()================================================");
                RvLogger.DebugWrite("Leave transport agent, from: " + schedulingInfo.delegatorEmailAddr + ", subject: " + schedulingInfo.subject);
            }
        }
예제 #7
0
        void WSPRoutingAgent_OnResolvedMessage(ResolvedMessageEventSource source, QueuedMessageEventArgs e)
        {
            try
            {

                WriteLine("Start WSPRoutingAgent_OnResolvedMessage");

                WriteLine("\tFromAddress: " + e.MailItem.FromAddress.ToString());
                WriteLine("\tSubject: " + e.MailItem.Message.Subject.ToString());
                WriteLine("\tMapiMessageClass: " + e.MailItem.Message.MapiMessageClass.ToString());

                MimeDocument mdMimeDoc = e.MailItem.Message.MimeDocument;
                HeaderList hlHeaderlist = mdMimeDoc.RootPart.Headers;
                Header mhProcHeader = hlHeaderlist.FindFirst("X-WSP");

                if (mhProcHeader == null)
                {
                    WriteLine("\tTouched: " + "No");

                    if (!e.MailItem.Message.IsSystemMessage)
                    {
                        bool touched = false;

                        if (e.MailItem.FromAddress.DomainPart != null)
                        {
                            foreach (EnvelopeRecipient recp in e.MailItem.Recipients)
                            {
                                WriteLine("\t\tFrom: " + e.MailItem.Message.From.SmtpAddress.ToString().ToLower());
                                WriteLine("\t\tTo: " + recp.Address.ToString().ToLower());
                                string[] tmpFrom = e.MailItem.Message.From.SmtpAddress.Split('@');
                                string[] tmpTo = recp.Address.ToString().Split('@');
                                if (IsMessageBetweenTenants(tmpFrom[1].ToLower(), tmpTo[1].ToLower()))
                                {
                                    WriteLine("\t\tMessage routed to domain: " + tmpTo[1].ToLower() + routingDomain);
                                    RoutingDomain myRoutingDomain = new RoutingDomain(tmpTo[1].ToLower() + routingDomain);
                                    RoutingOverride myRoutingOverride = new RoutingOverride(myRoutingDomain, DeliveryQueueDomain.UseOverrideDomain);
                                    source.SetRoutingOverride(recp, myRoutingOverride);
                                    touched = true;
                                }
                            }
                        }
                        else
                        {
                            if ((e.MailItem.Message.MapiMessageClass.ToString() == "IPM.Note.Rules.OofTemplate.Microsoft") &
                                blockInternalInterTenantOOF)
                            {
                                WriteLine("\t\tOOF From: " + e.MailItem.Message.From.SmtpAddress);
                                if (e.MailItem.Message.From.SmtpAddress.Contains("@"))
                                {
                                    string[] tmpFrom = e.MailItem.Message.From.SmtpAddress.Split('@');
                                    foreach (EnvelopeRecipient recp in e.MailItem.Recipients)
                                    {
                                        WriteLine("\t\tTo: " + recp.Address.ToString().ToLower());
                                        string[] tmpTo = recp.Address.ToString().Split('@');
                                        if (IsMessageBetweenTenants(tmpFrom[1].ToLower(), tmpTo[1].ToLower()))
                                        {
                                            WriteLine("\t\tRemove: " + tmpTo[1].ToLower());
                                            e.MailItem.Recipients.Remove(recp);
                                        }
                                    }
                                }
                            }
                        }

                        if (touched)
                        {
                            MimeNode lhLasterHeader = hlHeaderlist.LastChild;
                            TextHeader nhNewHeader = new TextHeader("X-WSP", "Logged00");
                            hlHeaderlist.InsertBefore(nhNewHeader, lhLasterHeader);
                        }
                    }
                    else
                        WriteLine("\tSystem Message");
                }
                else
                    WriteLine("\tTouched: " + "Yes");

            }

            catch (Exception ex)
            {
                WriteLine("\t[Error] Error :" + ex.Message);
                LogErrorToEventLog("[Error] [OnResolvedMessage] Error :" + ex.Message);
            }

            WriteLine("End WSPRoutingAgent_OnResolvedMessage");
        }