コード例 #1
0
 private static Boolean IsWorking(String taskName)
 {
     MailsTasksHandler.LockTasksList();
     if (MailsTasksHandler.TasksList.ContainsKey(taskName) && MailsTasksHandler.TasksList[taskName].IsWorking)
     {
         MailsTasksHandler.UnlockTasksList();
         return(true);
     }
     MailsTasksHandler.UnlockTasksList();
     return(false);
 }
コード例 #2
0
        public static void SynchronizeTrash(String mailAddress)
        {
            MailAccount mailAccountTrash;
            MailsTask   newTaskTrash;
            String      mailAddressTrash = mailAddress + "/TRASH";

            if (MailsTasksHandler.IsWorking(mailAddressTrash))
            {
                return;
            }

            using (ISession session = NHibernateManager.OpenSession())
            {
                mailAccountTrash = MailAccount.FindByAddress(mailAddress, session, false);
                try
                {
                    mailAccountTrash.ConnectFull(session);
                }
                catch (NullReferenceException exc)
                {
                    Log.LogException(exc, "Direccion inexistente en la base de datos: " + mailAccountTrash + ".");
                    return;
                }
                catch (InvalidAuthenticationException exc)
                {
                    Log.LogException(exc, "No se pudo conectar a imap con la direccion: " + mailAddress + ", ha cambiado el password.");
                    return;
                }
                catch (SocketException exc)
                {
                    Log.LogException(exc, "No se pudo conectar a imap con la direccion: " + mailAddress + ".");
                    return;
                }
                Label trashLabel = Label.FindBySystemName(mailAccountTrash, "Trash", session);
                newTaskTrash = new MailsTask(mailAccountTrash.GetUIDLocal(session, trashLabel.Entity.SystemName, true),
                                             mailAccountTrash.GetUIDLocal(session, trashLabel.Entity.SystemName, false),
                                             mailAccountTrash.GetUIDExternalFrom(trashLabel.Entity.Name, true),
                                             mailAccountTrash.GetUIDExternalFrom(trashLabel.Entity.Name, false),
                                             trashLabel,
                                             mailAccountTrash);
                session.Close();
            }
            if (!newTaskTrash.HasFinished)
            {
                MailsTasksHandler.LockTasksList();
                MailsTasksHandler.TasksList[mailAddressTrash] = newTaskTrash;
                MailsTasksHandler.UnlockTasksList();
                MailsTasksHandler.StartMailsTask(newTaskTrash);
            }
        }
コード例 #3
0
        private static Boolean IsAnyWorking(String[] tasksNames)
        {
            MailsTasksHandler.LockTasksList();
            Boolean anyIsWorking = false;

            foreach (String taskName in tasksNames)
            {
                if (MailsTasksHandler.TasksList.ContainsKey(taskName) && MailsTasksHandler.TasksList[taskName].IsWorking)
                {
                    anyIsWorking = true;
                    break;
                }
            }
            MailsTasksHandler.UnlockTasksList();
            return(anyIsWorking);
        }
コード例 #4
0
        public static void StartSynchronization(String mailAddress, Boolean forwardOnly = true)
        {
            MailAccount mailAccountAll;
            MailsTask   newAllTask;
            MailsTask   newTaskTrash;
            MailsTask   newSpamTask;
            String      mailAddressAll   = mailAddress + "/ALL";
            String      mailAddressTrash = mailAddress + "/TRASH";
            String      mailAddressSpam  = mailAddress + "/SPAM";

            if (MailsTasksHandler.IsAnyWorking(new String[]  { mailAddressAll, mailAddressTrash, mailAddressSpam }))
            {
                return; //alguna tarea se encuentra trabajando
            }
            using (ISession session = NHibernateManager.OpenSession())
            {
                mailAccountAll = MailAccount.FindByAddress(mailAddress, session, false);
                try
                {
                    mailAccountAll.ConnectFull(session);
                }
                catch (NullReferenceException exc)
                {
                    Log.LogException(exc, "Direccion inexistente en la base de datos: " + mailAccountAll + ".");
                    return;
                }
                catch (InvalidAuthenticationException exc)
                {
                    Log.LogException(exc, "No se pudo conectar a imap con la direccion: " + mailAddress + ", ha cambiado el password.");
                    return;
                }
                catch (SocketException exc)
                {
                    Log.LogException(exc, "No se pudo conectar a imap con la direccion: " + mailAddress + ".");
                    return;
                }
                Label allLabel   = Label.FindBySystemName(mailAccountAll, "All", session);
                Label trashLabel = Label.FindBySystemName(mailAccountAll, "Trash", session);
                Label spamLabel  = Label.FindBySystemName(mailAccountAll, "Junk", session);

                newAllTask = new MailsTask(mailAccountAll.GetUIDLocal(session, allLabel.Entity.SystemName, true),  //lastUidLocal
                                           mailAccountAll.GetUIDLocal(session, allLabel.Entity.SystemName, false), //firstUidLocal
                                           mailAccountAll.GetUIDExternalFrom(allLabel.Entity.Name, true),          //lastUidExternal
                                           mailAccountAll.GetUIDExternalFrom(allLabel.Entity.Name, false),         //firstUidExternal
                                           allLabel,
                                           mailAccountAll);
                newTaskTrash = new MailsTask(mailAccountAll.GetUIDLocal(session, trashLabel.Entity.SystemName, true),  //lastUidLocal
                                             mailAccountAll.GetUIDLocal(session, trashLabel.Entity.SystemName, false), //firstUidLocal
                                             mailAccountAll.GetUIDExternalFrom(trashLabel.Entity.Name, true),          //lastUidExternal
                                             mailAccountAll.GetUIDExternalFrom(trashLabel.Entity.Name, false),         //firstUidExternal
                                             trashLabel,
                                             null);
                newSpamTask = new MailsTask(mailAccountAll.GetUIDLocal(session, spamLabel.Entity.SystemName, true),  //lastUidLocal
                                            mailAccountAll.GetUIDLocal(session, spamLabel.Entity.SystemName, false), //firstUidLocal
                                            mailAccountAll.GetUIDExternalFrom(spamLabel.Entity.Name, true),          //lastUidExternal
                                            mailAccountAll.GetUIDExternalFrom(spamLabel.Entity.Name, false),         //firstUidExternal
                                            spamLabel,
                                            null);
                session.Close();
            }
            if (!newAllTask.HasFinished)             //puede ser que no se necesite sincronizar dependiendo de los numeros
            {
                if (newAllTask.HighestUidLocal != 0) //si no es la primera vez, que sincronice hacia adelante sin limites
                {
                    newAllTask.SetUnlimitedForwarding(true);
                }
                newAllTask.SetForwardOnly(forwardOnly);
                MailsTasksHandler.LockTasksList();
                MailsTasksHandler.TasksList[mailAddressAll] = newAllTask;
                MailsTasksHandler.UnlockTasksList();
                MailsTasksHandler.StartMailsTask(newAllTask);
            }
            if (!newTaskTrash.HasFinished)
            {
                MailAccount mailAccountTrash = mailAccountAll.Clone(); //crear otra conexion a IMAP
                newTaskTrash.SetMailAccount(mailAccountTrash);
                MailsTasksHandler.LockTasksList();
                MailsTasksHandler.TasksList[mailAddressTrash] = newTaskTrash;
                MailsTasksHandler.UnlockTasksList();
                MailsTasksHandler.StartMailsTask(newTaskTrash);
            }
            if (!newSpamTask.HasFinished)
            {
                MailAccount mailAccountSpam = mailAccountAll.Clone(); //crear otra conexion a IMAP
                newSpamTask.SetMailAccount(mailAccountSpam);
                MailsTasksHandler.LockTasksList();
                MailsTasksHandler.TasksList[mailAddressSpam] = newSpamTask;
                MailsTasksHandler.UnlockTasksList();
                MailsTasksHandler.StartMailsTask(newSpamTask);
            }
        }