Esempio n. 1
0
        public static void MergePSTFiles(string pstFilename1, string pstFilename2, string mergedFilename = null,
                                         string duplicatesFilename1 = null, string duplicatesFilename2 = null, bool saveDuplicates = true,
                                         string[] foldersToIgnore   = null)
        {
            Console.WriteLine(String.Format("Loading and Merging PST Files - file1: '{0}' into file2: '{1}'", pstFilename1, pstFilename2));

            //Get PST 1
            PSTFile pstFile1 = new PSTFile(pstFilename1, "PST1");


            //Get PST 2
            PSTFile pstFile2 = new PSTFile(pstFilename2, "PST2");

            //Merge PST files
            MergePSTFiles(pstFile1, pstFile2, mergedFilename, duplicatesFilename1, duplicatesFilename2, saveDuplicates, foldersToIgnore);
        }
Esempio n. 2
0
        public void SaveDuplicatesToFile(string pstFilename,
                                         string pstName         = "DuplicateEmails",
                                         string duplicateFolder = "Duplicates",
                                         string originalFolder  = "Originals")
        {
            Console.WriteLine("Saving duplicates to file: '" + pstFilename + "'");
            PSTFile pstDuplicates = new PSTFile(pstFilename, pstName);

            if (duplicateFolder != "" && DuplicateMailItems.Any())
            {
                pstDuplicates.AddMailItems(DuplicateMailItems.Select(mailItem => mailItem.Value.MailObject).ToList(), duplicateFolder);
            }
            if (originalFolder != "" && OriginalMailItems.Any())
            {
                pstDuplicates.AddMailItems(OriginalMailItems.Select(mailItem => mailItem.Value.MailObject).ToList(), originalFolder);
            }
        }
Esempio n. 3
0
        public static void MergePSTFiles(PSTFile pstFile1, PSTFile pstFile2, string mergedFilename = null,
                                         string duplicatesFilename1 = null, string duplicatesFilename2 = null, bool saveDuplicates = true,
                                         string[] foldersToIgnore   = null)
        {
            Console.WriteLine(String.Format("Merging PSTFile Objects - file1: '{0}' into file2: '{1}'", pstFile1.PSTName, pstFile2.PSTName));

            //Get PST 1
            pstFile1.GetMailItems(true, foldersToIgnore);
            //Extract duplicates
            if (saveDuplicates && pstFile1.DuplicateMailItems.Any())
            {
                duplicatesFilename1 = duplicatesFilename1 ?? pstFile1.GetPSTFileDirectory() + "duplicates_" + pstFile1.GetPSTFilename();
                pstFile1.SaveDuplicatesToFile(duplicatesFilename1, "DuplicatesIn1");
            }

            //Get PST 2
            pstFile2.GetMailItems(true, foldersToIgnore);
            //Extract Duplicates
            if (saveDuplicates && pstFile2.DuplicateMailItems.Any())
            {
                duplicatesFilename2 = duplicatesFilename2 ?? pstFile1.GetPSTFileDirectory() + "duplicates_" + pstFile1.GetPSTFilename();
                pstFile2.SaveDuplicatesToFile(duplicatesFilename2, "DuplicatesIn2");
            }

            // In 2 Not in 1
            List <PSTFile.MailItemObject> mailIn2NotIn1 = ComparePSTFiles(pstFile1, pstFile2, PSTFile.MailCompareType.In2NotIn1);

            //Merge into new PST file
            if (mergedFilename != null && mergedFilename != pstFile1.PSTFilePath)
            {
                PSTFile mergedPSTFile = new PSTFile(mergedFilename, "Merged");
                mergedPSTFile.AddMailItems(pstFile1.GetAllMailItems());
                if (mailIn2NotIn1.Any())
                {
                    mergedPSTFile.AddMailItems(mailIn2NotIn1);
                }
            }
            //Merge 2 into 1...
            else if (mergedFilename == null || mergedFilename == pstFile1.PSTFilePath)
            {
                if (mailIn2NotIn1.Any())
                {
                    pstFile1.AddMailItems(mailIn2NotIn1);
                }
            }
        }
Esempio n. 4
0
        public static List <MailItemObject> ComparePSTFiles(PSTFile pstFile1,
                                                            PSTFile pstFile2,
                                                            MailCompareType compareType = MailCompareType.In1NotIn2)
        {
            List <MailItemObject> compareRes = new List <MailItemObject>();

            switch (compareType)
            {
            case MailCompareType.In1NotIn2:
                foreach (KeyValuePair <string, MailItemObject> mailItem in pstFile1.AllMailItems)
                {
                    if (!pstFile2.AllMailItems.ContainsKey(mailItem.Key))
                    {
                        compareRes.Add(mailItem.Value);
                    }
                }
                break;

            case MailCompareType.In2NotIn1:
                foreach (KeyValuePair <string, MailItemObject> mailItem in pstFile2.AllMailItems)
                {
                    if (!pstFile1.AllMailItems.ContainsKey(mailItem.Key))
                    {
                        compareRes.Add(mailItem.Value);
                    }
                }
                break;

            case MailCompareType.InBoth:
                foreach (KeyValuePair <string, MailItemObject> mailItem in pstFile1.AllMailItems)
                {
                    if (pstFile2.AllMailItems.ContainsKey(mailItem.Key))
                    {
                        compareRes.Add(mailItem.Value);
                    }
                }
                break;
            }
            return(compareRes);
        }
Esempio n. 5
0
 public List <MailItemObject> ComparePSTFiles(PSTFile pstFile2,
                                              MailCompareType compareType = MailCompareType.In1NotIn2)
 {
     return(ComparePSTFiles(this, pstFile2, compareType));
 }