コード例 #1
0
ファイル: MailViewWindow.xaml.cs プロジェクト: nbhopson/QMail
        private void showMail(ASObject mail)
        {
            try
            {
                webBrowser.Navigate("about:blank");
                attachments.Children.Clear();

                Subject.Text = mail["subject"] as string;
                DateTime date = (DateTime)mail["mail_date"];
                if (date != null)
                    Date.Text = date.ToString("yyyy-MM-dd HH:mm");
                else
                    Date.Text = "";

                Sender.Text = mail["mail_from_label"] as string;

                int customer_grade = mail.getInt("customer_grade");

                GradeLabel.Text = getGradeLabel(customer_grade);
                GradeImage.Source = getGradeImage(customer_grade);

                int handle_action = mail.getInt("handle_action");
                HandleActionLabel.Text = getHandleAction(handle_action);
                HandleActionImage.Source = getHandleActionImage(handle_action);

                /*
                string remark = mail.getString("remark");
                if (String.IsNullOrWhiteSpace(remark))
                    txtRemark.Visibility = System.Windows.Visibility.Collapsed;
                else
                    txtRemark.Text = remark;
                 * */

                string contents = mail["contents"] as string;
                if (!String.IsNullOrEmpty(contents))
                {
                    XmlDocument contentsXml = new XmlDocument();
                    contentsXml.LoadXml(CleanInvalidXmlChars(contents));
                    string htmlfile = null;
                    bool hasText = false;
                    string root_path;

                    root_path = Desktop.instance.ApplicationPath + "/mail/" + mail["mail_file"];
                    DirectoryInfo dirinfo = Directory.GetParent(root_path);
                    root_path = dirinfo.FullName + "/" + mail["uuid"] + ".parts/";

                    foreach (XmlElement xml in contentsXml.GetElementsByTagName("PART"))
                    {
                        string type = xml.GetAttribute("type");
                        if (type == "html")
                        {
                            htmlfile = root_path + mail["uuid"] + ".html";
                        }
                        else if (type == "text")
                        {
                            hasText = true;
                        }
                        else if (type == "file")
                        {
                            if (String.IsNullOrEmpty(xml.GetAttribute("content-id")))
                            {
                                AttachmentItem item = new AttachmentItem();
                                item.SetAttachment(root_path + xml.GetAttribute("filename"));
                                attachments.Children.Add(item);
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(htmlfile))
                    {
                        if (File.Exists(htmlfile))
                        {
                            Uri uri = new Uri("file:///" + htmlfile);
                            webBrowser.Navigate(uri);
                        }
                    }
                    else if (hasText)
                    {
                        string textfile = root_path + mail["uuid"] + ".text.html";
                        if (File.Exists(textfile))
                        {
                            Uri uri = new Uri("file:///" + textfile);
                            webBrowser.Navigate(uri);
                        }
                    }
                }

                txtFrom.Text = mail.getString("country_from");
                txtArea.Text = (String.IsNullOrWhiteSpace(mail.getString("area_from")) ? "" : mail.getString("area_from"));
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.Write(e.StackTrace);
                ime.controls.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #2
0
ファイル: MailSendWindow.xaml.cs プロジェクト: nbhopson/QMail
 void btnAddAttachement_Click(object sender, RoutedEventArgs e)
 {
     this.Dispatcher.BeginInvoke((System.Action)delegate
     {
         OpenFileDialog ofld = new OpenFileDialog();
         ofld.Title = "选择文件";
         ofld.Multiselect = true;
         ofld.Filter = "所有文件*.*|*.*";
         if (ofld.ShowDialog() == true)
         {
             string[] filenames = ofld.FileNames;
             foreach (string filename in filenames)
             {
                 if (isExist(filename))
                     continue;
                 AttachmentItem item = new AttachmentItem();
                 item.Editable = false;
                 item.SetAttachment(filename);
                 attachments.Children.Add(item);
             }
         }
     }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
 }
コード例 #3
0
ファイル: MailReader.xaml.cs プロジェクト: nbhopson/QMail
        public void ShowMail(ASObject mail, bool isSearch = false)
        {
            btnGrade.IsEnabled = !isSearch;
            btnRemark.IsEnabled = !isSearch;
            btnHandle.IsEnabled = !isSearch;

            if (mail.getString("folder") != "INBOX" && !isSearch)
            {
                btnGrade.IsEnabled = false;
                btnRemark.IsEnabled = false;
                btnHandle.IsEnabled = false;
            }

            hideTranslate();

            tobTranslate.IsChecked = false;

            this.mail = mail;
            try
            {
                root.Visibility = System.Windows.Visibility.Visible;
                Mouse.OverrideCursor = Cursors.Wait;

                webBrowser.Navigate("about:blank");
                attachments.Children.Clear();

                txtSubject.Text = mail["subject"] as string;
                DateTime date = (DateTime)mail["mail_date"];
                if (date != null)
                    txtDate.Text = date.ToString("yyyy-MM-dd HH:mm");
                else
                    txtDate.Text = "";

                txtSender.Text = mail["mail_from_label"] as string;

                int customer_grade = mail.getInt("customer_grade");

                txtGradeLabel.Text = getGradeLabel(customer_grade);
                imgGrade.Source = getGradeImage(customer_grade);

                int handle_action = mail.getInt("handle_action");
                txtHandleAction.Text = getHandleAction(handle_action);
                imgHandleAction.Source = getHandleActionImage(handle_action);

                string contents = mail["contents"] as string;
                string file = Desktop.instance.ApplicationPath + "/mail/" + mail["mail_file"];
                if (String.IsNullOrEmpty(contents) || !File.Exists(file))
                {
                    if (!isSearch)
                    {
                        MailWorker.instance.ParseMail(mail);
                        MailWorker.instance.updateMailRecord(mail, new string[] { "attachments", "contents" });
                    }
                    else
                        MailWorker.instance.ParseMail(mail);
                    contents = mail["contents"] as string;
                }
                XmlDocument contentsXml = new XmlDocument();
                if (!String.IsNullOrEmpty(contents))
                {
                    contentsXml.LoadXml(CleanInvalidXmlChars(contents));
                    string htmlfile = null;
                    bool hasText = false;
                    string root_path;

                    root_path = Desktop.instance.ApplicationPath + "/mail/" + mail["mail_file"];
                    DirectoryInfo dirinfo = Directory.GetParent(root_path);
                    root_path = dirinfo.FullName + "/" + mail["uuid"] + ".parts/";

                    foreach (XmlElement xml in contentsXml.GetElementsByTagName("PART"))
                    {
                        string type = xml.GetAttribute("type");
                        if (type == "html")
                        {
                            htmlfile = root_path + mail["uuid"] + ".html";
                        }
                        else if (type == "text")
                        {
                            hasText = true;
                        }
                        else if (type == "file")
                        {
                            if (String.IsNullOrEmpty(xml.GetAttribute("content-id")))
                            {
                                AttachmentItem item = new AttachmentItem();
                                item.SetAttachment(root_path + xml.GetAttribute("filename"));
                                attachments.Children.Add(item);
                            }
                        }
                    }

                    if (!String.IsNullOrEmpty(htmlfile))
                    {
                        if (File.Exists(htmlfile))
                        {
                            Uri uri = new Uri("file:///" + htmlfile);
                            webBrowser.Navigate(uri);
                        }
                    }
                    else if (hasText)
                    {
                        string textfile = root_path + mail["uuid"] + ".text.html";
                        if (File.Exists(textfile))
                        {
                            Uri uri = new Uri("file:///" + textfile);
                            webBrowser.Navigate(uri);
                        }
                    }
                }

                string country_from = mail["country_from"] as string;
                object ip_from = mail["ip_from"];
                if (String.IsNullOrWhiteSpace(country_from))
                {
                    //var remote_ip_info = {"ret":1,"start":"210.75.64.0","end":"210.75.95.255","country":"\u4e2d\u56fd","province":"\u4e0a\u6d77","city":"\u4e0a\u6d77","district":"","isp":"","type":"\u4f01\u4e1a","desc":"\u4e0a\u6d77\u901a\u7528\u6c7d\u8f66\u516c\u53f8"};
                    string url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=";
                    country_from = FileLoader.loadFile(url + ip_from, null);
                    string begin = "{";
                    string end = "}";
                    country_from = country_from.Substring(country_from.IndexOf(begin));
                    country_from = country_from.Substring(0, country_from.IndexOf(end) + 1);
                    ASObject json = JsonUtil.toASObject(JObject.Parse(country_from));
                    if (json.getInt("ret") == -1)
                    {
                        mail["country_from"] = "未知";
                        if (!isSearch)
                            MailWorker.instance.updateMail(mail, new string[] { "country_from" });
                    }
                    else
                    {
                        mail["country_from"] = json.getString("country");//MailWorker.instance.getCountryCode(json.getString("country"));
                        string area_from = String.IsNullOrWhiteSpace(json.getString("province")) ? "" : json.getString("province");
                        if (!String.IsNullOrWhiteSpace(area_from) && !String.IsNullOrWhiteSpace(json.getString("city")))
                            area_from += "/" + json.getString("city");
                        if (!String.IsNullOrWhiteSpace(area_from))
                            mail["area_from"] = area_from;
                        if (!isSearch)
                            MailWorker.instance.updateMail(mail, new string[] { "country_from", "area_from" });
                    }
                }

                txtFrom.Text = mail.getString("country_from");
                txtArea.Text = (String.IsNullOrWhiteSpace(mail.getString("area_from")) ? "" : mail.getString("area_from"));

                //检查阅读回折

                if (mail.getString("flags") == "RECEIPT")
                {
                    string to = mail.getString("contact_mail");
                    this.Dispatcher.BeginInvoke((System.Action)delegate
                    {
                        if (ime.controls.MessageBox.Show("是否发送阅读回折?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                        {
                            String subject = mail.getString("subject");
                            date = (DateTime)mail["mail_date"];
                            if (date == null)
                                date = DateTime.Now;
                            string source = mail.getString("mail_account");
                            StringBuilder sb = new StringBuilder();
                            sb.Append("<p>这是邮件收条, ").Append(date.ToString("yyyy-MM-dd HH:mm:ss")).Append(",发给")
                                .Append(source).Append(" 主题为 ").Append(subject).Append(" 的信件已被接受")
                                .Append("<br /><br />此收条只表明收件人的计算机上曾显示过此邮件</p>");
                            ASObject from = MailSendWorker.instance.findAccount(source);
                            if (from != null)
                            {
                                MailWorker.instance.sendReceiptMail(sb.ToString(), "Re:" + subject, from, new string[] { to });
                                mail["flags"] = "RECENT";
                                MailWorker.instance.updateMail(mail, new string[] { "flags" });
                            }
                        }
                        else
                        {
                            mail["flags"] = "RECENT";
                            MailWorker.instance.updateMail(mail, new string[] { "flags" });
                        }
                    }, System.Windows.Threading.DispatcherPriority.ApplicationIdle);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.Write(e.StackTrace);
                ime.controls.MessageBox.Show(e.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
        }
コード例 #4
0
ファイル: MailSendWindow.xaml.cs プロジェクト: nbhopson/QMail
        protected override void OnPreviewDrop(DragEventArgs e)
        {
            base.OnPreviewDrop(e);

            if (e.Data.GetDataPresent(DataFormats.FileDrop, true))
            {
                string[] filenames = (string[])e.Data.GetData(DataFormats.FileDrop, true);
                foreach (string filename in filenames)
                {
                    if (isExist(filename))
                        continue;
                    AttachmentItem item = new AttachmentItem();
                    item.Editable = false;
                    item.SetAttachment(filename);
                    attachments.Children.Add(item);
                }
            }
            e.Handled = true;
        }