Beispiel #1
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);
 }
Beispiel #2
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)
            {
            }
        }