public static void Run()
        {
            // ExStart:ReadMessagesFromThunderbird

            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Thunderbird();

            // Open the storage file with FileStream
            FileStream stream = new FileStream(dataDir + "ExampleMbox.mbox", FileMode.Open, FileAccess.Read);
            // Create an instance of the MboxrdStorageReader class and pass the stream
            MboxrdStorageReader reader = new MboxrdStorageReader(stream, false);
            // Start reading messages
            MailMessage message = reader.ReadNextMessage();

            // Read all messages in a loop
            while (message != null)
            {
                // Manipulate message - show contents
                Console.WriteLine("Subject: " + message.Subject);
                // Save this message in EML or MSG format
                message.Save(message.Subject + ".eml", SaveOptions.DefaultEml);
                message.Save(message.Subject + ".msg", SaveOptions.DefaultMsgUnicode);

                // Get the next message
                message = reader.ReadNextMessage();
            }
            // Close the streams
            reader.Dispose();
            stream.Close();
            // ExEnd:ReadMessagesFromThunderbird
        }
        public static void Run()
        {
            // ExStart:ReadMessagesFromThunderbird

            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_SMTP();

            // Open the storage file with FileStream
            FileStream stream = new FileStream(dataDir + "Outlook.pst", FileMode.Open, FileAccess.Read);
            // Create an instance of the MboxrdStorageReader class and pass the stream
            MboxrdStorageReader reader = new MboxrdStorageReader(stream, false);
            // Start reading messages
            MailMessage message = reader.ReadNextMessage();

            // Read all messages in a loop
            while (message != null)
            {
                // Manipulate message - show contents
                Console.WriteLine("Subject: " + message.Subject);
                // Save this message in EML or MSG format
                message.Save(message.Subject + ".eml", SaveOptions.DefaultEml);
                message.Save(message.Subject + ".msg", SaveOptions.DefaultMsgUnicode);

                // Get the next message
                message = reader.ReadNextMessage();
            }
            // Close the streams
            reader.Dispose();
            stream.Close();
            // ExEnd:ReadMessagesFromThunderbird
        }
        public static void Run()
        {
            // ExStart: GetMarkerInformation
            // The path to the File directory.
            string dataDir = RunExamples.GetDataDir_Thunderbird();

            using (FileStream stream = new FileStream(dataDir + "ExampleMbox.mbox", FileMode.Open, FileAccess.Read))
                using (MboxrdStorageReader reader = new MboxrdStorageReader(stream, false))
                {
                    MailMessage msg;
                    string      fromMarker = null;
                    while ((msg = reader.ReadNextMessage(out fromMarker)) != null)
                    {
                        Console.WriteLine(fromMarker);

                        msg.Dispose();
                    }
                }

            using (FileStream writeStream = new FileStream(dataDir + "ExampleMbox.mbox", FileMode.Create, FileAccess.Write))
                using (MboxrdStorageWriter writer = new MboxrdStorageWriter(writeStream, false))
                {
                    string      fromMarker = null;
                    MailMessage msg        = MailMessage.Load(dataDir + "EmailWithAttandEmbedded.eml");
                    writer.WriteMessage(msg, out fromMarker);

                    Console.WriteLine(fromMarker);
                }
            // ExEnd: GetMarkerInformation
        }
Beispiel #4
0
        static void Run()
        {
            // ExStart: GetMarkerInformation
            using (FileStream stream = new FileStream("inbox.dat", FileMode.Open, FileAccess.Read))
                using (MboxrdStorageReader reader = new MboxrdStorageReader(stream, false))
                {
                    MailMessage msg;
                    string      fromMarker = null;
                    while ((msg = reader.ReadNextMessage(out fromMarker)) != null)
                    {
                        Console.WriteLine(fromMarker);

                        msg.Dispose();
                    }
                }

            using (FileStream writeStream = new FileStream("inbox.dat", FileMode.Create, FileAccess.Write))
                using (MboxrdStorageWriter writer = new MboxrdStorageWriter(writeStream, false))
                {
                    string      fromMarker = null;
                    MailMessage msg        = MailMessage.Load("input.eml");
                    writer.WriteMessage(msg, out fromMarker);

                    Console.WriteLine(fromMarker);
                }
            // ExEnd: GetMarkerInformation
        }
Beispiel #5
0
        Response ConvertMboxToMht(string fileName, string folderName)
        {
            return(ProcessTask(fileName, folderName, delegate(string inputFilePath, string outputFolderPath)
            {
                // Save as mht with header
                var mhtSaveOptions = new MhtSaveOptions
                {
                    //Specify formatting options required
                    //Here we are specifying to write header informations to output without writing extra print header
                    //and the output headers should display as the original headers in message
                    MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader | MhtFormatOptions.DisplayAsOutlook,
                    // Check the body encoding for validity.
                    CheckBodyContentEncoding = true
                };

                using (var reader = new MboxrdStorageReader(inputFilePath, false))
                {
                    for (int i = 0; i < reader.GetTotalItemsCount(); i++)
                    {
                        var message = reader.ReadNextMessage();
                        message.Save(Path.Combine(outputFolderPath, "Message" + i + ".mht"), mhtSaveOptions);
                    }
                }
            }));
        }
        static void Run()
        { 
            // ExStart: GetMarkerInformation
            using (FileStream stream = new FileStream("inbox.dat", FileMode.Open, FileAccess.Read))
            using (MboxrdStorageReader reader = new MboxrdStorageReader(stream, false))
            {
                MailMessage msg;
                string fromMarker = null;
                while ((msg = reader.ReadNextMessage(out fromMarker)) != null)
                {
                    Console.WriteLine(fromMarker);

                    msg.Dispose();
                }
            }

            using (FileStream writeStream = new FileStream("inbox.dat", FileMode.Create, FileAccess.Write))
            using (MboxrdStorageWriter writer = new MboxrdStorageWriter(writeStream, false))
            {
                string fromMarker = null;
                MailMessage msg = MailMessage.Load("input.eml");
                writer.WriteMessage(msg, out fromMarker);

                Console.WriteLine(fromMarker);
            }
            // ExEnd: GetMarkerInformation
        }
Beispiel #7
0
 ///<Summary>
 /// ConvertMboxToMsg method to convert mbox to msg file
 ///</Summary>
 Response ConvertMboxToMsg(string fileName, string folderName)
 {
     return(ProcessTask(fileName, folderName, delegate(string inputFilePath, string outputFolderPath)
     {
         using (var reader = new MboxrdStorageReader(inputFilePath, false))
         {
             for (int i = 0; i < reader.GetTotalItemsCount(); i++)
             {
                 var message = reader.ReadNextMessage();
                 message.Save(Path.Combine(outputFolderPath, "Message" + i + ".msg"), SaveOptions.DefaultMsgUnicode);
             }
         }
     }));
 }
Beispiel #8
0
        public void Run()
        {
            //ExStart: GetCurrentMessageSize
            string dataDir = RunExamples.GetDataDir_Thunderbird();

            using (FileStream stream = new FileStream(dataDir + "ExampleMbox.mbox", FileMode.Open, FileAccess.Read))
                using (MboxrdStorageReader reader = new MboxrdStorageReader(stream, false))
                {
                    MailMessage msg;
                    while ((msg = reader.ReadNextMessage()) != null)
                    {
                        long currentDataSize = reader.CurrentDataSize;

                        msg.Dispose();
                    }
                }
            //ExEnd: GetCurrentMessageSize
        }
Beispiel #9
0
        Response SaveMboxAsDocument(string fileName, string folderName, SaveFormat format, string saveExtension)
        {
            return(ProcessTask(fileName, folderName, saveExtension, false, false, delegate(string inFilePath, string outPath, string zipOutFolder)
            {
                using (var reader = new MboxrdStorageReader(inFilePath, false))
                {
                    var msgStream = new MemoryStream();

                    for (int i = 0; i < reader.GetTotalItemsCount(); i++)
                    {
                        var message = reader.ReadNextMessage();
                        message.Save(msgStream, SaveOptions.DefaultMhtml);
                    }

                    msgStream.Position = 0;

                    SaveDocumentStreamToFolder(msgStream, inFilePath, Directory.GetParent(outPath).FullName, format);
                }
            }));
        }