Beispiel #1
0
        public void Get(string paramOne)
        {
            if (paramOne.ToLower() == "reset")
            {
                Log.Append("GET - Reset Email Sync Parameters");
                Global.isSyncing = false;
                Readiness.DeleteBlockerFile();
            }

            //if (!Permissions.ValidAPIKey(APIKey)) return new Email[] {};
            paramOne = AESGCM.SimpleDecryptWithPassword(paramOne.Replace("_", "/").Replace("-", "+"), AESGCM.AES256Key);

            if (paramOne.ToLower() == "sync")
            {
                Log.Append("GET - Sync PST Files");
                PSTImporter.SyncPSTFiles();
            }
            if (paramOne.ToLower() == "validate")
            {
                Log.Append("GET - Validating email and file integrity");
                Task.Run(() => Global.ValidateMessages());
            }
            if (paramOne.ToLower() == "refresh")
            {
                Log.Append("GET - Refresh Email List requested");
                // Reload settings before getting emails
                Global.LoadSettings();
                EmailRepository.CacheInfo(Global.GetAllEmails().ToArray());
            }
            //return new Email[] { };
        }
Beispiel #2
0
        // ==========================================================================================
        // =====================================[ EMAILS ]===========================================
        // ==========================================================================================

        public static List <Email> GetAllEmails(bool forceUpdate = false)
        {
            #if DEBUG
            Readiness.DeleteBlockerFile();
            #endif

            Log.Append("Pulling emails from email servers...");

            TimeSpan startTime = DateTime.Now.TimeOfDay;

            List <Email> newEmails = new List <Email>();

            if (isSyncing || !Readiness.EmailSyncReady())
            {
                Log.Append("ERROR: Existing sync in progress");

                return(new List <Email>());
            }

            Readiness.CreateBlockerFile();

            // If force update, set last update time to new DateTime (year = 1800)
            if (forceUpdate)
            {
                UserList.ForEach(x => x.LastUpdateTime = new DateTime());
            }

            foreach (User user in UserList.Where(x => x.SyncEmails))
            {
                newEmails.AddRange(user.GetEmails());

                if (Readiness.CheckTerminationStatus())
                {
                    break;
                }
            }

            // Remove emails from last update date (prevent redundancy)
            ClearDuplicateMailByID();

            Readiness.DeleteBlockerFile();

            Log.Append(String.Format("All inboxes completed. Total of {0} emails cached ({2} new emails). Process took {1}", EmailList.Count,
                                     Arithmetic.GetStopWatchStr((DateTime.Now.TimeOfDay - startTime).TotalMilliseconds), newEmails.Count));

            ExportEmailFile();

            // Remove non-validated and unmapped messages in the background
            Task.Run(() => ValidateMessages(true));

            SaveSettings();

            return(newEmails);
        }
Beispiel #3
0
        internal static void LoadInitializers()
        {
            ArchivesChecker.GetEntireArchive();
            LoadSettings();
            ImportEmailFile();
            Readiness.DeleteBlockerFile();

            if (!Environment.MachineName.Contains("ROBIN"))
            {
                //Global.GetAllEmails();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Verify that every message has an associated email object (if not, remove)
        /// </summary>
        public static void ValidateMessages(bool postSyncCheck = false)
        {
            if (isSyncing && !postSyncCheck)
            {
                Log.Append("ERROR: Sync in progress. Cannot validate information");
                return;
            }

            TimeSpan startTime = DateTime.Now.TimeOfDay;

            int startingCount = PurgeDuplicates();

            Log.Append("Validating email & data integrity...");

            int removedMessages = 0;

            startingCount += EmailList.Count;

            EmailList = EmailList.Where(x => File.Exists(messagesDirectoryPath + x.ID + ".eml") && UserList.Any(y => y.Email.ToLower() == x.To.ToLower())).ToList();

            string[] messageFiles = Directory.GetFiles(messagesDirectoryPath, "*.eml*");

            foreach (string filePath in messageFiles)
            {
                if (!EmailList.Any(x => x.ID == Path.GetFileName(filePath).Substring(0, 9)))
                {
                    File.Delete(filePath);
                    removedMessages++;
                }
            }

            removedMessages += startingCount - EmailList.Count;


            Log.Append(String.Format("Validation completed. Found and removed {0} unverified messages. Process took {1}",
                                     removedMessages, Arithmetic.GetStopWatchStr((DateTime.Now.TimeOfDay - startTime).TotalMilliseconds)));

            // Save again after verification if removed anything
            if (removedMessages > 0)
            {
                ExportEmailFile();
            }

            Readiness.DeleteBlockerFile();
        }
Beispiel #5
0
        public static void RegenerateCacheFile()
        {
            Log.Append("ERROR: Could not parse email file. Recovering cache file...");

            TimeSpan startTime = DateTime.Now.TimeOfDay;

            EmailList = new List <Email>();

            string[] messageFiles = Directory.GetFiles(messagesDirectoryPath, "*.eml*");

            int emailCount      = 0;
            int totalEmailCount = messageFiles.Length;

            foreach (string filePath in messageFiles)
            {
                CDO.Message CDOMessage = Email.GetEmlFromFile(filePath);

                Email email = new Email()
                {
                    ID           = Path.GetFileName(filePath).Substring(0, 9),
                    UID          = "0",
                    To           = CDOMessage.To + (CDOMessage.CC.Length > 0 ? "," + CDOMessage.CC : ""),
                    From         = CDOMessage.From,
                    Subject      = CDOMessage.Subject,
                    EmailMessage = "", // prevent nullification
                    MailDate     = CDOMessage.ReceivedTime
                };

                emailCount++;

                email.ParseToEmail();
                AppendEmail(email, String.Format("{0}/{1}", emailCount, totalEmailCount));

                email.MapNameFromEmail();
            }

            // Save regenerated files
            ExportEmailFile();

            isSyncing = false;
            Readiness.DeleteBlockerFile();

            Log.Append(String.Format("Cache regeneration completed. Process took {0}",
                                     Arithmetic.GetStopWatchStr((DateTime.Now.TimeOfDay - startTime).TotalMilliseconds)));
        }