Beispiel #1
0
        public static bool TryParseSmtpResponseString(string lastErrorDetailsString, out string smtpResponse)
        {
            SmtpResponse smtpResponse2;

            if (SmtpResponse.TryParse(lastErrorDetailsString, out smtpResponse2))
            {
                smtpResponse = lastErrorDetailsString;
                return(true);
            }
            return(LastError.TryParseSubstring(lastErrorDetailsString, "LED", out smtpResponse));
        }
 private static RecipientTrackingEvent.FormatterMethod FailedGeneralDelegate()
 {
     return(delegate(RecipientTrackingEvent.FormatterSource source, string[] args)
     {
         if (args != null && args.Length > 0)
         {
             string text;
             if (!LastError.TryParseSmtpResponseString(args[0], out text))
             {
                 text = args[0];
             }
             SmtpResponse key;
             if (SmtpResponse.TryParse(text, out key))
             {
                 if (key.SmtpResponseType == SmtpResponseType.PermanentError && args.Length >= 2 && string.Equals(args[1], "Content Filter Agent"))
                 {
                     return CoreStrings.RejectedExplanationContentFiltering;
                 }
                 LocalizedString result;
                 if (AckReason.EnhancedTextGetter.TryGetValue(key, out result))
                 {
                     return result;
                 }
                 if (!string.IsNullOrEmpty(key.EnhancedStatusCode))
                 {
                     if (DsnShortMessages.TryGetResourceRecipientExplanation(key.EnhancedStatusCode, out result))
                     {
                         return result;
                     }
                     LocalizedString?customDsnCode = RecipientTrackingEvent.GetCustomDsnCode(key.EnhancedStatusCode, source.ConfigSession, source.UserLanguages);
                     if (customDsnCode != null)
                     {
                         return customDsnCode.Value;
                     }
                 }
             }
         }
         return CoreStrings.EventFailedGeneral;
     });
 }
Beispiel #3
0
        protected override void InternalProcessRecord()
        {
            int           num           = 0;
            AgentLogEntry agentLogEntry = null;

            while (this.OpenNextFile())
            {
                try
                {
                    int num2 = 0;
                    while (!this.reader.EndOfStream)
                    {
                        string text = this.reader.ReadLine();
                        num2++;
                        try
                        {
                            if (!this.IsHeader(text))
                            {
                                string[] array = this.SplitFields(text);
                                if (num > 0)
                                {
                                    agentLogEntry.Recipients.Add(new AgentLogEntry.RoutingAddressWrapper((RoutingAddress)array[8]));
                                    num--;
                                    if (num == 0)
                                    {
                                        base.WriteObject(agentLogEntry);
                                    }
                                }
                                else
                                {
                                    DateTime dateTime = DateTime.Parse(array[0], DateTimeFormatInfo.InvariantInfo);
                                    if (this.IsInRange(dateTime))
                                    {
                                        agentLogEntry           = new AgentLogEntry();
                                        agentLogEntry.Timestamp = dateTime;
                                        agentLogEntry.SessionId = array[1];
                                        if (!string.IsNullOrEmpty(array[4]))
                                        {
                                            agentLogEntry.IPAddress = IPAddress.Parse(array[4]);
                                        }
                                        agentLogEntry.MessageId       = array[5];
                                        agentLogEntry.P1FromAddress   = new AgentLogEntry.RoutingAddressWrapper((RoutingAddress)array[6]);
                                        agentLogEntry.P2FromAddresses = this.ParseP2From(array[7]);
                                        agentLogEntry.Agent           = array[10];
                                        agentLogEntry.Event           = array[11];
                                        agentLogEntry.Action          = (AgentAction)Enum.Parse(typeof(AgentAction), array[12]);
                                        if (!string.IsNullOrEmpty(array[13]) && !SmtpResponse.TryParse(array[13], out agentLogEntry.SmtpResponse))
                                        {
                                            this.WriteError(new ArgumentException(Strings.AgentLogInvalidSmtpResponse(num2, this.GetCurrentFilePath()), "smtpResponse"), ErrorCategory.InvalidArgument, null, false);
                                        }
                                        else
                                        {
                                            agentLogEntry.Reason     = array[14];
                                            agentLogEntry.ReasonData = array[15];
                                            if (array.Length > 16)
                                            {
                                                agentLogEntry.Diagnostics = array[16];
                                            }
                                            if (array.Length > 17)
                                            {
                                                Guid.TryParse(array[17], out agentLogEntry.NetworkMsgID);
                                            }
                                            if (array.Length > 18)
                                            {
                                                Guid.TryParse(array[18], out agentLogEntry.TenantID);
                                            }
                                            if (array.Length > 19)
                                            {
                                                agentLogEntry.Directionality = array[19];
                                            }
                                            num = int.Parse(array[9], NumberFormatInfo.InvariantInfo);
                                            agentLogEntry.Recipients = new List <AgentLogEntry.RoutingAddressWrapper>(num);
                                            if (num > 0)
                                            {
                                                string   text2  = array[8];
                                                string[] array2 = text2.Split(new char[]
                                                {
                                                    ';'
                                                });
                                                if (array2.Length != num && array2.Length != 1)
                                                {
                                                    throw new FormatException("Invalid log format, the recipient count field does not match the actual number of recipients found");
                                                }
                                                num -= array2.Length;
                                                foreach (string address in array2)
                                                {
                                                    agentLogEntry.Recipients.Add(new AgentLogEntry.RoutingAddressWrapper((RoutingAddress)address));
                                                }
                                                if (num > 0)
                                                {
                                                    continue;
                                                }
                                            }
                                            base.WriteObject(agentLogEntry);
                                        }
                                    }
                                }
                            }
                        }
                        catch (ArgumentException e)
                        {
                            this.WriteError(this.CreateEntryException(e, num2), ErrorCategory.InvalidData, text, false);
                        }
                        catch (FormatException e2)
                        {
                            this.WriteError(this.CreateEntryException(e2, num2), ErrorCategory.InvalidData, text, false);
                        }
                        catch (OverflowException e3)
                        {
                            this.WriteError(this.CreateEntryException(e3, num2), ErrorCategory.InvalidData, text, false);
                        }
                        catch (IndexOutOfRangeException e4)
                        {
                            this.WriteError(this.CreateEntryException(e4, num2), ErrorCategory.InvalidData, text, false);
                        }
                    }
                }
                finally
                {
                    if (this.reader != null)
                    {
                        this.reader.Close();
                        this.reader = null;
                    }
                }
            }
        }
Beispiel #4
0
        public bool GetRecipientStatus(long internalId, string messageId, string recipientAddress, out RecipientStatus?status, out string lastError, out DateTime?lastRetry, out DateTime?nextRetry, out string queueName, out bool isUnreachable)
        {
            status        = null;
            lastError     = null;
            lastRetry     = null;
            nextRetry     = null;
            queueName     = null;
            isUnreachable = true;
            ExtensibleMessageInfo[] messageInfo = this.GetMessageInfo(internalId);
            if (messageInfo == null || messageInfo.Length == 0)
            {
                TraceWrapper.SearchLibraryTracer.TraceDebug <long>(this.GetHashCode(), "No results found for message internal ID: {0}", internalId);
                return(false);
            }
            ExtensibleMessageInfo extensibleMessageInfo = null;

            for (int i = 0; i < messageInfo.Length; i++)
            {
                string internetMessageId = messageInfo[i].InternetMessageId;
                if (string.IsNullOrEmpty(internetMessageId) || !internetMessageId.Equals(messageId) || messageInfo[i].Recipients == null)
                {
                    TraceWrapper.SearchLibraryTracer.TraceError <string, string>(this.GetHashCode(), "Message-IDs did not match, Task: {0}, Queues: {1}", messageId, internetMessageId);
                }
                else
                {
                    foreach (RecipientInfo recipientInfo in messageInfo[i].Recipients)
                    {
                        if (recipientInfo.Address.Equals(recipientAddress))
                        {
                            lastError             = recipientInfo.LastError;
                            status                = new RecipientStatus?(recipientInfo.Status);
                            extensibleMessageInfo = messageInfo[i];
                            break;
                        }
                    }
                }
            }
            if (extensibleMessageInfo == null)
            {
                TraceWrapper.SearchLibraryTracer.TraceError(this.GetHashCode(), "Message did not match", new object[0]);
                return(false);
            }
            if (string.IsNullOrEmpty(lastError))
            {
                lastError = extensibleMessageInfo.LastError;
            }
            QueueIdentity queue = extensibleMessageInfo.Queue;

            ExtensibleQueueInfo[] queueInfo = this.GetQueueInfo(queue);
            if (queueInfo == null || queueInfo.Length != 1)
            {
                TraceWrapper.SearchLibraryTracer.TraceError <QueueIdentity>(this.GetHashCode(), "No queue found with ID: {0}", queue);
                return(false);
            }
            queueName     = queueInfo[0].Identity.ToString();
            isUnreachable = (queueInfo[0].DeliveryType == DeliveryType.Unreachable);
            SmtpResponse smtpResponse;

            if (string.IsNullOrEmpty(lastError) || (SmtpResponse.TryParse(lastError, out smtpResponse) && smtpResponse.SmtpResponseType == SmtpResponseType.Success))
            {
                lastError = queueInfo[0].LastError;
            }
            if (status == null && (queueInfo[0].Status == QueueStatus.Retry || queueInfo[0].Status == QueueStatus.Suspended))
            {
                status = new RecipientStatus?(RecipientStatus.Retry);
            }
            lastRetry = queueInfo[0].LastRetryTime;
            nextRetry = queueInfo[0].NextRetryTime;
            return(true);
        }
        protected override void InternalProcessRecord()
        {
            if (this.probeGuid == Guid.Empty)
            {
                this.probeGuid = Guid.NewGuid();
            }
            SystemProbeMailProperties systemProbeMailProperties = new SystemProbeMailProperties();

            systemProbeMailProperties.Guid = this.ProbeGuid;
            try
            {
                SmtpTalk smtpTalk = new SmtpTalk(new SendSystemProbeEmail.SmtpClientDebugOutput(this));
                smtpTalk.Connect(this.smtpServer, this.port ?? 25);
                smtpTalk.Ehlo();
                SmtpResponse ehloResponse;
                if (SmtpResponse.TryParse(smtpTalk.EhloResponseText, out ehloResponse))
                {
                    this.ehloOptions.ParseResponse(ehloResponse, new IPAddress(0L));
                }
                if (this.UseSsl)
                {
                    smtpTalk.StartTls(true);
                    smtpTalk.Ehlo();
                }
                if (!string.IsNullOrEmpty(this.smtpUser))
                {
                    smtpTalk.Authenticate(new NetworkCredential(this.smtpUser, this.smtpPassword), SmtpSspiMechanism.Kerberos);
                }
                else if (this.UseSsl)
                {
                    smtpTalk.Authenticate(CredentialCache.DefaultNetworkCredentials, SmtpSspiMechanism.Kerberos);
                }
                if (this.ehloOptions.XSysProbe)
                {
                    base.WriteVerbose(Strings.SendingGuidInMailFrom);
                    smtpTalk.MailFrom(string.Format(CultureInfo.InvariantCulture, "{0} xsysprobeid={1}", new object[]
                    {
                        this.from,
                        this.probeGuid.ToString()
                    }), null);
                }
                else
                {
                    smtpTalk.MailFrom(this.from, null);
                }
                this.to.ForEach(delegate(string to)
                {
                    smtpTalk.RcptTo(to, new bool?(false));
                });
                string text = Path.Combine(Path.GetTempPath(), this.probeGuid.ToString());
                if (!Directory.Exists(text))
                {
                    Directory.CreateDirectory(text);
                }
                List <string> list = new List <string>(Directory.GetFiles(text, "*.eml"));
                list.ForEach(delegate(string f)
                {
                    File.Delete(f);
                });
                MailMessage message = this.CreateMailMessage();
                using (SmtpClient smtpClient = new SmtpClient(this.smtpServer))
                {
                    smtpClient.DeliveryMethod          = SmtpDeliveryMethod.SpecifiedPickupDirectory;
                    smtpClient.PickupDirectoryLocation = text;
                    smtpClient.Send(message);
                }
                list = new List <string>(Directory.GetFiles(text, "*.eml"));
                if (list.Count != 1)
                {
                    throw new Exception("Unexpected number of files in private pickup folder");
                }
                using (FileStream fileStream = File.OpenRead(list[0]))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        fileStream.CopyTo(memoryStream);
                        memoryStream.Position = 0L;
                        smtpTalk.Chunking(memoryStream);
                    }
                }
                if (this.testContext)
                {
                    systemProbeMailProperties.MailMessage = list[0];
                }
                else
                {
                    try
                    {
                        Directory.Delete(text, true);
                    }
                    catch (IOException ex)
                    {
                        base.WriteWarning(ex.Message);
                    }
                }
                try
                {
                    smtpTalk.Quit();
                }
                catch (SocketException)
                {
                }
                catch (IOException)
                {
                }
            }
            catch (MustBeTlsForAuthException ex2)
            {
                base.WriteWarning(ex2.Message);
            }
            catch (UnexpectedSmtpServerResponseException ex3)
            {
                base.WriteWarning(ex3.Message);
            }
            base.WriteObject(systemProbeMailProperties);
        }