コード例 #1
0
        public void UserLoginByEmail(string email, string login, string password, WMStartPage startPage, string toEmail)
        {
            Account acct = Account.LoginAccount(email, login, password);

            if (acct != null)
            {
                string    sessionHash = Utils.GetMD5DigestHexString(HttpContext.Current.Session.SessionID);
                DbStorage storage     = DbStorageCreator.CreateDatabaseStorage(acct);
                try
                {
                    storage.Connect();
                    storage.CreateTempRow(acct.ID, string.Format(@"sessionHash_{0}", sessionHash));
                }
                catch (WebMailException)
                {
                    throw;
                }
                catch (Exception ex)
                {
                    throw new WebMailDatabaseException(ex);
                }
                finally
                {
                    storage.Disconnect();
                }

                HttpContext.Current.Response.Redirect(_wmRoot + @"/" + string.Format(@"integration/integr.aspx?hash={0}&scr={1}&to={2}", sessionHash, (int)startPage, toEmail), false);
            }
        }
コード例 #2
0
ファイル: User.cs プロジェクト: cuplexProjects/C-Projects
        public void Update()
        {
            DbStorage ds = DbStorageCreator.CreateDatabaseStorage(null);

            try
            {
                ds.UpdateUserColumn(_id_column, _id_user, _value);
            }
            finally
            {
                ds.Disconnect();
            }
        }
コード例 #3
0
ファイル: User.cs プロジェクト: cuplexProjects/C-Projects
        public static UserColumn[] GetColumnsFromDb(int id_user)
        {
            DbStorage ds = DbStorageCreator.CreateDatabaseStorage(null);

            try
            {
                return(ds.GetUserColumns(id_user));
            }
            finally
            {
                ds.Disconnect();
            }
        }
コード例 #4
0
ファイル: User.cs プロジェクト: cuplexProjects/C-Projects
        public static void DeleteColumn(UserColumn column)
        {
            DbStorage ds = DbStorageCreator.CreateDatabaseStorage(null);

            try
            {
                ds.DeleteUserColumn(column);
            }
            finally
            {
                ds.Disconnect();
            }
        }
コード例 #5
0
ファイル: User.cs プロジェクト: cuplexProjects/C-Projects
        public static UserColumn CreateColumn(int id_column, int id_user, int value)
        {
            DbStorage ds = DbStorageCreator.CreateDatabaseStorage(null);

            try
            {
                return(ds.CreateUserColumn(id_column, id_user, value));
            }
            finally
            {
                ds.Disconnect();
            }
        }
コード例 #6
0
        protected void AutoCheckMailForAccount(Account acct)
        {
            if (acct != null)
            {
                try
                {
                    DbStorage              dbs     = DbStorageCreator.CreateDatabaseStorage(acct);
                    MailProcessor          mp      = new MailProcessor(dbs);
                    WebmailResourceManager _resMan = (new WebmailResourceManagerCreator()).CreateResourceManager();
                    try
                    {
                        mp.MessageDownloaded += new DownloadedMessageHandler(mp_MessageDownloaded);
                        mp.Connect();

                        FolderCollection fc1 = dbs.GetFolders();
                        FolderCollection fc2 = new FolderCollection();
                        foreach (Folder fld in fc1)
                        {
                            if (fld.Type == FolderType.Inbox)
                            {
                                fc2.Add(fld);
                            }
                        }
                        Dictionary <long, string> updatedFolders = mp.Synchronize(fc2);
                        string strFolders = "";
                        foreach (KeyValuePair <long, string> kvp in updatedFolders)
                        {
                            strFolders += "{id: " + kvp.Key.ToString() + ", fullName: '" + kvp.Value + "'}, ";
                        }
                        Response.Write(@"<script type=""text/javascript"">parent.SetUpdatedFolders([" + strFolders.TrimEnd(new char[2] {
                            ',', ' '
                        }) + "], false);</script>");
                    }
                    finally
                    {
                        mp.MessageDownloaded -= new DownloadedMessageHandler(mp_MessageDownloaded);
                        mp.Disconnect();
                    }
                }
                catch (WebMailException ex)
                {
                    Log.WriteException(ex);
                    errorDesc = Utils.EncodeJsSaveString(ex.Message);
                    if (Type == 1 || Type == 2)
                    {
                        Session.Add(Constants.sessionErrorText, errorDesc);
                    }
                }
            }
        }
コード例 #7
0
 protected void CheckMailForAccount(Account acct)
 {
     if (acct != null)
     {
         try
         {
             DbStorage              dbs     = DbStorageCreator.CreateDatabaseStorage(acct);
             MailProcessor          mp      = new MailProcessor(dbs);
             WebmailResourceManager _resMan = (new WebmailResourceManagerCreator()).CreateResourceManager();
             try
             {
                 mp.MessageDownloaded += new DownloadedMessageHandler(mp_MessageDownloaded);
                 Response.Write(@"<script type=""text/javascript"">parent.SetStateTextHandler(""" + _resMan.GetString("LoggingToServer") + @""");</script>");
                 mp.Connect();
                 Response.Write(@"<script type=""text/javascript"">parent.SetStateTextHandler(""" + _resMan.GetString("GettingMsgsNum") + @""");</script>");
                 Dictionary <long, string> updatedFolders = mp.Synchronize(dbs.GetFolders());
                 if (Type == 0)
                 {
                     string strFolders = "";
                     foreach (KeyValuePair <long, string> kvp in updatedFolders)
                     {
                         strFolders += "{id: " + kvp.Key.ToString() + ", fullName: '" + kvp.Value + "'}, ";
                     }
                     Response.Write(@"<script type=""text/javascript"">parent.SetUpdatedFolders([" + strFolders.TrimEnd(new char[2] {
                         ',', ' '
                     }) + "]);</script>");
                 }
             }
             finally
             {
                 mp.MessageDownloaded -= new DownloadedMessageHandler(mp_MessageDownloaded);
                 Response.Write(@"<script type=""text/javascript"">parent.SetStateTextHandler(""" + _resMan.GetString("LoggingOffFromServer") + @""");</script>");
                 mp.Disconnect();
             }
         }
         catch (WebMailException ex)
         {
             Log.WriteException(ex);
             errorDesc = Utils.EncodeJsSaveString(ex.Message);
             if (Type == 1)
             {
                 Session.Add(Constants.sessionErrorText, errorDesc);
             }
         }
     }
 }
コード例 #8
0
        internal static System.Xml.XmlAttribute CreateInboxSyncAttr(XmlElement webmailNode, Account acct)
        {
            XmlAttribute   inboxSyncTypeAttr = webmailNode.OwnerDocument.CreateAttribute("inbox_sync_type");
            FolderSyncType inboxSyncType     = FolderSyncType.NewHeadersOnly;
            MailProcessor  mp = new MailProcessor(DbStorageCreator.CreateDatabaseStorage(acct));

            try
            {
                mp.Connect();
                Folder fld = mp.GetFolder(FolderType.Inbox);
                if (fld != null)
                {
                    inboxSyncType = fld.SyncType;
                }
            }
            finally
            {
                mp.Disconnect();
            }
            inboxSyncTypeAttr.Value = ((short)inboxSyncType).ToString(CultureInfo.InvariantCulture);

            return(inboxSyncTypeAttr);
        }
コード例 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Account acct = Session[Constants.sessionAccount] as Account;

            if (acct != null)
            {
                int fileType             = (string.Compare(Request.Form["file_type"], "0", true, CultureInfo.InvariantCulture) == 0) ? 0 : 1;
                HttpFileCollection files = Request.Files;
                if ((files != null) && (files.Count > 0))
                {
                    HttpPostedFile file = files[0];
                    if (file != null)
                    {
                        byte[] buffer = null;
                        using (Stream uploadStream = file.InputStream)
                        {
                            buffer = new byte[uploadStream.Length];
                            long numBytesToRead = uploadStream.Length;
                            long numBytesRead   = 0;
                            while (numBytesToRead > 0)
                            {
                                int n = uploadStream.Read(buffer, (int)numBytesRead, (int)numBytesToRead);
                                if (n == 0)
                                {
                                    break;
                                }
                                numBytesRead   += n;
                                numBytesToRead -= n;
                            }
                        }
                        if (buffer != null)
                        {
                            try
                            {
                                string    csvText = Encoding.Default.GetString(buffer);
                                CsvParser parser  = new CsvParser(csvText, true);
                                DataTable dt      = parser.Parse();
                                if (dt.Rows.Count == 0)
                                {
                                    WebmailResourceManager resMan = (new WebmailResourceManagerCreator()).CreateResourceManager();
                                    Log.WriteLine("import Page_Load", "Error: No contacts for import");
                                    _jsErrorCode        = 2;
                                    _jsContactsImported = 0;
                                    Session[Constants.sessionReportText] = string.Format(@"{0}", resMan.GetString("ErrorNoContacts"));
                                    return;
                                }

                                ArrayList contacts = new ArrayList();
                                for (int rowsIndex = 0; rowsIndex < dt.Rows.Count; rowsIndex++)
                                {
                                    bool contactInitialized    = false;
                                    AddressBookContact contact = new AddressBookContact();
                                    contact.IDUser = acct.UserOfAccount.ID;
                                    string  firstName   = string.Empty;
                                    string  lastName    = string.Empty;
                                    string  nickname    = string.Empty;
                                    string  displayName = string.Empty;
                                    string  birthday    = string.Empty;
                                    DataRow dr          = dt.Rows[rowsIndex];
                                    for (int columnsIndex = 0; columnsIndex < dt.Columns.Count; columnsIndex++)
                                    {
                                        if (dr[columnsIndex] != DBNull.Value)
                                        {
                                            if (dr[columnsIndex] as string != null)
                                            {
                                                switch (dt.Columns[columnsIndex].ColumnName.ToLower())
                                                {
                                                case "first name":
                                                case "firstname":
                                                    firstName          = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "last name":
                                                case "lastname":
                                                    lastName           = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "notes":
                                                    contact.Notes      = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "home street":
                                                case "homestreet":
                                                case "homeaddress":
                                                    contact.HStreet    = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "home city":
                                                case "homecity":
                                                    contact.HCity      = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "home postal code":
                                                case "zip":
                                                    contact.HZip       = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "home state":
                                                case "homestate":
                                                    contact.HState     = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "home country":
                                                case "homecountry":
                                                case "home country/region":
                                                    contact.HCountry   = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "home phone":
                                                case "homephone":
                                                    contact.HPhone     = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "home fax":
                                                case "homefax":
                                                    contact.HFax       = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "mobile phone":
                                                case "mobilephone":
                                                    contact.HMobile    = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "web page":
                                                case "webpage":
                                                case "personal web page":
                                                case "personalwebpage":
                                                    contact.HWeb       = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "company":
                                                    contact.BCompany   = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "business street":
                                                case "businessstreet":
                                                    contact.BStreet    = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "business city":
                                                case "businesscity":
                                                    contact.BCity      = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "business state":
                                                case "businessstate":
                                                    contact.BState     = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "business postal code":
                                                    contact.BZip       = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "business country":
                                                case "business country/region":
                                                    contact.BCountry   = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "job title":
                                                case "jobtitle":
                                                    contact.BJobTitle  = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "department":
                                                    contact.BDepartment = dr[columnsIndex] as string;
                                                    contactInitialized  = true;
                                                    break;

                                                case "office location":
                                                case "officelocation":
                                                    contact.BOffice    = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "business phone":
                                                case "businessphone":
                                                    contact.BOffice    = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "business fax":
                                                case "businessfax":
                                                    contact.BFax       = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "business web page":
                                                case "businesswebpage":
                                                    contact.BWeb       = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "e-mail address":
                                                case "e-mailaddress":
                                                case "emailaddress":
                                                case "e-mail":
                                                case "email":
                                                    contact.HEmail     = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "e-mail display name":
                                                case "e-maildisplayname":
                                                case "emaildisplayname":
                                                case "name":
                                                    displayName        = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "birthday":
                                                    birthday           = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;

                                                case "nickname":
                                                    nickname           = dr[columnsIndex] as string;
                                                    contactInitialized = true;
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    if (!contactInitialized)
                                    {
                                        WebmailResourceManager resMan = (new WebmailResourceManagerCreator()).CreateResourceManager();
                                        Log.WriteLine("import Page_Load", "Error: CSV file has invalid format");
                                        _jsErrorCode        = 3;
                                        _jsContactsImported = 0;
                                        Session[Constants.sessionReportText] = string.Format(@"{0}", resMan.GetString("ErrorInvalidCSV"));
                                        break;
                                    }
                                    string fullName;
                                    if (nickname != string.Empty)
                                    {
                                        fullName = string.Format("{0} \"{1}\" {2}", firstName, nickname, lastName);
                                    }
                                    else
                                    {
                                        fullName = string.Format("{0} {1}", firstName, lastName);
                                    }
                                    contact.FullName = fullName;
                                    try
                                    {
                                        DateTime birthdayDate = DateTime.Parse(birthday);
                                        contact.BirthdayDay   = (byte)birthdayDate.Day;
                                        contact.BirthdayMonth = (byte)birthdayDate.Month;
                                        contact.BirthdayYear  = (short)birthdayDate.Year;
                                    }
                                    catch {}
                                    contacts.Add(contact);
                                }
                                DbStorage storage = DbStorageCreator.CreateDatabaseStorage(acct);
                                try
                                {
                                    storage.Connect();
                                    foreach (AddressBookContact contact in contacts)
                                    {
                                        contact.AutoCreate = true;

                                        try
                                        {
                                            storage.CreateAddressBookContact(contact);
                                            _jsContactsImported++;
                                        }
                                        catch { }
                                    }
                                    _jsErrorCode = 1;
                                    WebmailResourceManager resMan = (new WebmailResourceManagerCreator()).CreateResourceManager();
                                    Session[Constants.sessionReportText] = string.Format(@"{0} {1} {2}", resMan.GetString("InfoHaveImported"), _jsContactsImported, resMan.GetString("InfoNewContacts"));
                                }
                                finally
                                {
                                    storage.Disconnect();
                                }
                            }
                            catch
                            {
                                Log.WriteLine("import Page_Load", "Error while importing contacts");
                                _jsErrorCode        = 0;
                                _jsContactsImported = 0;
                            }
                        }
                    }
                }
            }
        }
コード例 #10
0
 public AddressBookDBStorage(Account account)
     : base(account)
 {
     _dbStorage = DbStorageCreator.CreateDatabaseStorage(account);
 }
コード例 #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            acct = Session[Constants.sessionAccount] as Account;
            if (acct == null)
            {
                Response.Redirect("default.aspx", true);
            }

            string userAgent;             //Client browser
            string temp_filename = Request.QueryString["temp_filename"];

            if (temp_filename != null)
            {
                try
                {
                    byte[] buffer     = new byte[0];
                    object tempFolder = Utils.GetTempFolderName(Session);
                    if (tempFolder != null)
                    {
                        //Response.Write(tempFolder.ToString() + "<br>");
                        //Response.Write(temp_filename);
                        //Response.End();
                        string safe_temp_file_name = Path.GetFileName(temp_filename);

                        string fullPath = Path.Combine(tempFolder.ToString(), safe_temp_file_name);
                        if (File.Exists(fullPath))
                        {
                            using (FileStream fs = File.OpenRead(fullPath))
                            {
                                buffer = new byte[fs.Length];
                                fs.Read(buffer, 0, buffer.Length);
                            }
                        }
                    }
                    else
                    {
                        return;
                    }
                    string filename = Request.QueryString["filename"] ?? temp_filename;
                    string download = Request.QueryString["download"];
                    //*************************************************************
                    //IE with cyrillic file names
                    //*************************************************************
                    string encodedFilename;
                    userAgent = Request.UserAgent;
                    if (userAgent.IndexOf("MSIE") > -1)
                    {
                        encodedFilename = Server.UrlPathEncode(filename);
                    }
                    else
                    {
                        encodedFilename = filename;
                    }
                    //**************************************************************
                    if (download != null)
                    {
                        Response.Clear();

                        if (string.Compare(download, "1", true, CultureInfo.InvariantCulture) == 0)
                        {
                            Response.AddHeader("Content-Disposition", @"attachment; filename=""" + encodedFilename + @"""");
                            Response.AddHeader("Accept-Ranges", "bytes");
                            Response.AddHeader("Content-Length", buffer.Length.ToString(CultureInfo.InvariantCulture));
                            Response.AddHeader("Content-Transfer-Encoding", "binary");
                            Response.ContentType = "application/octet-stream";
                        }
                        else
                        {
                            string ext = Path.GetExtension(filename);
                            if (!string.IsNullOrEmpty(ext))
                            {
                                ext = ext.Substring(1, ext.Length - 1);                                 // remove first dot
                            }
                            Response.ContentType = Utils.GetAttachmentMimeTypeFromFileExtension(ext);
                        }
                    }
                    Response.BinaryWrite(buffer);
                    Response.Flush();
                }
                catch (Exception ex)
                {
                    Log.WriteException(ex);
                }
            }
            else
            {
                if (Request.QueryString["partID"] != null)
                {
                    byte[] buffer = new byte[0];

                    try
                    {
                        string uid = HttpUtility.UrlDecode(Request.QueryString["uid"]);
                        string full_folder_name = Request.QueryString["full_folder_name"];
                        string partID           = Request.QueryString["partID"];
                        string filename         = Request.QueryString["filename"];
                        string download         = Request.QueryString["download"];
                        string temp_file        = Request.QueryString["tmp_filename"];
                        string temp_folder      = Utils.GetTempFolderName(Session);

                        //*************************************************************
                        //IE with cyrillic file names
                        //*************************************************************
                        string encodedFilename;
                        userAgent = Request.UserAgent;
                        if (userAgent.IndexOf("MSIE") > -1)
                        {
                            encodedFilename = Server.UrlPathEncode(filename);
                        }
                        else
                        {
                            encodedFilename = filename;
                        }
                        //**************************************************************

                        if (!string.IsNullOrEmpty(temp_file) && File.Exists(Path.Combine(temp_folder, temp_file)))
                        {
                            using (FileStream fs = File.OpenRead(Path.Combine(temp_folder, temp_file)))
                            {
                                buffer = new byte[fs.Length];
                                fs.Read(buffer, 0, buffer.Length);
                            }
                        }
                        else
                        {
                            MailProcessor mp = new MailProcessor(DbStorageCreator.CreateDatabaseStorage(Session[Constants.sessionAccount] as Account));
                            try
                            {
                                mp.Connect();
                                Folder fld = mp.GetFolder(full_folder_name);
                                if (fld != null)
                                {
                                    buffer = mp.GetAttachmentPart(uid, fld, partID);
                                }
                            }
                            finally
                            {
                                mp.Disconnect();
                            }
                            string tmp_filename = Utils.CreateTempFilePath(temp_folder, filename, true);
                            File.WriteAllBytes(tmp_filename, buffer);
                        }


                        if (download != null)
                        {
                            Response.Clear();

                            if (string.Compare(download, "1", true, CultureInfo.InvariantCulture) == 0)
                            {
                                Response.AddHeader("Content-Disposition", @"attachment; filename=""" + encodedFilename + @"""");
                                Response.AddHeader("Accept-Ranges", "bytes");
                                Response.AddHeader("Content-Length", buffer.Length.ToString(CultureInfo.InvariantCulture));
                                Response.AddHeader("Content-Transfer-Encoding", "binary");
                                Response.ContentType = "application/octet-stream";
                            }
                            else
                            {
                                string ext = Path.GetExtension(filename);
                                if (!string.IsNullOrEmpty(ext))
                                {
                                    ext = ext.Substring(1, ext.Length - 1); // remove first dot
                                }
                                Response.ContentType = Utils.GetAttachmentMimeTypeFromFileExtension(ext);
                            }
                        }

                        Response.BinaryWrite(buffer);
                        Response.Flush();
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(ex);
                    }
                }
                else if ((Request.QueryString["id_msg"] != null) &&
                         (Request.QueryString["uid"] != null) &&
                         (Request.QueryString["id_folder"] != null) &&
                         (Request.QueryString["folder_path"] != null))
                {
                    try
                    {
                        int  id_msg    = int.Parse(Request.QueryString["id_msg"], CultureInfo.InvariantCulture);
                        long id_folder = long.Parse(Request.QueryString["id_folder"], CultureInfo.InvariantCulture);

                        WebMailMessage msg = null;
                        MailProcessor  mp  = new MailProcessor(DbStorageCreator.CreateDatabaseStorage(Session[Constants.sessionAccount] as Account));
                        try
                        {
                            mp.Connect();
                            Folder fld = mp.GetFolder(id_folder);
                            if (fld != null)
                            {
                                msg = mp.GetMessage((fld.SyncType != FolderSyncType.DirectMode) ? (object)id_msg : HttpUtility.UrlDecode(Request.QueryString["uid"]), fld);
                            }
                        }
                        finally
                        {
                            mp.Disconnect();
                        }

                        if (msg.MailBeeMessage != null)
                        {
                            string subj = msg.MailBeeMessage.Subject;
                            //«\», «/», «?», «|», «*», «<», «>», «:»
                            string safeSubject = string.Empty;
                            for (int i = 0; i < subj.Length; i++)
                            {
                                if (subj[i] == '\\' || subj[i] == '|' || subj[i] == '/' ||
                                    subj[i] == '?' || subj[i] == '*' || subj[i] == '<' ||
                                    subj[i] == '>' || subj[i] == ':')
                                {
                                    continue;
                                }
                                safeSubject += subj[i];
                            }
                            safeSubject = safeSubject.TrimStart();
                            if (safeSubject.Length > 30)
                            {
                                safeSubject = safeSubject.Substring(0, 30).TrimEnd();
                            }
                            safeSubject = safeSubject.TrimEnd(new char[2] {
                                '.', ' '
                            });
                            if (safeSubject.Length == 0)
                            {
                                safeSubject = "message";
                            }

                            string encodedMsgFilename;
                            userAgent = Request.UserAgent;
                            if (userAgent.IndexOf("MSIE") > -1)
                            {
                                encodedMsgFilename = Server.UrlPathEncode(safeSubject);
                                Response.AddHeader("Expires", "0");
                                Response.AddHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
                                Response.AddHeader("Pragma", "public");
                            }
                            else
                            {
                                encodedMsgFilename = safeSubject;
                            }
                            //**************************************************************
                            byte[] buffer = msg.MailBeeMessage.GetMessageRawData();
                            //**************************************************************
                            Response.Clear();
                            Response.ContentType = "application/octet-stream";
                            Response.AddHeader("Accept-Ranges", "bytes");
                            Response.AddHeader("Content-Length", buffer.Length.ToString(CultureInfo.InvariantCulture));
                            Response.AddHeader("Content-Disposition", string.Format(@"attachment; filename=""{0}.eml""", encodedMsgFilename));
                            Response.AddHeader("Content-Transfer-Encoding", "binary");
                            Response.BinaryWrite(buffer);
                            Response.Flush();
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.WriteException(ex);
                    }
                }
            }
        }
コード例 #12
0
        public override Dictionary <long, string> Synchronize(FolderCollection foldersTree)
        {
            DbStorage        dbStorage = DbStorageCreator.CreateDatabaseStorage(_account);
            FolderCollection folders   = new FolderCollection();

            FolderCollection.CreateFolderListFromTree(ref folders, foldersTree);
            ArrayList pop3Uids             = new ArrayList();
            bool      downloadErrorOccured = false;

            Folder fld = folders[FolderType.Inbox];

            if (fld != null)
            {
                if (fld.SyncType == FolderSyncType.DirectMode)
                {
                    if (!_updatedFolders.ContainsKey(fld.ID))
                    {
                        _updatedFolders.Add(fld.ID, fld.FullPath);
                    }
                    return(_updatedFolders);
                }
                if (fld.SyncType == FolderSyncType.DontSync)
                {
                    return(_updatedFolders);
                }

                try
                {
                    dbStorage.Connect();

                    // get new messages start index
                    string[]  pop3DbUids     = dbStorage.GetUids();
                    string[]  pop3ServerUids = _pop3Obj.GetMessageUids();
                    ArrayList dbUidsToDelete = new ArrayList();
                    ArrayList pop3ServerIndexesToDownload = new ArrayList();

                    foreach (string pop3DbUid in pop3DbUids)
                    {
                        if (Array.IndexOf(pop3ServerUids, pop3DbUid) == -1)
                        {
                            dbUidsToDelete.Add(pop3DbUid);
                        }
                    }

                    foreach (string pop3ServerUid in pop3ServerUids)
                    {
                        if (Array.IndexOf(pop3DbUids, pop3ServerUid) == -1)
                        {
                            pop3ServerIndexesToDownload.Add(_pop3Obj.GetMessageIndexFromUid(pop3ServerUid));
                        }
                    }

                    if ((_account.MailMode == MailMode.KeepMessagesOnServer) ||
                        (_account.MailMode == MailMode.KeepMessagesOnServerAndDeleteMessageWhenItsRemovedFromTrash))
                    {
                        object[] serverUidsToDelete = dbStorage.GetOldMessagesUids(_account.MailsOnServerDays);
                        // delete from server
                        if (serverUidsToDelete.Length > 0)
                        {
                            DeleteMessages(serverUidsToDelete, fld);
                        }
                    }
                    // retrieve new messages
                    GetNewMessagesFromServerAndSaveToDb(dbStorage, fld, (int[])pop3ServerIndexesToDownload.ToArray(typeof(int)), out downloadErrorOccured, ref pop3Uids);

                    if ((fld.SyncType == FolderSyncType.NewEntireMessages) ||
                        (fld.SyncType == FolderSyncType.NewHeadersOnly))
                    {
                        return(_updatedFolders);
                    }
                    // delete messages from db
                    if (dbUidsToDelete.Count > 0)
                    {
                        WebMailMessageCollection msgsToDelete = dbStorage.LoadMessagesByUids((string[])dbUidsToDelete.ToArray(typeof(string)), fld, false);
                        dbStorage.DeleteMessages(msgsToDelete.ToIDsCollection(), fld);
                        if (!_updatedFolders.ContainsKey(fld.ID))
                        {
                            _updatedFolders.Add(fld.ID, fld.FullPath);
                        }
                    }
                }
                finally
                {
                    if (!downloadErrorOccured)
                    {
                        // get all uids and save it to db
                        pop3Uids = ArrayList.Adapter(_pop3Obj.GetMessageUids());
                        dbStorage.ReplaceUids(pop3Uids.ToArray());
                    }
                    else
                    {
                        dbStorage.SaveUids(pop3Uids.ToArray());
                    }
                    dbStorage.Disconnect();
                }
            }
            return(_updatedFolders);
        }
コード例 #13
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            string hash   = Request.QueryString["hash"] as string;
            string screen = Request.QueryString["scr"] as string;
            string to     = Request.QueryString["to"] as string;

            if ((hash != null) && (hash.Length >= 0))
            {
                WebmailSettings settings = (new WebMailSettingsCreator()).CreateWebMailSettings();
                TempRow         row      = null;
                DbStorage       storage  = DbStorageCreator.CreateDatabaseStorage(null);
                try
                {
                    storage.Connect();
                    row = storage.GetTempRow(-1, string.Format(@"sessionHash_{0}", hash));
                    if (row != null)
                    {
                        storage.DeleteTempRow(row.ID);
                    }
                    else
                    {
                        throw new WebMailException("Temp Row Is NULL");
                    }
                }
                catch (Exception ex)
                {
                    Log.WriteException(ex);
                    Response.Redirect(@"../default.aspx", true);
                }
                finally
                {
                    storage.Disconnect();
                }

                if (row != null)
                {
                    Account acct = Account.LoadFromDb(row.IDAcct, -1, false);
                    if (Session[Constants.sessionAccount] == null)
                    {
                        Session.Add(Constants.sessionAccount, acct);
                    }
                    else
                    {
                        Session[Constants.sessionAccount] = acct;
                    }
                    if (Session[Constants.sessionUserID] == null)
                    {
                        Session.Add(Constants.sessionUserID, acct.IDUser);
                    }
                    else
                    {
                        Session[Constants.sessionUserID] = acct.IDUser;
                    }

                    WMStartPage page = WMStartPage.Mailbox;
                    try
                    {
                        short scrNum = short.Parse(screen);
                        page = (WMStartPage)scrNum;
                    } catch {}
                    switch (page)
                    {
                    case WMStartPage.NewMessage:
                        if (to != null)
                        {
                            to = string.Format(@"&to={0}", to);
                        }
                        goto default;

                    case WMStartPage.Settings:
                        goto default;

                    case WMStartPage.Contacts:
                        goto default;

                    case WMStartPage.Mailbox:
                        goto default;

                    case WMStartPage.Calendar:
                        goto default;

                    default:
                        string check = string.Empty;
                        if (acct.GetMailAtLogin)
                        {
                            check = "check=1&";
                        }
                        HttpContext.Current.Response.Redirect(string.Format(@"../webmail.aspx?" + check + @"start={0}{1}", (int)page, to));
                        break;
                    }
                }
            }
        }