Пример #1
0
 private static void WriteHeaderToFile(FileStream file, string header, string content)
 {
     byte[] bytes = CTSGlobals.AsciiEncoding.GetBytes(MessageSnapshotWriter.Rfc2047Encode(header + ": " + content));
     file.Write(bytes, 0, bytes.Length);
     file.WriteByte(13);
     file.WriteByte(10);
 }
Пример #2
0
 private static void WriteInjectedHeadersToFile(FileStream file, string id, string topic, string agent, string sender, IEnumerable <string> receivers, string messageState)
 {
     MessageSnapshotWriter.WriteBeginningHeadersToFile(file, id, topic, agent, messageState);
     if (sender != null)
     {
         MessageSnapshotWriter.WriteSenderHeaderToFile(file, sender);
     }
     if (receivers != null)
     {
         foreach (string address in receivers)
         {
             MessageSnapshotWriter.WriteReceiverHeaderToFile(file, address);
         }
     }
     MessageSnapshotWriter.WriteEndHeadersToFile(file);
 }
Пример #3
0
        private void WriteMessageToFile(FileStream file, string id, string topic, string agent, MailItem mailItem)
        {
            if (mailItem.HasBeenDeferred || mailItem.HasBeenDeleted)
            {
                MessageSnapshotWriter.WriteInjectedHeadersToFile(file, id, topic, agent, null, null, mailItem.HasBeenDeferred ? "Deferred" : "Deleted");
                return;
            }
            string[] array = new string[mailItem.Recipients.Count];
            int      num   = 0;

            foreach (EnvelopeRecipient envelopeRecipient in mailItem.Recipients)
            {
                array[num++] = envelopeRecipient.Address.ToString();
            }
            MessageSnapshotWriter.WriteInjectedHeadersToFile(file, id, topic, agent, mailItem.FromAddress.ToString(), array);
            mailItem.MimeDocument.RootPart.WriteTo(file);
        }
Пример #4
0
        private static void WriteBeginningHeadersToFile(FileStream file, string id, string topic, string agent, string messageState)
        {
            StringBuilder stringBuilder = new StringBuilder(512);

            stringBuilder.Append("X-CreatedBy: MessageSnapshot-Begin injected headers\r\n");
            stringBuilder.Append("X-MessageSnapshot-UTC-Time: ");
            stringBuilder.Append(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ", CultureInfo.InvariantCulture));
            stringBuilder.Append("\r\n");
            if (topic == "OnSubmittedMessage" || topic == "OnRoutedMessage" || topic == "OnResolvedMessage" || topic == "OnCategorizedMessage")
            {
                stringBuilder.Append("X-MessageSnapshot-Record-Id: ");
            }
            else
            {
                stringBuilder.Append("X-MessageSnapshot-Protocol-Id: ");
            }
            stringBuilder.Append(id);
            stringBuilder.Append("\r\n");
            if (agent == null)
            {
                stringBuilder.Append("X-MessageSnapshot-Source: Original\r\n");
            }
            else
            {
                string format = (agent.Length == 0) ? "X-MessageSnapshot-Source: {0}" : "X-MessageSnapshot-Source: {0},{1}";
                string value  = string.Format(CultureInfo.InvariantCulture, format, new object[]
                {
                    topic,
                    agent
                });
                stringBuilder.Append(MessageSnapshotWriter.Rfc2047Encode(value));
                stringBuilder.Append("\r\n");
            }
            if (!string.IsNullOrEmpty(messageState))
            {
                stringBuilder.AppendFormat("X-MessageSnapshot-MessageStatus: {0}\r\n", messageState);
            }
            byte[] bytes = CTSGlobals.AsciiEncoding.GetBytes(stringBuilder.ToString());
            file.Write(bytes, 0, bytes.Length);
        }
Пример #5
0
        public override void WriteOriginalData(int agentId, string id, string topic, string address, MailItem mailItem)
        {
            if (this.state.IsOriginalWritten || (this.state.OriginalWriterAgentId != null && agentId != this.state.OriginalWriterAgentId))
            {
                return;
            }
            FileMode fileMode = FileMode.Append;

            if (this.state.OriginalWriterAgentId == null)
            {
                this.state.OriginalWriterAgentId = new int?(agentId);
                fileMode = FileMode.Create;
            }
            string pipelineTracingPath = mailItem.PipelineTracingPath;

            if (string.IsNullOrEmpty(pipelineTracingPath))
            {
                return;
            }
            string snapshotFolder           = this.GetSnapshotFolder(pipelineTracingPath);
            string originalSnapshotFileName = this.GetOriginalSnapshotFileName(snapshotFolder);

            try
            {
                this.EnsureSnapshotFolderCreated(snapshotFolder);
                using (FileStream fileStream = new FileStream(originalSnapshotFileName, fileMode, FileAccess.Write, FileShare.None))
                {
                    if (topic == "OnRcptCommand")
                    {
                        if (fileMode == FileMode.Create)
                        {
                            MessageSnapshotWriter.WriteBeginningHeadersToFile(fileStream, id, topic, null);
                            MessageSnapshotWriter.WriteSenderHeaderToFile(fileStream, mailItem.FromAddress.ToString());
                        }
                        MessageSnapshotWriter.WriteReceiverHeaderToFile(fileStream, address);
                    }
                    else if (topic == "OnEndOfHeaders")
                    {
                        MessageSnapshotWriter.WriteEndHeadersToFile(fileStream);
                        this.WriteMessageHeadersToFile(fileStream, mailItem);
                    }
                    else if (topic == "OnEndOfData")
                    {
                        this.AppendBodyToFile(fileStream, mailItem);
                        this.state.IsOriginalWritten = true;
                    }
                    else if (topic == "OnSubmittedMessage")
                    {
                        this.WriteMessageToFile(fileStream, id, topic, null, mailItem);
                        this.state.IsOriginalWritten = true;
                    }
                }
            }
            catch (IOException)
            {
            }
            catch (UnauthorizedAccessException)
            {
            }
            catch (SecurityException)
            {
            }
        }
Пример #6
0
 private static void WriteInjectedHeadersToFile(FileStream file, string id, string topic, string agent, string sender, IEnumerable <string> receivers)
 {
     MessageSnapshotWriter.WriteInjectedHeadersToFile(file, id, topic, agent, sender, receivers, null);
 }
Пример #7
0
 private static void WriteReceiverHeaderToFile(FileStream file, string address)
 {
     MessageSnapshotWriter.WriteHeaderToFile(file, "X-Receiver", address);
 }
Пример #8
0
 private static void WriteBeginningHeadersToFile(FileStream file, string id, string topic, string agent)
 {
     MessageSnapshotWriter.WriteBeginningHeadersToFile(file, id, topic, agent, null);
 }