Exemplo n.º 1
0
        public override WebMailMessageCollection LoadMessages(Folder fld)
        {
            WebMailMessageCollection returnColl = new WebMailMessageCollection();
            MailMessageCollection    messages;

            try
            {
                messages = _pop3Obj.DownloadEntireMessages();
            }
            catch (MailBeeException ex)
            {
                Log.WriteException(ex);
                throw new WebMailMailBeeException(ex);
            }
            if (messages != null)
            {
                foreach (MailMessage msg in messages)
                {
                    WebMailMessage webMsg = new WebMailMessage(_account);
                    webMsg.Init(msg, true, fld);
                    returnColl.Add(webMsg);
                }
            }
            return(returnColl);
        }
Exemplo n.º 2
0
        public override WebMailMessageCollection LoadMessages(object[] messageIndexSet, Folder fld)
        {
            WebMailMessageCollection msgsColl = new WebMailMessageCollection();

            foreach (string uid in messageIndexSet)
            {
                int index = _pop3Obj.GetMessageIndexFromUid(uid);
                if (index > 0)
                {
                    try
                    {
                        WebMailMessage webMsg = new WebMailMessage(_account);
                        webMsg.Init(_pop3Obj.DownloadEntireMessage(index), true, fld);
                        msgsColl.Add(webMsg);
                    }
                    catch (MailBeeException ex)
                    {
                        Log.WriteException(ex);
                        throw new WebMailMailBeeException(ex);
                    }
                }
                else
                {
                    continue;
                }
            }
            return(msgsColl);
        }
Exemplo n.º 3
0
        public override WebMailMessageCollection LoadMessageHeaders(object[] messageIndexSet, Folder fld)
        {
            WebMailMessageCollection msgsColl = new WebMailMessageCollection();

            foreach (object uid in messageIndexSet)
            {
                int index = _pop3Obj.GetMessageIndexFromUid(Convert.ToString(uid));
                if (index > 0)
                {
                    try
                    {
                        WebMailMessage webMsg = new WebMailMessage(_account);
                        webMsg.Init(_pop3Obj.DownloadMessageHeader(index), true, fld);
                        if (fld.SyncType == FolderSyncType.DirectMode)
                        {
                            webMsg.Seen = true;
                        }
                        msgsColl.Add(webMsg);
                    }
                    catch (MailBeeException ex)
                    {
                        Log.WriteException(ex);
                        throw new WebMailMailBeeException(ex);
                    }
                }
                else
                {
                    continue;
                }
            }
            return(msgsColl);
        }
 public WebMailMessageCollection(Account acct, MailMessageCollection messageCollection, bool isUidStr, Folder fld)
 {
     foreach (MailMessage msg in messageCollection)
     {
         WebMailMessage webMsg = new WebMailMessage(acct);
         webMsg.Init(msg, isUidStr, fld);
         Add(webMsg);
     }
 }
Exemplo n.º 5
0
        public WebMailMessage LoadMessage(object index, Folder fld, bool markSeen)
        {
            int            id_msg = ObjectToInt32(index);
            WebMailMessage msg    = _dbMan.SelectMessage(id_msg, fld);

            if (markSeen && msg != null && !msg.Seen)
            {
                // mark as seen
                msg.Seen = true;
                _dbMan.UpdateMessage(msg);
            }
            return(msg);
        }
 public object[] ToIDsCollection()
 {
     object[] result = new object[List.Count];
     for (int i = 0; i < List.Count; i++)
     {
         WebMailMessage msg = List[i] as WebMailMessage;
         if (msg != null)
         {
             result[i] = msg.IDMsg;
         }
     }
     return(result);
 }
Exemplo n.º 7
0
        public FilterAction GetActionToApply(WebMailMessage msg)
        {
            string str = null;

            switch (_field)
            {
            case FilterField.From:
            {
                str = msg.FromMsg.ToString();
            }
            break;

            case FilterField.To:
            {
                str = msg.ToMsg.ToString();
            }
            break;

            case FilterField.Subject:
            {
                str = msg.Subject;
            }
            break;

            case FilterField.XSpamHeader:
            {
                HeaderCollection spamHeaders = msg.MailBeeMessage.Headers.Items("X-Spam-Header");
                if (spamHeaders != null && spamHeaders.Count > 0)
                {
                    str = spamHeaders[0].Value;
                }
            }
            break;

            case FilterField.XVirusHeader:
            {
                HeaderCollection virusHeaders = msg.MailBeeMessage.Headers.Items("X-Virus-Header");
                if (virusHeaders != null && virusHeaders.Count > 0)
                {
                    str = virusHeaders[0].Value;
                }
            }
            break;
            }
            if (str != null)
            {
                return(ProcessMessage(str));
            }
            return(FilterAction.DoNothing);
        }
 public object[] ToUidsCollection(bool isStrUid)
 {
     object[] result = new object[List.Count];
     for (int i = 0; i < List.Count; i++)
     {
         WebMailMessage msg = List[i] as WebMailMessage;
         if (msg != null)
         {
             object temp = (isStrUid) ? (object)msg.StrUid : (object)msg.IntUid;
             if (temp.ToString() != "-1")
             {
                 result[i] = temp;
             }
         }
     }
     return(result);
 }
Exemplo n.º 9
0
        public override WebMailMessage LoadMessage(object index, Folder fld)
        {
            int indexOnServer = _pop3Obj.GetMessageIndexFromUid(index.ToString());

            try
            {
                if (indexOnServer > 0)
                {
                    WebMailMessage webMsg = new WebMailMessage(_account);
                    MailMessage    msg    = _pop3Obj.DownloadEntireMessage(indexOnServer);
                    webMsg.Init(msg, true, fld);
                    return(webMsg);
                }
                throw new WebMailMailBoxException((new WebmailResourceManagerCreator()).CreateResourceManager().GetString("PROC_MSG_HAS_DELETED"));
            }
            catch (MailBeeException ex)
            {
                Log.WriteException(ex);
                throw new WebMailMailBeeException(ex);
            }
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            bool showPicturesSettings = false;

            acct = Session[Constants.sessionAccount] as Account;
            if (acct == null)
            {
                Response.Redirect("default.aspx", true);
            }
            else
            {
                if (acct.UserOfAccount.Settings.RTL)
                {
                    _stylesRtl = true;
                }
                defaultSkin = Utils.EncodeJsSaveString(acct.UserOfAccount.Settings.DefaultSkin);
                _manager    = (new WebmailResourceManagerCreator()).CreateResourceManager();
                if ((acct.UserOfAccount != null) && (acct.UserOfAccount.Settings != null))
                {
                    showPicturesSettings = ((acct.UserOfAccount.Settings.ViewMode & ViewMode.AlwaysShowPictures) > 0) ? true : false;
                }

                try {
                    int    charset;
                    string full_name_folder;
                    long   id_folder;
                    string uid;
                    int    id;
                    if (Request.QueryString["id"] != null)
                    {
                        id               = Convert.ToInt32(Request.QueryString["id"]);
                        uid              = Request.QueryString["uid"];
                        id_folder        = Convert.ToInt64(Request.QueryString["id_folder"]);
                        full_name_folder = Request.QueryString["full_name_folder"];
                        charset          = Convert.ToInt32(Request.QueryString["charset"]);
                    }
                    else
                    {
                        id               = (int)Session["id"];
                        uid              = (string)Session["uid"];
                        id_folder        = (long)Session["id_folder"];
                        full_name_folder = (string)Session["full_name_folder"];
                        charset          = (int)Session["charset"];
                    }

                    IsHTMLMsg = false;
                    msgPlain  = null;
                    msgHTML   = null;
                    BaseWebMailActions bwml = new BaseWebMailActions(acct, Page);
                    if (showPicturesSettings)
                    {
                        msg = bwml.GetMessage(id, uid, id_folder, charset, 1, true, false, false, MessageMode.None);
                    }
                    else
                    {
                        msg = bwml.GetMessage(id, uid, id_folder, full_name_folder, charset, false, MessageMode.None);
                    }
                    LabelFrom.Text = Server.HtmlEncode(msg.FromMsg.ToString());
                    LabelTo.Text   = Server.HtmlEncode(msg.ToMsg.ToString());
                    CcAddr         = msg.CcMsg.ToString();
                    if (CcAddr != string.Empty)
                    {
                        LabelCc.Text = Server.HtmlEncode(msg.CcMsg.ToString());
                    }
                    DateFormatting df = new DateFormatting(acct, msg.MsgDate);
                    LabelDate.Text    = df.FullDate;
                    LabelSubject.Text = Server.HtmlEncode(msg.Subject);

                    AttachmentCollection AttachmentsColl = msg.MailBeeMessage.Attachments;

                    StringBuilder sb = new StringBuilder();
                    foreach (Attachment Attach in AttachmentsColl)
                    {
                        sb.AppendFormat(@"{0}, ", Attach.Filename);
                    }
                    if (sb.Length > 2)
                    {
                        sb.Remove(sb.Length - 2, 2);
                    }
                    Attachments = sb.ToString();
                    if (Attachments.Length > 0)
                    {
                        LabelAttachments.Text = Attachments;
                    }

                    msgPlain = Utils.MakeHtmlBodyFromPlainBody(msg.MailBeeMessage.BodyPlainText, true, "");
                    msgHTML  = msg.MailBeeMessage.BodyHtmlText;
                    if (msgPlain == "")
                    {
                        msgPlain = Utils.ConvertHtmlToPlain(msgHTML);
                    }
                    if (msgHTML != "")
                    {
                        IsHTMLMsg = true;
                        //Message body
                        MessageBody.Text = msgHTML;
                    }
                    else
                    {
                        IsHTMLMsg        = false;
                        MessageBody.Text = msgPlain;
                    }
                }
                catch (Exception ex) {
                    Log.WriteException(ex);
                    Response.Write(ex.Message);
                }
            }
        }
Exemplo n.º 11
0
 public virtual void SaveMessage(WebMailMessage message, Folder fld)
 {
 }
Exemplo n.º 12
0
        public static void SendMail(Account account, WebMailMessage message)
        {
            Random rnd                     = new Random();
            int    pid                     = rnd.Next(1000, 9999);
            string MessageFileName         = Utils.GetUnixTimeStamp().ToString() + "-001." + pid.ToString() + ".LOCALXMAIL";
            string MessageTempFileNamePath = Path.Combine(Path.Combine(WmServerRootPath, @"spool\temp\"), MessageFileName);
            string MessageFileNamePath     = Path.Combine(Path.Combine(WmServerRootPath, @"spool\local\"), MessageFileName);

            /*for demo*/
            const string demoDomain       = "afterlogic.com";
            const string demoErrorMessage = "For security reasons, sending e-mail from this account to external " +
                                            "addresses is disabled. Please send to [email protected] or relogin in Advanced Login mode using your " +
                                            "mail account on another mail server.";

            if (account.IsDemo)
            {
                for (int i = 0; i < message.MailBeeMessage.To.Count; i++)
                {
                    int    dogPos = message.MailBeeMessage.To[i].Email.IndexOf("@");
                    string domain = message.MailBeeMessage.To[i].Email.Substring(dogPos + 1);
                    if (domain != demoDomain)
                    {
                        throw new WebMailException(demoErrorMessage);
                    }
                }
                for (int i = 0; i < message.MailBeeMessage.Cc.Count; i++)
                {
                    int    dogPos = message.MailBeeMessage.Cc[i].Email.IndexOf("@");
                    string domain = message.MailBeeMessage.Cc[i].Email.Substring(dogPos + 1);
                    if (domain != demoDomain)
                    {
                        throw new WebMailException(demoErrorMessage);
                    }
                }
                for (int i = 0; i < message.MailBeeMessage.Bcc.Count; i++)
                {
                    int    dogPos = message.MailBeeMessage.Bcc[i].Email.IndexOf("@");
                    string domain = message.MailBeeMessage.Bcc[i].Email.Substring(dogPos + 1);
                    if (domain != demoDomain)
                    {
                        throw new WebMailException(demoErrorMessage);
                    }
                }
            }

            StreamWriter sw = File.CreateText(MessageTempFileNamePath);

            sw.WriteLine(string.Format(@"mail from:<{0}>", message.MailBeeMessage.From.Email));

            sw.WriteLine(string.Format(@"mail from:<{0}>", account.Email));

            foreach (EmailAddress eAddress in message.MailBeeMessage.To)
            {
                sw.WriteLine(string.Format(@"rcpt to:<{0}>", eAddress.Email));
            }

            foreach (EmailAddress eAddressCc in message.MailBeeMessage.Cc)
            {
                sw.WriteLine(string.Format(@"rcpt to:<{0}>", eAddressCc.Email));
            }

            foreach (EmailAddress eAddressBcc in message.MailBeeMessage.Bcc)
            {
                sw.WriteLine(string.Format(@"rcpt to:<{0}>", eAddressBcc.Email));
            }

            message.MailBeeMessage.Bcc.Clear();

            sw.WriteLine();
            sw.Write(Encoding.UTF8.GetString(message.MailBeeMessage.GetMessageRawData()));
            sw.WriteLine();
            sw.Close();

            File.Move(MessageTempFileNamePath, MessageFileNamePath);
        }
        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);
                    }
                }
            }
        }
 public void Remove(WebMailMessage value)
 {
     List.Remove(value);
 }
Exemplo n.º 15
0
 // true if successfull, otherwise false
 public static void SendMail(Account account, WebMailMessage message)
 {
     SendMail(account, message, string.Empty);
 }
Exemplo n.º 16
0
 public override void SaveMessage(WebMailMessage message, Folder fld)
 {
     _dbMan.SaveMessage(-1, message, fld);
 }
 public void Insert(int index, WebMailMessage value)
 {
     List.Insert(index, value);
 }
 public int Add(WebMailMessage value)
 {
     return(List.Add(value));
 }
Exemplo n.º 19
0
 public virtual void SaveMessage(int id_msg, WebMailMessage message, Folder fld)
 {
     _dbMan.SaveMessage(id_msg, message, fld);
 }
Exemplo n.º 20
0
        public static void SendMail(Account account, WebMailMessage message, string dataFolder)
        {
            WebmailResourceManager resMan;

            if (dataFolder != string.Empty)
            {
                resMan = new WebmailResourceManager(dataFolder);
            }
            else
            {
                resMan = (new WebmailResourceManagerCreator()).CreateResourceManager();
            }

            try
            {
                MailMessage messageToSend = new MailMessage();
                messageToSend.Priority    = message.MailBeeMessage.Priority;
                messageToSend.Sensitivity = message.MailBeeMessage.Sensitivity;

                messageToSend.From          = message.MailBeeMessage.From;
                messageToSend.To            = message.MailBeeMessage.To;
                messageToSend.Cc            = message.MailBeeMessage.Cc;
                messageToSend.Bcc           = message.MailBeeMessage.Bcc;
                messageToSend.Subject       = message.MailBeeMessage.Subject;
                messageToSend.ConfirmRead   = message.MailBeeMessage.ConfirmRead;
                messageToSend.Date          = DateTime.Now;
                messageToSend.BodyHtmlText  = message.MailBeeMessage.BodyHtmlText;
                messageToSend.BodyPlainText = message.MailBeeMessage.BodyPlainText;



                if (HttpContext.Current != null)
                {
                    string str = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    messageToSend.Headers.Add("X-Originating-IP", str, false);
                }

                foreach (Attachment attach in message.MailBeeMessage.Attachments)
                {
                    messageToSend.Attachments.Add(attach);
                }

                WebmailSettings settings;
                if (dataFolder != string.Empty)
                {
                    settings = (new WebMailSettingsCreator()).CreateWebMailSettings(dataFolder);
                }
                else
                {
                    settings = (new WebMailSettingsCreator()).CreateWebMailSettings();
                }


                MailBee.SmtpMail.Smtp.LicenseKey = settings.LicenseKey;


                MailBee.SmtpMail.Smtp objSmtp = new MailBee.SmtpMail.Smtp();

                if (settings.EnableLogging)
                {
                    objSmtp.Log.Enabled = true;

                    if (dataFolder != string.Empty)
                    {
                        objSmtp.Log.Filename = Path.Combine(dataFolder, Constants.logFilename);
                    }
                    else
                    {
                        string dataFolderPath = Utils.GetDataFolderPath();
                        if (dataFolderPath != null)
                        {
                            objSmtp.Log.Filename = Path.Combine(dataFolderPath, Constants.logFilename);
                        }
                    }
                }

                SmtpServer server = new SmtpServer();
//                server.SmtpOptions = ExtendedSmtpOptions.NoChunking;
                server.Name        = !string.IsNullOrEmpty(account.MailOutgoingHost) ? account.MailOutgoingHost : account.MailIncomingHost;
                server.Port        = account.MailOutgoingPort;
                server.AccountName = !string.IsNullOrEmpty(account.MailOutgoingLogin) ? account.MailOutgoingLogin : account.MailIncomingLogin;
                server.Password    = (!string.IsNullOrEmpty(account.MailOutgoingPassword)) ? account.MailOutgoingPassword : account.MailIncomingPassword;

                if (account.MailOutgoingAuthentication)
                {
                    server.AuthMethods = AuthenticationMethods.Auto;
                    server.AuthOptions = AuthenticationOptions.PreferSimpleMethods;
                }

                if (server.Port == 465)
                {
                    server.SslMode     = SslStartupMode.OnConnect;
                    server.SslProtocol = SecurityProtocol.Auto;
                    server.SslCertificates.AutoValidation = CertificateValidationFlags.None;
                }

                if (server.Port == 587 && Constants.UseStartTLS)
                {
                    server.SslMode = SslStartupMode.UseStartTlsIfSupported;
                }

                objSmtp.SmtpServers.Add(server);

                Encoding outgoingCharset = Utils.GetOutCharset(account.UserOfAccount.Settings);
                messageToSend.Charset = outgoingCharset.HeaderName;

                objSmtp.Message = messageToSend;

                try
                {
                    objSmtp.Connect();

                    objSmtp.Send();
                }
                catch (MailBeeGetHostNameException ex)
                {
                    Log.WriteException(ex);
                    throw new WebMailException(resMan.GetString("ErrorSMTPConnect"));
                }
                catch (MailBeeConnectionException ex)
                {
                    Log.WriteException(ex);
                    throw new WebMailException(resMan.GetString("ErrorSMTPConnect"));
                }
                catch (MailBeeSmtpLoginBadCredentialsException ex)
                {
                    Log.WriteException(ex);
                    throw new WebMailException(resMan.GetString("ErrorSMTPAuth"));
                }
                catch (MailBeeException ex)
                {
                    Log.WriteException(ex);
                    throw new WebMailMailBeeException(ex);
                }
                finally
                {
                    if (objSmtp.IsConnected)
                    {
                        objSmtp.Disconnect();
                    }
                }
            }
            catch (MailBeeException ex)
            {
                Log.WriteException(ex);
                throw new WebMailMailBeeException(ex);
            }
        }
Exemplo n.º 21
0
        protected void PrepareViewMessage()
        {
            if (openMode != "view")
            {
                return;
            }

            BaseWebMailActions bwml   = new BaseWebMailActions(acct, Page);
            byte safety               = 0;
            bool showPicturesSettings = ((acct.UserOfAccount.Settings.ViewMode & ViewMode.AlwaysShowPictures) > 0) ? true : false;

            if (showPicturesSettings)
            {
                safety = 1;
            }
            WebMailMessage msg       = bwml.GetMessage(msgId, msgUid, folderId, charset, safety, true, false, false, MessageMode.None);
            MailMessage    outputMsg = msg.MailBeeMessage;

            jsClearMessageSubject = Utils.EncodeJsSaveString(outputMsg.Subject) + " - ";

            jsMessageInit  = "ViewMessage = new CMessage();\n";
            jsMessageInit += "ViewMessage.FolderId = " + msg.IDFolderDB.ToString() + ";\n";
            jsMessageInit += "ViewMessage.FolderFullName = '" + msg.FolderFullName + "';\n";
            jsMessageInit += "ViewMessage.Size = " + msg.Size.ToString() + ";\n";
            jsMessageInit += "ViewMessage.Id = " + msg.IDMsg.ToString() + ";\n";
            jsMessageInit += "ViewMessage.Uid = '" + (string.IsNullOrEmpty(msg.StrUid)
                                ? msg.IntUid.ToString() : msg.StrUid) + "';\n";
            jsMessageInit += "ViewMessage.HasHtml = " + (string.IsNullOrEmpty(outputMsg.BodyHtmlText)
                                ? "false" : "true") + ";\n";
            jsMessageInit += "ViewMessage.HasPlain = " + (string.IsNullOrEmpty(outputMsg.BodyPlainText)
                                ? "false" : "true") + ";\n";
            jsMessageInit += "ViewMessage.Importance = " + Utils.ToStringPriority(msg.Priority) + ";\n";
            jsMessageInit += "ViewMessage.Sensivity = " + Utils.ToStringSensitivity(msg.Sensitivity) + ";\n";
            jsMessageInit += "ViewMessage.Charset = " + msg.OverrideCharset.ToString(CultureInfo.InvariantCulture) + ";\n";
            jsMessageInit += "ViewMessage.HasCharset = " + (string.IsNullOrEmpty(outputMsg.Charset)
                                ? "false" : "true") + ";\n";
            string strCharset = !string.IsNullOrEmpty(outputMsg.Charset)
                                ? outputMsg.Charset
                                : Utils.GetCodePageName(msg.OverrideCharset);
            string rtl = (Utils.IsRtlCharset(strCharset, acct.UserOfAccount.Settings.RTL)) ? "true" : "false";

            jsMessageInit += "ViewMessage.RTL = " + rtl + ";\n";
            jsMessageInit += "ViewMessage.Safety = " + msg.Safety.ToString(CultureInfo.InvariantCulture) + ";\n";
            jsMessageInit += "ViewMessage.Downloaded = " + ((msg.Downloaded) ? "true" : "false") + ";\n";

            jsMessageInit += "ViewMessage.FromAddr = '" + Utils.EncodeJsSaveString(outputMsg.From.ToString()) + "';\n";
            jsMessageInit += "ViewMessage.FromDisplayName = '" + Utils.EncodeJsSaveString(outputMsg.From.DisplayName) + "';\n";
            jsMessageInit += "ViewMessage.ToAddr = '" + Utils.EncodeJsSaveString(outputMsg.To.ToString()) + "';\n";
            string shortTo = string.Empty;

            if ((outputMsg.To.ToString().IndexOf(acct.Email) == -1) && (outputMsg.To.Count > 0))
            {
                shortTo = (outputMsg.To[0].DisplayName.Length > 0) ? outputMsg.To[0].DisplayName : outputMsg.To[0].Email;
            }
            jsMessageInit += "ViewMessage.ShortToAddr = '" + Utils.EncodeJsSaveString(shortTo) + "';\n";
            jsMessageInit += "ViewMessage.CCAddr = '" + Utils.EncodeJsSaveString(outputMsg.Cc.ToString()) + "';\n";
            jsMessageInit += "ViewMessage.BCCAddr = '" + Utils.EncodeJsSaveString(outputMsg.Bcc.ToString()) + "';\n";
            jsMessageInit += "ViewMessage.ReplyToAddr = '" + Utils.EncodeJsSaveString(outputMsg.ReplyTo.ToString()) + "';\n";
            jsMessageInit += "ViewMessage.Subject = '" + Utils.EncodeJsSaveString(outputMsg.Subject) + "';\n";
            DateFormatting df = new DateFormatting(acct, msg.MsgDate);

            jsMessageInit += "ViewMessage.Date = '" + Utils.EncodeJsSaveString(df.ShortDate) + "';\n";
            jsMessageInit += "ViewMessage.FullDate = '" + Utils.EncodeJsSaveString(df.FullDate) + "';\n";
            jsMessageInit += "ViewMessage.Time = '" + Utils.EncodeJsSaveString(df.Time) + "';\n";

            jsMessageInit += "ViewMessage.HtmlBody = '" + Utils.EncodeJsSaveString(outputMsg.BodyHtmlText) + "';\n";
            jsMessageInit += "ViewMessage.PlainBody = '" + Utils.EncodeJsSaveString(Utils.MakeHtmlBodyFromPlainBody(outputMsg.BodyPlainText, true, "")) + "';\n";

            string replyHtml = Utils.GetMessageHtmlReplyToBody(acct, outputMsg);

            jsMessageInit += "ViewMessage.ReplyHtml = '" + Utils.EncodeJsSaveString(replyHtml) + "';\n";
            jsMessageInit += "ViewMessage.IsReplyHtml = true;\n";
            jsMessageInit += "ViewMessage.ForwardHtml = ViewMessage.ReplyHtml;\n";
            jsMessageInit += "ViewMessage.IsForwardHtml = true;\n";
            string replyPlain = Utils.GetMessagePlainReplyToBody(acct, outputMsg);

            jsMessageInit += "ViewMessage.ReplyPlain = '" + Utils.EncodeJsSaveString(replyPlain) + "';\n";
            jsMessageInit += "ViewMessage.IsReplyPlain = true;\n";
            jsMessageInit += "ViewMessage.ForwardPlain = ViewMessage.ReplyPlain;\n";
            jsMessageInit += "ViewMessage.IsForwardPlain = true;\n";

            if (outputMsg.Attachments.Count > 0)
            {
                jsMessageInit += "ViewMessage.Attachments = [];\n";
                foreach (Attachment attach in outputMsg.Attachments)
                {
                    string _downloadlink = string.Empty;
                    if (string.IsNullOrEmpty(attach.SavedAs))
                    {
                        _downloadlink = Utils.GetAttachmentDownloadLink(outputMsg, attach, folderFullName, false, Page.Session);
                    }
                    else
                    {
                        _downloadlink = Utils.GetAttachmentDownloadLink(attach, false);
                    }
                    string _viewlink = string.Empty;
                    if (string.IsNullOrEmpty(attach.SavedAs))
                    {
                        _viewlink = Utils.GetAttachmentDownloadLink(outputMsg, attach, folderFullName, true, Page.Session);
                    }
                    else
                    {
                        _viewlink = Utils.GetAttachmentDownloadLink(attach, true);
                    }
                    string filename = Path.GetFileName(attach.SavedAs);
                    jsMessageInit += "ViewMessage.Attachments.push({" + String.Format(@"Id: {0}, Inline: {1}, FileName: '{2}', Size: {3}, Download: '{4}', View: '{5}', TempName: '{6}', MimeType: '{7}'",
                                                                                      "-1",
                                                                                      (attach.IsInline) ? "true" : "false",
                                                                                      (attach.Filename.Length > 0) ? attach.Filename : attach.Name,
                                                                                      attach.Size.ToString(),
                                                                                      _downloadlink,
                                                                                      _viewlink,
                                                                                      filename,
                                                                                      Utils.GetAttachmentMimeTypeFromFileExtension(Path.GetExtension(filename))) + "});\n";
                }
            }

            jsMessageInit += "ViewMessage.SaveLink = '" + Utils.GetMessageDownloadLink(msg, folderId, folderFullName) + "';\n";
            jsMessageInit += "ViewMessage.PrintLink = '" + Utils.GetMessagePrintLink(msg, folderId, folderFullName) + "';\n";
        }
 public bool Contains(WebMailMessage value)
 {
     // If value is not of type WebMailMessage, this will return false.
     return(List.Contains(value));
 }
 public int IndexOf(WebMailMessage value)
 {
     return(List.IndexOf(value));
 }
Exemplo n.º 24
0
 public virtual void UpdateMessage(WebMailMessage message)
 {
     _dbMan.UpdateMessage(message);
 }