Exemplo n.º 1
0
    public void MakeActive(bool yesOrNo)
    {
        //ShowEMail(yesOrNo);

        if (yesOrNo)
        {
            loadingDelayRefTime            = Time.time;
            curtransitionScreenFramesIndex = 0;
            transitionScreenFrameRefTime   = Time.time;

            MailState = MailMode.Loading;
        }
        else
        {
            mailListText.enabled      = false;
            mailListSelection.enabled = false;

            attachmentImageInspector.enabled   = false;
            attachmentTextInspector.enabled    = false;
            attachmentTextInspectorBgd.enabled = false;
            attachmentNameText.enabled         = false;
            attachmentTextOfPOI.enabled        = false;
            attachmentCursor.enabled           = false;

            DimMessageWindows(false);

            curtransitionScreenFramesIndex = transitionScreenFrames.Count - 1;
            transitionScreenFrameRefTime   = Time.time;
            MailState = MailMode.Closing;
        }
    }
Exemplo n.º 2
0
    public void PressCircle()
    {
        if (MailState == MailMode.ViewingAttachment)
        {
            InspectAttachment(false);
            attachmentCursor.enabled    = false;
            attachmentTextOfPOI.enabled = false;

            MailState = MailMode.ViewingMessage;
        }
    }
Exemplo n.º 3
0
        public Account(string dataFolder)
        {
            WebmailSettings settings;

            if (dataFolder != string.Empty)
            {
                settings = (new WebMailSettingsCreator()).CreateWebMailSettings(dataFolder);
            }
            else
            {
                settings = (new WebMailSettingsCreator()).CreateWebMailSettings();
            }
            _id                    = -1;
            _idUser                = -1;
            _idDomain              = 0;
            _defaultAccount        = true;
            _deleted               = false;
            _email                 = "";
            _mailProtocol          = settings.IncomingMailProtocol;
            _mailIncHost           = settings.IncomingMailServer;
            _mailIncLogin          = "";
            _mailIncPassword       = "";
            _mailIncPort           = settings.IncomingMailPort;
            _mailOutHost           = settings.OutgoingMailServer;
            _mailOutLogin          = "";
            _mailOutPassword       = "";
            _mailOutPort           = settings.OutgoingMailPort;
            _mailOutAuthentication = settings.ReqSmtpAuth;
            _friendlyName          = "";
            _useFriendlyName       = true;
            _defaultOrder          = DefaultOrder.DateDesc;
            _getMailAtLogin        = true;
            _mailMode              = MailMode.LeaveMessagesOnServer;
            _mailsOnServerDays     = 1;
            _signature             = "";
            _signatureType         = SignatureType.Plain;
            _signatureOptions      = SignatureOptions.DontAddSignature;
            _user                  = null;
            _delimiter             = "/";
            _mailbox_size          = 0;
            _mailing_list          = false;
            _imap_quota            = -1;
            _namespace             = "";
        }
Exemplo n.º 4
0
    ///
    /// CONTROLS
    ///

    public void PressX()
    {
        if (MailState == MailMode.ViewingMessage && curEMail.attachments.Count > 0 && curAttachment != null)
        {
            InspectAttachment(true);

            curAttachmentPointOfInterestIndex = 0;
            InitializeTextOfCurrentAttachmentCurrentPOI();

            MailState = MailMode.ViewingAttachment;
        }
        else if (MailState == MailMode.ViewingAttachment)
        {
            InspectAttachment(false);
            attachmentCursor.enabled    = false;
            attachmentTextOfPOI.enabled = false;

            MailState = MailMode.ViewingMessage;
        }
    }
Exemplo n.º 5
0
    // Start is called before the first frame update
    void Start()
    {
        currentEmailListIndex   = 0;
        currentListVisibleIndex = 0;
        curEMail       = emailList[currentEmailListIndex];
        curEMail.isNew = false;

        mailListText.supportRichText  = true;
        mailRecipient.supportRichText = true;
        mailSender.supportRichText    = true;

        mailListSelectionHeight          = (int)Mathf.Floor(mailListSelection.rectTransform.rect.height);
        mailListSelectionInitialPosition = mailListSelection.rectTransform.anchoredPosition;

        mailTextInitialAlpha       = mailText.color.a;
        mailTextBgdInitialAlpha    = mailTextBgd.color.a;
        mailRecipientInitialAlpha  = mailRecipient.color.a;
        mailSenderInitialAlpha     = mailSender.color.a;
        mailScrollerInitialAlpha   = mailTextScroller.color.a;
        mailScrollUpInitialAlpha   = mailTextScrollUp.color.a;
        mailScrollDownInitialAlpha = mailTextScrollDown.color.a;

        attachmentTextWidth    = attachmentTextInspector.rectTransform.rect.width;
        attachmentTextBgdWidth = attachmentTextInspectorBgd.rectTransform.rect.width;

        curAttachmentIndex = 0;
        curAttachmentIcon  = mailAttachmentsIcons[curAttachmentIndex];
        curAttachmentPointOfInterestIndex          = 0;
        attachmentPointDescriptionTextIsUnraveling = false;
        curAttachmentPointDescriptionCharIndex     = 0;

        attachmentSelectorIsIncreasingAlpha = false;

        curFirstLineIndex = 0;
        DetermineVisibleTextOfCurrentMessage();

        ShowEMail(false);

        MailState = MailMode.Inactive;
    }
Exemplo n.º 6
0
        public override void Handle(GameSession session, PacketReader packet)
        {
            MailMode mode = (MailMode)packet.ReadByte();

            switch (mode)
            {
            case MailMode.Open:
                HandleOpen(session);
                break;

            case MailMode.Send:
                HandleSend(session, packet);
                break;

            case MailMode.Read:
                HandleRead(session, packet);
                break;

            case MailMode.Collect:
                HandleCollect(session, packet);
                break;

            case MailMode.Delete:
                HandleDelete(session, packet);
                break;

            case MailMode.ReadBatch:
                HandleReadBatch(session, packet);
                break;

            case MailMode.CollectBatch:
                HandleCollectBatch(session, packet);
                break;

            default:
                IPacketHandler <GameSession> .LogUnknownMode(mode);

                break;
            }
        }
Exemplo n.º 7
0
 public Account(int id_account, bool def_acct, bool deleted, string email, IncomingMailProtocol mail_protocol,
                string mail_inc_host, string mail_inc_login, string mail_inc_pass, int mail_inc_port, string mail_out_host,
                string mail_out_login, string mail_out_pass, int mail_out_port, bool mail_out_auth, string friendly_nm,
                bool use_friendly_nm, DefaultOrder def_order, bool getmail_at_login, MailMode mail_mode,
                short mails_on_server_days, string signature, SignatureType signature_type, SignatureOptions signature_opt,
                string delimiter, long mailbox_size, int idDomain, bool mailing_list, int imap_quota, string Namespace)
 {
     _id                    = id_account;
     _defaultAccount        = def_acct;
     _deleted               = deleted;
     _email                 = email;
     _mailProtocol          = mail_protocol;
     _mailIncHost           = mail_inc_host;
     _mailIncLogin          = mail_inc_login;
     _mailIncPassword       = mail_inc_pass;
     _mailIncPort           = mail_inc_port;
     _mailOutHost           = mail_out_host;
     _mailOutLogin          = mail_out_login;
     _mailOutPassword       = mail_out_pass;
     _mailOutPort           = mail_out_port;
     _mailOutAuthentication = mail_out_auth;
     _friendlyName          = friendly_nm;
     _useFriendlyName       = use_friendly_nm;
     _defaultOrder          = def_order;
     _getMailAtLogin        = getmail_at_login;
     _mailMode              = mail_mode;
     _mailsOnServerDays     = mails_on_server_days;
     _signature             = signature;
     _signatureType         = signature_type;
     _signatureOptions      = signature_opt;
     _delimiter             = delimiter;
     _mailbox_size          = mailbox_size;
     _idDomain              = idDomain;
     _mailing_list          = mailing_list;
     _imap_quota            = imap_quota;
     _namespace             = Namespace;
 }
Exemplo n.º 8
0
 public void ForceClose()
 {
     ShowEMail(false);
     MailState = MailMode.Inactive;
 }
Exemplo n.º 9
0
    // Update is called once per frame
    void Update()
    {
        curEMail = emailList[currentEmailListIndex];

        switch (MailState)
        {
        case MailMode.Inactive:

            CheckForNewMail();

            break;

        case MailMode.Loading:

            mailListBgd.texture = transitionScreenFrames[curtransitionScreenFramesIndex];

            if (Time.time - loadingDelayRefTime > loadingDelayTime)
            {
                mailListBgd.enabled                 = true;
                messengerMainScreen.materials       = blankScreenMaterial;
                messengerAttachmentScreen.materials = blankScreenMaterial;

                if (Time.time - transitionScreenFrameRefTime > transitionScreenFrameTime)
                {
                    if (curtransitionScreenFramesIndex < transitionScreenFrames.Count - 1)
                    {
                        curtransitionScreenFramesIndex++;
                        transitionScreenFrameRefTime = Time.time;
                    }
                    else
                    {
                        ShowEMail(true);

                        DetermineVisibleTextOfCurrentMessage();

                        MailState = MailMode.ViewingMessage;
                    }
                }
            }

            break;

        case MailMode.ViewingMessage:

            if (curEMail.attachments.Count > 0)
            {
                curAttachmentIcon = mailAttachmentsIcons[curAttachmentIndex];
                curAttachment     = curEMail.attachments[curAttachmentIndex];

                mailAttachmentSelector.enabled = true;
                mailAttachmentSelector.rectTransform.anchoredPosition = curAttachmentIcon.rectTransform.anchoredPosition;
                FlashAttachmentIcon();

                attachmentNameText.text    = curAttachment.attachmentShortDescription;
                attachmentNameText.enabled = true;
            }
            else
            {
                mailAttachmentSelector.enabled = false;

                attachmentNameText.text    = "";
                attachmentNameText.enabled = false;
            }

            curEMail = emailList[currentEmailListIndex];
            AssignTextAndBgd(curEMail, currentEmailListIndex, currentListVisibleIndex);
            ShowAttachments(curEMail, true);

            break;

        case MailMode.ViewingAttachment:

            if (curAttachment != null)
            {
                if (curAttachment.pointsOfInterest.Count > 0)
                {
                    attachmentCursor.enabled    = true;
                    attachmentTextOfPOI.enabled = true;

                    attachmentCursor.rectTransform.anchoredPosition =
                        attachmentImageInspector.rectTransform.anchoredPosition + curAttachment.pointsOfInterest[curAttachmentPointOfInterestIndex].posRelToImageCenter;

                    FlashAttachmentCursor();

                    if (attachmentPointDescriptionTextIsUnraveling)
                    {
                        if (Time.time - attachmentUnravelingTextRefTime > attachmentUnravelingTextTimePerCharForPOI)
                        {
                            if (curAttachmentPointDescriptionCharIndex < unravelingCharsForPOI.Count)
                            {
                                attachmentTextOfPOI.text += unravelingCharsForPOI[curAttachmentPointDescriptionCharIndex];
                                curAttachmentPointDescriptionCharIndex++;

                                attachmentUnravelingTextRefTime = Time.time;
                            }
                            else
                            {
                                attachmentPointDescriptionTextIsUnraveling = false;
                            }
                        }
                    }
                }
            }
            else
            {
                attachmentCursor.enabled    = false;
                attachmentTextOfPOI.enabled = false;
            }

            break;

        case MailMode.Closing:

            mailListBgd.texture = transitionScreenFrames[curtransitionScreenFramesIndex];

            if (Time.time - transitionScreenFrameRefTime > transitionScreenFrameTime)
            {
                if (curtransitionScreenFramesIndex > 0)
                {
                    curtransitionScreenFramesIndex--;
                    transitionScreenFrameRefTime = Time.time;
                }
                else
                {
                    ShowEMail(false);

                    MailState = MailMode.Inactive;
                }
            }

            break;
        }
    }
Exemplo n.º 10
0
        public Account CreateAccount(bool def_acct, bool deleted, string email, IncomingMailProtocol mail_protocol,
                                     string mail_inc_host, string mail_inc_login, string mail_inc_pass, int mail_inc_port,
                                     string mail_out_host, string mail_out_login, string mail_out_pass, int mail_out_port,
                                     bool mail_out_auth, string friendly_nm, bool use_friendly_nm, DefaultOrder def_order,
                                     bool getmail_at_login, MailMode mail_mode, short mails_on_server_days, string signature,
                                     SignatureType signature_type, SignatureOptions signature_opt, string delimiter, long mailbox_size,
                                     FolderSyncType inboxSyncType, bool advanced_login, int id_domain, bool mailing_list, int imap_quota, string Namespace)
        {
            WebmailResourceManager resMan = (new WebmailResourceManagerCreator()).CreateResourceManager();

            //----- validate incoming data -----
            if ((email == null) || (email.Trim().Length == 0))
            {
                if (advanced_login)
                {
                    throw new WebMailException(resMan.GetString("WarningEmailFieldBlank"));
                }
            }
            Regex r = new Regex(@"[\w!#\$%\^\{}`~&'\+-=_\.]+@[\w-\.]+");
            Match m = r.Match(email);

            if (!m.Success)
            {
                throw new WebMailException("WarningCorrectEmail");
            }
            if ((mail_inc_login == null) || (mail_inc_login.Trim().Length == 0))
            {
                if (advanced_login)
                {
                    throw new WebMailException(resMan.GetString("WarningLoginFieldBlank"));
                }
            }
            if (mail_inc_login.IndexOfAny(new char[] { '"', '/', '\\', '*', '?', '<', '>', '|', ':' }) >= 0)
            {
                throw new WebMailException(resMan.GetString("WarningCorrectLogin"));
            }
            if (string.IsNullOrEmpty(mail_inc_pass))
            {
                throw new WebMailException(resMan.GetString("WarningPassBlank"));
            }
            if ((mail_inc_host == null) || (mail_inc_host.Trim().Length == 0))
            {
                throw new WebMailException(resMan.GetString("WarningIncServerBlank"));
            }
            r = new Regex(@"[^(\w-\.)]+");
            m = r.Match(mail_inc_host);
            if (m.Success)
            {
                if (advanced_login)
                {
                    throw new WebMailException(resMan.GetString("WarningCorrectIncServer"));
                }
            }
            if ((mail_inc_port < 0) || (mail_inc_port > 65535))
            {
                if (advanced_login)
                {
                    throw new WebMailException(resMan.GetString("WarningIncPortNumber"));
                }
            }
            if ((mail_out_host == null) || (mail_out_host.Trim().Length == 0))
            {
                if (advanced_login)
                {
                    throw new WebMailException(resMan.GetString("WarningOutServerBlank"));
                }
            }
            r = new Regex(@"[^(\w-\.)]+");
            m = r.Match(mail_out_host);
            if (m.Success)
            {
                if (advanced_login)
                {
                    throw new WebMailException(resMan.GetString("WarningCorrectOutServer"));
                }
            }
            if ((mail_out_port < 0) || (mail_out_port > 65535))
            {
                if (advanced_login)
                {
                    throw new WebMailException(resMan.GetString("WarningOutPortNumber"));
                }
            }
            //------ end validate incoming data --------


            WebmailSettings  settings   = (new WebMailSettingsCreator()).CreateWebMailSettings();
            Account          newAccount = null;
            DbManagerCreator creator    = new DbManagerCreator();
            DbManager        dbMan      = creator.CreateDbManager();

            try
            {
                dbMan.Connect();

                if (settings.EnableWmServer && mail_protocol == IncomingMailProtocol.WMServer)
                {
                    string          emailDomain  = EmailAddress.GetDomainFromEmail(email);
                    string          emailUser    = EmailAddress.GetAccountNameFromEmail(email);
                    WMServerStorage storage      = new WMServerStorage(null);
                    string[]        domains      = storage.GetDomainList();
                    bool            domainExists = false;

                    foreach (string domain in domains)
                    {
                        if (string.Compare(emailDomain, domain, true, CultureInfo.InvariantCulture) == 0)
                        {
                            Domain dom = Domain.GetDomain(emailDomain);
                            if (dom != null)
                            {
                                id_domain = dom.ID;
                            }

                            WMServerUser[] users             = storage.GetUserList(emailDomain);
                            bool           userExists        = false;
                            bool           mailingListExists = false;
                            foreach (WMServerUser user in users)
                            {
                                if (string.Compare(emailUser, user.Name, true, CultureInfo.InvariantCulture) == 0)
                                {
                                    if (string.Compare("U", user.Type, true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        userExists = true;
                                    }
                                    else
                                    {
                                        mailingListExists = true;
                                    }
                                    break;
                                }
                            }
                            if (!userExists && !mailing_list || !mailingListExists && mailing_list)
                            {
                                if (!mailingListExists)
                                {
                                    storage.AddUser(emailDomain, emailUser, mail_inc_pass);
                                }
                                else
                                {
                                    throw new WebMailException(resMan.GetString("ErrorPOP3IMAP4Auth"));
                                }
                            }
                            domainExists = true;
                            break;
                        }
                    }

                    if (!domainExists)
                    {
                        throw new WebMailException(resMan.GetString("ErrorDomainExist"));
                    }
                }

                if (mail_protocol == IncomingMailProtocol.WMServer)
                {
                    delimiter = ".";
                }

                newAccount = dbMan.CreateAccount(_id, def_acct, deleted, email, mail_protocol, mail_inc_host,
                                                 mail_inc_login, mail_inc_pass, mail_inc_port, mail_out_host, mail_out_login, mail_out_pass,
                                                 mail_out_port, mail_out_auth, friendly_nm, use_friendly_nm, def_order, getmail_at_login,
                                                 mail_mode, mails_on_server_days, signature, signature_type, signature_opt, delimiter,
                                                 mailbox_size, id_domain, mailing_list, imap_quota, Namespace);
                newAccount.UserOfAccount = this;

                dbMan.DbAccount = newAccount;
                FileSystem fs = new FileSystem(email, newAccount.ID, true);
                if (mail_protocol != IncomingMailProtocol.WMServer)
                {
                    fs.CreateAccount();
                }

                if (mail_protocol == IncomingMailProtocol.Pop3)
                {
                    if (settings.AllowDirectMode && settings.DirectModeIsDefault)
                    {
                        inboxSyncType = FolderSyncType.DirectMode;
                    }

                    // -- this fix for gmail pop3 --
                    if (mail_inc_host == "pop.gmail.com")
                    {
                        inboxSyncType = FolderSyncType.AllEntireMessages;
                    }
                    // -----------------------------

                    if (!settings.StoreMailsInDb)
                    {
                        fs.CreateFolder(Constants.FolderNames.Inbox);
                    }
                    dbMan.CreateFolder(newAccount.ID, -1, FolderType.Inbox, Constants.FolderNames.Inbox, Constants.FolderNames.Inbox, inboxSyncType, false, 0);

                    if (!settings.StoreMailsInDb)
                    {
                        fs.CreateFolder(Constants.FolderNames.SentItems);
                    }
                    dbMan.CreateFolder(newAccount.ID, -1, FolderType.SentItems, Constants.FolderNames.SentItems, Constants.FolderNames.SentItems, FolderSyncType.DontSync, false, 1);

                    if (!settings.StoreMailsInDb)
                    {
                        fs.CreateFolder(Constants.FolderNames.Drafts);
                    }
                    dbMan.CreateFolder(newAccount.ID, -1, FolderType.Drafts, Constants.FolderNames.Drafts, Constants.FolderNames.Drafts, FolderSyncType.DontSync, false, 2);

                    if (!settings.StoreMailsInDb)
                    {
                        fs.CreateFolder(Constants.FolderNames.Spam);
                    }
                    dbMan.CreateFolder(newAccount.ID, -1, FolderType.Spam, Constants.FolderNames.Spam, Constants.FolderNames.Spam, FolderSyncType.DontSync, false, 3);

                    if (!settings.StoreMailsInDb)
                    {
                        fs.CreateFolder(Constants.FolderNames.Trash);
                    }
                    dbMan.CreateFolder(newAccount.ID, -1, FolderType.Trash, Constants.FolderNames.Trash, Constants.FolderNames.Trash, FolderSyncType.DontSync, false, 4);
                }
                else if (mail_protocol == IncomingMailProtocol.WMServer)
                {
                    MailServerStorage wmServerStorage = MailServerStorageCreator.CreateMailServerStorage(newAccount);
                    try
                    {
                        wmServerStorage.Connect();
                        FolderCollection fc = wmServerStorage.GetFolders();

                        Folder fld = fc[FolderType.SentItems];
                        if (fld == null)
                        {
                            string       fullPath = newAccount.Delimiter + Constants.FolderNames.SentItems;
                            const string name     = Constants.FolderNames.SentItems;
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.SentItems);
                            }
                            fld = new Folder(newAccount.ID, -1, fullPath, name);
                            wmServerStorage.CreateFolder(fld);
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.SentItems, name, fullPath, FolderSyncType.AllHeadersOnly, false, 1);
                        }

                        fld = fc[FolderType.Drafts];
                        if (fld == null)
                        {
                            string       fullPath = newAccount.Delimiter + Constants.FolderNames.Drafts;
                            const string name     = Constants.FolderNames.Drafts;
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.Drafts);
                            }
                            fld = new Folder(newAccount.ID, -1, fullPath, name);
                            wmServerStorage.CreateFolder(fld);
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.Drafts, name, fullPath, FolderSyncType.AllHeadersOnly, false, 2);
                        }

                        fld = fc[FolderType.Spam];
                        if (fld == null)
                        {
                            string       fullPath = newAccount.Delimiter + Constants.FolderNames.Spam;
                            const string name     = Constants.FolderNames.Spam;
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.Spam);
                            }
                            fld = new Folder(newAccount.ID, -1, fullPath, name);
                            wmServerStorage.CreateFolder(fld);
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.Spam, name, fullPath, FolderSyncType.AllHeadersOnly, false, 3);
                        }

                        fld = fc[FolderType.Trash];
                        if (fld == null)
                        {
                            string       fullPath = newAccount.Delimiter + Constants.FolderNames.Trash;
                            const string name     = Constants.FolderNames.Trash;
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.Trash);
                            }
                            fld = new Folder(newAccount.ID, -1, fullPath, name);
                            wmServerStorage.CreateFolder(fld);
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.Trash, name, fullPath, FolderSyncType.AllHeadersOnly, false, 4);
                        }

                        fld = fc[FolderType.Quarantine];
                        if (fld == null)
                        {
                            string       fullPath = newAccount.Delimiter + Constants.FolderNames.Quarantine;
                            const string name     = Constants.FolderNames.Quarantine;
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.Quarantine);
                            }
                            fld = new Folder(newAccount.ID, -1, fullPath, name);
                            wmServerStorage.CreateFolder(fld);
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.Quarantine, name, fullPath, FolderSyncType.AllHeadersOnly, false, 5);
                        }

                        dbMan.CreateFoldersTree(fc);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(ex);
                        throw new WebMailException(ex);
                    }
                }
                else if (mail_protocol == IncomingMailProtocol.Imap4)
                {
                    MailServerStorage imapStorage = MailServerStorageCreator.CreateMailServerStorage(newAccount);
                    try
                    {
                        imapStorage.Connect();
                        FolderCollection fc  = imapStorage.GetFolders();
                        Folder           fld = fc[FolderType.Inbox];
                        if (fld != null)
                        {
                            fld.SyncType = FolderSyncType.DirectMode;
                        }

//                        if (settings.AllowDirectMode && settings.DirectModeIsDefault)
//                        {
                        fc.ReSetSyncTypeToDirectMode();
//                        }

                        fld = fc[FolderType.Drafts];
                        if (fld == null)
                        {
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.Drafts);
                            }
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.Drafts, Constants.FolderNames.Drafts, Constants.FolderNames.Drafts, FolderSyncType.DontSync, false, 2);
                        }

                        fld = fc[FolderType.SentItems];
                        if (fld == null)
                        {
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.SentItems);
                            }
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.SentItems, Constants.FolderNames.SentItems, Constants.FolderNames.SentItems, FolderSyncType.DontSync, false, 1);
                        }

                        fld = fc[FolderType.Spam];
                        if (fld == null)
                        {
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.Spam);
                            }
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.Spam, Constants.FolderNames.Spam, Constants.FolderNames.Spam, FolderSyncType.DontSync, false, 3);
                        }

                        fld = fc[FolderType.Trash];
                        if (fld == null && settings.Imap4DeleteLikePop3)
                        {
                            if (!settings.StoreMailsInDb)
                            {
                                fs.CreateFolder(Constants.FolderNames.Trash);
                            }
                            dbMan.CreateFolder(newAccount.ID, -1, FolderType.Trash, Constants.FolderNames.Trash, Constants.FolderNames.Trash, FolderSyncType.DontSync, false, 4);
                        }

                        newAccount.Delimiter = (fc.Count > 0) ? fc[0].ImapFolder.Delimiter : newAccount.Delimiter;

                        if (!settings.StoreMailsInDb)
                        {
                            fs.CreateFoldersTree(fc);
                        }
                        dbMan.CreateFoldersTree(fc);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(ex);
                        throw new WebMailException(ex);
                    }
                    finally
                    {
                        imapStorage.Disconnect();
                    }
                }
            }
            catch (IOException ex)
            {
                Log.WriteException(ex);
                throw new WebMailException(ex);
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.WriteException(ex);
                throw new WebMailException(ex);
            }
            catch (WebMailException ex)
            {
                Log.WriteException(ex);
                if (newAccount != null)
                {
                    if (dbMan.IsConnected)
                    {
                        dbMan.DeleteAccount(newAccount.ID);
                    }
                    else
                    {
                        dbMan.Connect();
                        dbMan.DeleteAccount(newAccount.ID);
                    }
                }
                throw;
            }
            finally
            {
                dbMan.Disconnect();
            }
            return(newAccount);
        }