Esempio n. 1
0
        private void menuFileDirectSend_Click(object sender, EventArgs e)
        {
            string size = "";
            string priority = "";

            // アドレスまたは本文が未入力のとき
            if (textAddress.Text == "" || textBody.Text == "") {
                if (textAddress.Text == "") {
                    // アドレス未入力エラーメッセージを表示する
                    MessageBox.Show("宛先が入力されていません。", "直接送信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (textBody.Text == "") {
                    // 本文未入力エラーメッセージを表示する
                    MessageBox.Show("本文が入力されていません。", "直接送信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }

            // 件名がないときは件名に(無題)を設定する
            if (textSubject.Text == "") {
                textSubject.Text = "(無題)";
            }

            // 優先度の設定をする
            priority = mailPriority[comboPriority.Text];

            // 文面の末尾が\r\nでないときは\r\nを付加する
            if (!textBody.Text.EndsWith("\r\n")) {
                textBody.Text += "\r\n";
            }

            // 添付ファイルが1個以上ある場合
            if (buttonAttachList.DropDownItems.Count > 0) {
                var blanks = Enumerable.Range(0, buttonAttachList.DropDownItems.Count).
                    Where(i => buttonAttachList.DropDownItems[i].Text.Contains("は削除されています。")).ToArray();
                Array.ForEach(blanks, i => buttonAttachList.DropDownItems.RemoveAt(i));

                // メニューが空になった時は添付リストの表示を非表示にする
                buttonAttachList.Visible = buttonAttachList.DropDownItems.Count == 0;
            }

            // 削除アイテムチェック後に添付ファイルが1個以上ある場合
            if (buttonAttachList.DropDownItems.Count > 0) {
                var attaches = Enumerable.Range(0, buttonAttachList.DropDownItems.Count).Select(i => buttonAttachList.DropDownItems[i].Text);
                // 添付ファイル名のリストを変数に渡す
                attachName = string.Join(",", attaches.ToArray());
            }

            // 送信メールサイズを取得する
            size = GetMailSize();

            // 直接送信
            MainForm.DirectSendMail(this.textAddress.Text, this.textCc.Text, this.textBcc.Text, this.textSubject.Text, this.textBody.Text, attachName, priority);
            string date = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();

            // コレクションに追加する
            Mail newMail = new Mail(this.textAddress.Text, "", this.textSubject.Text, this.textBody.Text, this.attachName, date, size, "", false, "", this.textCc.Text, this.textBcc.Text, priority);
            SendList.Add(newMail);

            // ListViewItemSorterを解除する
            MainForm.listView1.ListViewItemSorter = null;

            // ツリービューとリストビューの表示を更新する
            MainForm.UpdateTreeView();
            MainForm.UpdateListView();

            // ListViewItemSorterを指定する
            MainForm.listView1.ListViewItemSorter = MainForm.listViewItemSorter;

            // 編集モードをfalseにする
            IsEdit = false;
            IsDirty = false;

            // データ変更フラグをtrueにする
            MainForm.dataDirtyFlag = true;

            this.Close();
        }
Esempio n. 2
0
        private void menuFileSend_Click(object sender, EventArgs e)
        {
            string size = "";
            string priority = "";

            // アドレスまたは本文が未入力のとき
            if (textAddress.Text == "" || textBody.Text == "") {
                if (textAddress.Text == "") {
                    // アドレス未入力エラーメッセージを表示する
                    MessageBox.Show("宛先が入力されていません。", "送信箱に入れる", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (textBody.Text == "") {
                    // 本文未入力エラーメッセージを表示する
                    MessageBox.Show("本文が入力されていません。", "送信箱に入れる", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }

            // 件名がないときは件名に(無題)を設定する
            if (textSubject.Text == "") {
                textSubject.Text = "(無題)";
            }

            // 優先度の設定をする
            priority = mailPriority[comboPriority.Text];

            // 文面の末尾が\r\nでないときは\r\nを付加する
            if (!textBody.Text.EndsWith("\r\n")) {
                textBody.Text += "\r\n";
            }

            // 添付ファイルが1個以上ある場合
            if (buttonAttachList.DropDownItems.Count >= 1) {
                for (int cnt = 0; cnt < buttonAttachList.DropDownItems.Count; cnt++) {
                    // 添付ファイルが存在しないとき
                    if (buttonAttachList.DropDownItems[cnt].Text.Contains("は削除されています。")) {
                        // そのメニューを削除する
                        buttonAttachList.DropDownItems.RemoveAt(cnt);
                    }
                }

                // メニューが空になった時は添付リストの表示を非表示にする
                buttonAttachList.Visible = buttonAttachList.DropDownItems.Count != 0;
            }

            // 削除アイテムチェック後に添付ファイルが1個以上ある場合
            if (buttonAttachList.DropDownItems.Count > 0) {
                var attachList = string.Join(",", buttonAttachList.DropDownItems.Cast<ToolStripItem>().Select(i => i.Text).ToArray());
                // 添付ファイル名のリストを変数に渡す
                attachName = attachList;
            }

            // 未送信メールは作成日時を格納するようにする(未送信という文字列だと日付ソートでエラーになる)
            string date = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();

            // 編集フラグがOffのとき
            if (!IsEdit) {
                // 送信メールサイズを取得する
                size = GetMailSize();

                // Form1からのコレクションに追加してリスト更新する
                Mail newMail = new Mail(this.textAddress.Text, "", this.textSubject.Text, this.textBody.Text, attachName, date, size, "", true, "", this.textCc.Text, this.textBcc.Text, priority);
                SendList.Add(newMail);
            }
            else {
                // 選択したメールの内容を書き換える
                // 送信リストに入れている情報を書き換える
                size = GetMailSize();
                SendList[ListTag].subject = textSubject.Text;
                SendList[ListTag].address = textAddress.Text;
                SendList[ListTag].body = textBody.Text;
                SendList[ListTag].attach = attachName;
                SendList[ListTag].date = date;
                SendList[ListTag].size = size;
                SendList[ListTag].notReadYet = true;
                SendList[ListTag].cc = textCc.Text;
                SendList[ListTag].bcc = textBcc.Text;
                SendList[ListTag].priority = priority;

                // Becky!と同じように更新後はテキストも変更
                MainForm.textBody.Text = textBody.Text;
            }

            // ListViewItemSorterを解除する
            MainForm.listView1.ListViewItemSorter = null;

            // ツリービューとリストビューの表示を更新する
            MainForm.UpdateTreeView();
            MainForm.UpdateListView();

            // ListViewItemSorterを指定する
            MainForm.listView1.ListViewItemSorter = MainForm.listViewItemSorter;

            // 編集モードをfalseにする
            IsEdit = false;
            IsDirty = false;

            // データ変更フラグをtrueにする
            MainForm.dataDirtyFlag = true;

            this.Close();
        }
Esempio n. 3
0
        /// <summary>
        /// 返信メールを作成
        /// </summary>
        /// <param name="mail"></param>
        private void CreateReturnMail(Mail mail)
        {
            MailEditorForm NewMailForm = new MailEditorForm();

            // 親フォームをForm1に設定する
            NewMailForm.MainForm = this;

            // 送信箱の配列をForm3に渡す
            NewMailForm.SendList = collectionMail[SEND];

            // 返信のための宛先・件名を設定する
            NewMailForm.textAddress.Text = mail.address;
            NewMailForm.textSubject.Text = "Re:" + mail.subject;

            // 添付なしメールのときはbodyを渡す
            if (!attachMailReplay) {
                // UTF-8でエンコードされたメールのときはattachMailBodyを渡す
                if (attachMailBody != "") {
                    NewMailForm.textBody.Text = "\r\n\r\n---" + mail.address + " was wrote ---\r\n\r\n" + attachMailBody;
                }
                else {
                    NewMailForm.textBody.Text = "\r\n\r\n---" + mail.address + " was wrote ---\r\n\r\n" + mail.body;
                }
            }
            else {
                // 添付付きメールのときはattachMailBodyを渡す
                if (attachMailBody != "") {
                    NewMailForm.textBody.Text = "\r\n\r\n---" + mail.address + " was wrote ---\r\n\r\n" + attachMailBody;
                }
                else {
                    NewMailForm.textBody.Text = "\r\n\r\n---" + mail.address + " was wrote ---\r\n\r\n" + mail.body;
                }
            }

            // メール新規作成フォームを表示する
            NewMailForm.Show();
        }
Esempio n. 4
0
        /// <summary>
        /// メールの編集
        /// </summary>
        /// <param name="mail">メール</param>
        /// <param name="item">リストアイテム</param>
        private void EditMail(Mail mail, ListViewItem item)
        {
            Icon appIcon;

            // 1番目のカラムの表示が差出人か差出人または宛先のとき
            if (listView1.Columns[0].Text == "差出人" || listView1.Columns[0].Text == "差出人または宛先") {
                mail.notReadYet = false;

                ReforcusListView(listView1);

                // データ変更フラグをtrueにする
                dataDirtyFlag = true;
            }
            else if (listView1.Columns[0].Text == "宛先") {
                // 1番目のカラムが宛先のときは編集画面を表示する
                MailEditorForm EditMailForm = new MailEditorForm();

                // 親フォームをForm1に設定する
                EditMailForm.MainForm = this;

                // 親フォームにタイトルを設定する
                EditMailForm.Text = mail.subject + " - Akane Mail";

                // 送信箱の配列をForm3に渡す
                EditMailForm.SendList = collectionMail[SEND];
                EditMailForm.ListTag = (int)item.Tag;
                EditMailForm.IsEdit = true;

                // 宛先、件名、本文をForm3に渡す
                EditMailForm.textAddress.Text = mail.address;
                EditMailForm.textCc.Text = mail.cc;
                EditMailForm.textBcc.Text = mail.bcc;
                EditMailForm.textSubject.Text = mail.subject;
                EditMailForm.textBody.Text = mail.body;

                // 重要度をForm3に渡す
                if (mail.priority == "urgent") {
                    EditMailForm.comboPriority.SelectedIndex = 0;
                }
                else if (mail.priority == "normal") {
                    EditMailForm.comboPriority.SelectedIndex = 1;
                }
                else {
                    EditMailForm.comboPriority.SelectedIndex = 2;
                }

                // 添付ファイルが付いているとき
                if (mail.attach != "") {
                    // 添付リストメニューを表示
                    EditMailForm.buttonAttachList.Visible = true;
                    // 添付ファイルリストを分割して一覧にする
                    EditMailForm.attachFileNameList = mail.attach.Split(',');
                    // 添付ファイルの数だけメニューを追加する
                    foreach (var attachFile in EditMailForm.attachFileNameList) {
                        if (File.Exists(attachFile)) {
                            appIcon = System.Drawing.Icon.ExtractAssociatedIcon(attachFile);
                            EditMailForm.buttonAttachList.DropDownItems.Add(attachFile, appIcon.ToBitmap());
                        }
                        else {
                            EditMailForm.buttonAttachList.DropDownItems.Add(attachFile + "は削除されています。");
                        }
                    }
                }

                // メール編集フォームを表示する
                EditMailForm.Show();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// メールファイルの保存
        /// </summary>
        /// <param name="mail">メール</param>
        /// <param name="FileToSave">保存ファイル名</param>
        private void SaveMailFile(Mail mail, string FileToSave)
        {
            string fileBody = "";
            string fileHeader = "";

            // ヘッダから文字コードを取得する(添付付きは取得できない)
            string enc = Mail.ParseEncoding(mail.header);

            // 出力する文字コードがUTF-8ではないとき
            if (enc.ToLower().Contains("iso-") || enc.ToLower().Contains("shift_") || enc.ToLower().Contains("euc") || enc.ToLower().Contains("windows")) {
                // 出力するヘッダをUTF-8から各文字コードに変換する
                Byte[] b = Encoding.GetEncoding(enc).GetBytes(mail.header);
                fileHeader = Encoding.GetEncoding(enc).GetString(b);

                // 出力する本文をUTF-8から各文字コードに変換する
                b = Encoding.GetEncoding(enc).GetBytes(mail.body);
                fileBody = Encoding.GetEncoding(enc).GetString(b);
            }
            else if (enc.ToLower().Contains("utf-8") || mail.header.Contains("X-NMAIL-BODY-UTF8: 8bit")) {
                // text/plainまたはmultipart/alternativeでUTF-8でエンコードされたメールのとき
                // nMail.dllはUTF-8エンコードのメールを8bit単位に分解してUncode(16bit)扱いで格納している。
                // これはUnicodeで文字列を受け取る関数内で生のUTF-8の文字列を受け取っておかしなことに
                // なるのを防ぐための意図で行われている。
                // これをデコードするにはバイト型で格納し、UTF-8でデコードし直せば文字化けのような文字列を
                // 可読化することができる。

                // Byte型構造体に変換する
                var bs = mail.body.Select(s => (byte)s).ToArray();

                // GetStringでバイト型配列をUTF-8の配列にエンコードする
                fileBody = Encoding.UTF8.GetString(bs);

                // fileHeaderにヘッダを格納する
                fileHeader = mail.header;

                // ファイル出力フラグにUTF-8を設定する
                enc = "utf-8";
            }
            else {
                // ここに落ちてくるのは基本的に添付ファイルのみ
                Byte[] b = Encoding.GetEncoding("iso-2022-jp").GetBytes(mail.header);
                fileHeader = Encoding.GetEncoding("iso-2022-jp").GetString(b);

                b = Encoding.GetEncoding("iso-2022-jp").GetBytes(mail.body);
                fileBody = Encoding.GetEncoding("iso-2022-jp").GetString(b);

                // 文字コードをJISに設定する
                enc = "iso-2022-jp";
            }

            // ファイル書き込み用のエンコーディングを取得する
            Encoding writeEnc = Encoding.GetEncoding(enc);

            using (var writer = new StreamWriter(FileToSave, false, writeEnc)) {
                // 受信メール(ヘッダが存在する)のとき
                if (mail.header.Length > 0) {
                    writer.Write(fileHeader);
                    writer.Write("\r\n");
                }
                else {
                    // 送信メールのときはヘッダの代わりに送り先と件名を出力
                    writer.WriteLine("To: " + mail.address);
                    writer.WriteLine("Subject: " + mail.subject);
                    writer.Write("\r\n");
                }
                writer.Write(fileBody);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 転送メールを作成
        /// </summary>
        /// <param name="mail">メール</param>
        private void CreateFowerdMail(Mail mail)
        {
            string strFrom = "";
            string strTo = "";
            string strDate = "";
            string strSubject = "";

            Icon appIcon;
            MailEditorForm NewMailForm = new MailEditorForm();

            // 親フォームをForm1に設定する
            NewMailForm.MainForm = this;

            // 送信箱の配列をForm3に渡す
            NewMailForm.SendList = collectionMail[SEND];

            // 転送のために件名を設定する(件名は空白にする)
            NewMailForm.textAddress.Text = "";
            NewMailForm.textSubject.Text = "Fw:" + mail.subject;

            nMail.Attachment atch = new nMail.Attachment();

            // メールヘッダが存在するとき
            if (mail.header != "") {
                strFrom = atch.GetHeaderField("From:", mail.header);
                strTo = atch.GetHeaderField("To:", mail.header);
                strDate = atch.GetHeaderField("Date:", mail.header);
                strSubject = atch.GetHeaderField("Subject:", mail.header);
            }
            else {
                strFrom = AccountInfo.mailAddress;
                strTo = mail.address;
                strDate = mail.date;
                strSubject = mail.subject;
            }

            string fwHeader = "----------------------- Original Message -----------------------\r\n";
            fwHeader = fwHeader + " From: " + strFrom + "\r\n To: " + strTo + "\r\n Date: " + strDate;
            fwHeader = fwHeader + "\r\n Subject:" + strSubject + "\r\n----\r\n\r\n";

            // 添付なしメールのときはbodyを渡す
            if (!attachMailReplay) {
                // NewMailForm.textBody.Text = "\r\n\r\n--- Forwarded by " + Mail.mailAddress + " ---\r\n" + fwHeader + mail.body;
                // UTF-8でエンコードされたメールのときはattachMailBodyを渡す
                if (attachMailBody != "") {
                    NewMailForm.textBody.Text = "\r\n\r\n--- Forwarded by " + AccountInfo.mailAddress + " ---\r\n" + fwHeader + attachMailBody;
                }
                else {
                    // JISコードなどのメールは通常のbodyを渡す
                    NewMailForm.textBody.Text = "\r\n\r\n--- Forwarded by " + AccountInfo.mailAddress + " ---\r\n" + fwHeader + mail.body;
                }
            }
            else {
                // 添付付きメールのときはattachMailBodyを渡す
                if (attachMailBody != "") {
                    NewMailForm.textBody.Text = "\r\n\r\n--- Forwarded by " + AccountInfo.mailAddress + " ---\r\n" + fwHeader + attachMailBody;
                }
                else {
                    NewMailForm.textBody.Text = "\r\n\r\n--- Forwarded by " + AccountInfo.mailAddress + " ---\r\n" + fwHeader + mail.body;
                }
            }

            // 送信メールで添付ファイルがあるとき
            if (mail.attach != "") {
                // 添付リストメニューを表示
                NewMailForm.buttonAttachList.Visible = true;
                // 添付ファイルリストを分割して一覧にする
                NewMailForm.attachFileNameList = mail.attach.Split(',');
                // 添付ファイルの数だけメニューを追加する
                foreach (var attachFile in NewMailForm.attachFileNameList) {
                    appIcon = System.Drawing.Icon.ExtractAssociatedIcon(attachFile);
                    NewMailForm.buttonAttachList.DropDownItems.Add(attachFile, appIcon.ToBitmap());
                }
            }
            else if (this.buttonAttachList.Visible) {
                // 受信メールで添付ファイルがあるとき
                // 添付リストメニューを表示
                NewMailForm.buttonAttachList.Visible = true;

                // 添付ファイルの数だけメニューを追加する
                foreach (var attachFile in this.buttonAttachList.DropDownItems.Cast<ToolStripItem>().Select(i => i.Text)) {
                    // 添付ファイルが存在するかを確認してから添付する
                    if (File.Exists(Application.StartupPath + @"\tmp\" + attachFile)) {
                        appIcon = System.Drawing.Icon.ExtractAssociatedIcon(Application.StartupPath + @"\tmp\" + attachFile);
                        NewMailForm.buttonAttachList.DropDownItems.Add(Application.StartupPath + @"\tmp\" + attachFile, appIcon.ToBitmap());
                    }
                }
            }

            // メール新規作成フォームを表示する
            NewMailForm.Show();
        }
Esempio n. 7
0
        /// <summary>
        /// 指定されたメールを開く
        /// </summary>
        /// <param name="mail">メール</param>
        private void OpenMail(Mail mail)
        {
            Icon appIcon;
            bool htmlMail = false;
            bool base64Mail = false;

            // 添付ファイルメニューに登録されている要素を破棄する
            buttonAttachList.DropDownItems.Clear();
            buttonAttachList.Visible = false;
            attachMenuFlag = false;
            attachMailReplay = false;
            attachMailBody = "";

            // 添付ファイルクラスのインスタンスを作成する
            nMail.Attachment attach = new nMail.Attachment();

            // Contents-Typeがtext/htmlのメールか確認するフラグを取得する
            htmlMail = attach.GetHeaderField("Content-Type:", mail.header).Contains("text/html");

            // 未読メールの場合
            checkNotYetReadMail = mail.notReadYet;

            // 保存パスはプログラム直下に作成したtmpに設定する
            attach.Path = Application.StartupPath + @"\tmp";

            // 添付ファイルが存在するかを確認する
            int id = attach.GetId(mail.header);

            // 添付ファイルが存在する場合(存在しない場合は-1が返る)
            // もしくは HTML メールの場合
            if (id != nMail.Attachment.NoAttachmentFile || htmlMail) {
                try {
                    // 旧バージョンからの変換データではないとき
                    if (mail.convert == "") {
                        // HTML/Base64のデコードを有効にする
                        Options.EnableDecodeBody();
                    }
                    else {
                        // HTML/Base64のデコードを無効にする
                        Options.DisableDecodeBodyText();
                    }
                    // ヘッダと本文付きの文字列を添付クラスに追加する
                    attach.Add(mail.header, mail.body);

                    // 添付ファイルを取り外す
                    attach.Save();
                }
                catch (Exception ex) {
                    // エラーメッセージを表示する
                    labelMessage.Text = String.Format("エラー メッセージ:{0:s}", ex.Message);
                    return;
                }

                // 添付返信フラグをtrueにする
                attachMailReplay = true;

                // IE コンポーネントを使用かつ HTML パートを保存したファイルがある場合
                if (AccountInfo.bodyIEShow && attach.HtmlFile != "") {
                    // 本文表示用のテキストボックスの表示を非表示にしてHTML表示用のWebBrowserを表示する
                    this.textBody.Visible = false;
                    this.browserBody.Visible = true;

                    // Contents-Typeがtext/htmlでないとき(テキストとHTMLパートが存在する添付メール)
                    if (!htmlMail) {
                        // テキストパートを返信文に格納する
                        attachMailBody = attach.Body;
                    }
                    else {
                        // 本文にHTMLタグが直書きされているタイプのHTMLメールのとき
                        // 展開したHTMLファイルをストリーム読み込みしてテキストを返信用の変数に格納する
                        using (var sr = new StreamReader(Application.StartupPath + @"\tmp\" + attach.HtmlFile, Encoding.Default)) {
                            string htmlBody = sr.ReadToEnd();

                            // HTMLからタグを取り除いた本文を返信文に格納する
                            attachMailBody = Mail.HtmlToText(htmlBody, mail.header);
                        }
                    }

                    // 添付ファイル保存フォルダに展開されたHTMLファイルをWebBrowserで表示する
                    browserBody.AllowNavigation = true;
                    browserBody.Navigate(attach.Path + @"\" + attach.HtmlFile);
                }
                else {
                    // 添付ファイルを外した本文をテキストボックスに表示する
                    this.browserBody.Visible = false;
                    this.textBody.Visible = true;
                    // IE コンポーネントを使用せず、HTML メールで HTML パートを保存したファイルがある場合
                    if (htmlMail && !AccountInfo.bodyIEShow && attach.HtmlFile != "") {
                        // 本文にHTMLタグが直書きされているタイプのHTMLメールのとき
                        // 展開したHTMLファイルをストリーム読み込みしてテキストボックスに表示する
                        using (var sr = new StreamReader(Application.StartupPath + @"\tmp\" + attach.HtmlFile, Encoding.Default)) {
                            string htmlBody = sr.ReadToEnd();

                            // HTMLからタグを取り除く
                            htmlBody = Mail.HtmlToText(htmlBody, mail.header);

                            attachMailBody = htmlBody;
                            this.textBody.Text = htmlBody;
                        }
                    }
                    else if (attach.Body != "") {
                        // デコードした本文の行末が\n\nではないとき
                        if (!attach.Body.Contains("\n\n")) {
                            attachMailBody = attach.Body;
                            this.textBody.Text = attach.Body;
                        }
                        else {
                            attach.Body.Replace("\n\n", "\r\n");
                            attachMailBody = attach.Body.Replace("\n", "\r\n");
                            this.textBody.Text = attachMailBody;
                        }
                    }
                    else {
                        this.textBody.Text = mail.body;
                    }
                }
                // 添付ファイルを外した本文が空値以外の場合
                // 添付ファイル名リストがnull以外のとき
                if (attach.FileNameList != null) {
                    // IE コンポーネントありで、添付ファイルが HTML パートを保存したファイルのみの場合はメニューを表示しない
                    if (!AccountInfo.bodyIEShow || attach.HtmlFile == "" || attach.FileNameList.Length > 1) {
                        buttonAttachList.Visible = true;
                        attachMenuFlag = true;
                        // メニューに添付ファイルの名前を追加する
                        // IE コンポーネントありで、添付ファイルが HTML パートを保存したファイルはメニューに表示しない
                        foreach (var attachFile in attach.FileNameList.Where(a => a != attach.HtmlFile)) {
                            appIcon = System.Drawing.Icon.ExtractAssociatedIcon(Application.StartupPath + @"\tmp\" + attachFile);
                            buttonAttachList.DropDownItems.Add(attachFile, appIcon.ToBitmap());
                        }
                    }
                }
            }
            else {
                // 添付ファイルが存在しない通常のメールまたは
                // 送信済みメールのときは本文をテキストボックスに表示する
                this.browserBody.Visible = false;
                this.textBody.Visible = true;

                // 添付ファイルリストが""でないとき
                if (mail.attach != "") {
                    buttonAttachList.Visible = true;

                    // 添付ファイルリストを分割して一覧にする
                    string[] attachFileNameList = mail.attach.Split(',');

                    for (int i = 0; i < attachFileNameList.Length; i++) {
                        var attachFile = attachFileNameList[i];
                        if (File.Exists(attachFile)) {
                            appIcon = System.Drawing.Icon.ExtractAssociatedIcon(attachFile);
                            buttonAttachList.DropDownItems.Add(attachFile, appIcon.ToBitmap());
                        }
                        else {
                            buttonAttachList.DropDownItems.Add(attachFile + "は削除されています。");
                            buttonAttachList.DropDownItems[i].Enabled = false;
                        }
                    }
                }

                // Contents-TypeがBase64のメールの場合
                base64Mail = attach.GetDecodeHeaderField("Content-Transfer-Encoding:", mail.header).Contains("base64");

                // Base64の文章が添付されている場合
                if (base64Mail) {
                    // 文章をデコードする
                    Options.EnableDecodeBody();

                    // ヘッダと本文付きの文字列を添付クラスに追加する
                    attach.Add(mail.header, mail.body);

                    // 添付ファイルを取り外す
                    attach.Save();

                    if (!attach.Body.Contains("\n\n")) {
                        attachMailBody = attach.Body;
                        this.textBody.Text = attach.Body;
                    }
                    else {
                        attach.Body.Replace("\n\n", "\r\n");
                        attachMailBody = attach.Body.Replace("\n", "\r\n");
                        this.textBody.Text = attachMailBody;
                    }
                }
                else {
                    // ISO-2022-JPでかつquoted-printableがある場合(nMail.dllが対応するまでの暫定処理)
                    if (attach.GetHeaderField("Content-Type:", mail.header).ToLower().Contains("iso-2022-jp") && attach.GetHeaderField("Content-Transfer-Encoding:", mail.header).Contains("quoted-printable")) {
                        // 文章をデコードする
                        Options.EnableDecodeBody();

                        // ヘッダと本文付きの文字列を添付クラスに追加する
                        attach.Add(mail.header, mail.body);

                        // 添付ファイルを取り外す
                        attach.Save();

                        if (!attach.Body.Contains("\n\n")) {
                            attachMailBody = attach.Body;
                            this.textBody.Text = attach.Body;
                        }
                        else {
                            attach.Body.Replace("\n\n", "\r\n");
                            attachMailBody = attach.Body.Replace("\n", "\r\n");
                            this.textBody.Text = attachMailBody;
                        }
                    }
                    else if (attach.GetHeaderField("X-NMAIL-BODY-UTF8:", mail.header).Contains("8bit")) {
                        // Unicode化されたUTF-8文字列をデコードする
                        // 1件のメールサイズの大きさのbyte型配列を確保
                        var bs = mail.body.Select(c => (byte)c).ToArray();

                        // GetStringでバイト型配列をUTF-8の配列にエンコードする
                        attachMailBody = Encoding.UTF8.GetString(bs);
                        this.textBody.Text = attachMailBody;
                    }
                    else {
                        // テキストボックスに出力する文字コードをJISに変更する
                        byte[] b = Encoding.GetEncoding("iso-2022-jp").GetBytes(mail.body);
                        string strBody = Encoding.GetEncoding("iso-2022-jp").GetString(b);

                        // 本文をテキストとして表示する
                        this.textBody.Text = strBody;
                    }
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// POP3サーバからメールを受信する
        /// </summary>
        private void RecieveMail()
        {
            int mailCount = 0;              // 未受信メール件数

            ProgressMailInitDlg progressMailInit = ProgressMailInit;
            ProgressMailUpdateDlg progressMailUpdate = ProgressMailUpdate;
            UpdateViewDlg updateView = UpdateView;
            FlashWindowOnDlg flashWindow = FlashWindowOn;
            EnableButtonDlg enableButton = EnableButton;

            try {
                // ステータスバーに状況表示する
                labelMessage.Text = "メール受信中";

                // POP3のセッションを作成する
                using (var pop = new nMail.Pop3()) {
                    // POP3への接続タイムアウト設定をする
                    Options.EnableConnectTimeout();

                    // APOPを使用するときに使うフラグ
                    pop.APop = AccountInfo.apopFlag;

                    // POP3 over SSL/TLSフラグが有効のときはSSLを使用する
                    if (AccountInfo.popOverSSL) {
                        pop.SSL = nMail.Pop3.SSL3;
                        pop.Connect(AccountInfo.popServer, AccountInfo.popPortNumber);
                    }
                    else {
                        // POP3へ接続する
                        pop.Connect(AccountInfo.popServer, AccountInfo.popPortNumber);
                    }

                    // POP3への認証処理を行う
                    pop.Authenticate(AccountInfo.userName, AccountInfo.passWord);

                    // 未受信のメールが何件あるかチェックする
                    var countMail = new Task<int>(() =>
                    {
                        var uidls = Enumerable.Range(1, pop.Count).Select(i => { pop.GetUidl(i); return pop.Uidl; });
                        var locals = collectionMail[RECEIVE].Union(collectionMail[DELETE]);
                        var unreadMails = from u in uidls
                                          join l in locals on u equals l.uidl
                                          select l;
                        return unreadMails.Count();
                    });
                    countMail.Start();

                    // POP3サーバ上に1件以上のメールが存在するとき
                    if (pop.Count > 0) {
                        // ステータスバーに状況表示する
                        labelMessage.Text = pop.Count + "件のメッセージがサーバ上にあります。";
                    }
                    else {
                        // ステータスバーに状況表示する
                        labelMessage.Text = "新着のメッセージはありませんでした。";

                        // メール受信のメニューとツールボタンを有効化する
                        Invoke(enableButton, 1);
                        return;
                    }

                    var receivedCount = countMail.Result;
                    // 受信済みメールカウントがPOP3サーバ上にあるメール件数と同じとき
                    if (receivedCount == pop.Count) {
                        // ステータスバーに状況表示する
                        labelMessage.Text = "新着のメッセージはありませんでした。";

                        // プログレスバーを非表示に戻す
                        Invoke(new ProgressMailDisableDlg(ProgressMailDisable));

                        // メール受信のメニューとツールボタンを有効化する
                        Invoke(enableButton, 1);

                        return;
                    }

                    // プログレスバーを表示して最大値を未受信メール件数に設定する
                    int mailCountMax = pop.Count - receivedCount;
                    Invoke(progressMailInit, mailCountMax);

                    // 未受信のメールを取得するためカウントを1増加させる
                    receivedCount++;

                    // 取得したメールをコレクションに追加する
                    for (int no = receivedCount; no <= pop.Count; no++) {
                        // 受信中件数を表示
                        labelMessage.Text = no + "件目のメールを受信しています。";

                        // メールのUIDLを取得する
                        pop.GetUidl(no);

                        // HTML/Base64のデコードを無効にする
                        Options.DisableDecodeBodyText();

                        // メールの情報を取得する
                        pop.GetMail(no);

                        // メールの情報を格納する
                        Mail mail = new Mail(pop.From, pop.Header, pop.Subject, pop.Body, pop.FileName, pop.DateString, pop.Size.ToString(), pop.Uidl, true, "", pop.GetDecodeHeaderField("Cc:"), "", Mail.ParsePriority(pop.Header));
                        collectionMail[RECEIVE].Add(mail);

                        // 受信メールの数を増加する
                        mailCount++;

                        // メール受信時にPOP3サーバ上のメール削除のチェックがある時はPOP3サーバからメールを削除する
                        if (AccountInfo.deleteMail) {
                            pop.Delete(no);
                        }

                        // メールの受信件数を更新する
                        Invoke(progressMailUpdate, mailCount);

                        // スレッドを1秒間待機させる
                        System.Threading.Thread.Sleep(1000);
                    }
                }

                // プログレスバーを非表示に戻す
                Invoke(new ProgressMailDisableDlg(ProgressMailDisable));

                // メール受信のメニューとツールボタンを有効化する
                Invoke(enableButton, 1);

                // 未受信メールが1件以上の場合
                if (mailCount >= 1) {
                    // メール着信音の設定をしている場合
                    if (AccountInfo.popSoundFlag && AccountInfo.popSoundName != "") {
                        SoundPlayer sndPlay = new SoundPlayer(AccountInfo.popSoundName);
                        sndPlay.Play();
                    }

                    // ウィンドウが最小化でタスクトレイに格納されていて何分間隔かで受信をするとき
                    if (this.WindowState == FormWindowState.Minimized && AccountInfo.minimizeTaskTray && AccountInfo.autoMailFlag) {
                        notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
                        notifyIcon1.BalloonTipTitle = "新着メール";
                        notifyIcon1.BalloonTipText = mailCount + "件の新着メールを受信しました。";
                        notifyIcon1.ShowBalloonTip(300);
                    }
                    else {
                        // 画面をフラッシュさせる
                        Invoke(flashWindow);

                        // ステータスバーに状況表示する
                        labelMessage.Text = mailCount + "件の新着メールを受信しました。";
                    }

                    // データ変更フラグをtrueにする
                    dataDirtyFlag = true;
                }
                else {
                    // ステータスバーに状況表示する
                    labelMessage.Text = "新着のメッセージはありませんでした。";

                    // メール受信のメニューとツールボタンを有効化する
                    Invoke(enableButton, 1);

                    return;
                }
            }
            catch (nMail.nMailException nex) {
                // ステータスバーに状況表示する
                labelMessage.Text = "エラーNo:" + nex.ErrorCode + " エラーメッセージ:" + nex.Message;

                // メール受信のメニューとツールボタンを有効化する
                Invoke(enableButton, 1);

                return;
            }
            catch (Exception exp) {
                // ステータスバーに状況表示する
                labelMessage.Text = "エラーメッセージ:" + exp.Message;

                // メール受信のメニューとツールボタンを有効化する
                Invoke(enableButton, 1);

                return;
            }

            // TreeViewとListViewの更新を行う
            Invoke(updateView, 0);
        }
Esempio n. 9
0
        /// <summary>
        /// メールデータの読み込み
        /// </summary>
        private void MailDataLoad()
        {
            // 予期せぬエラーの時にメールの本文が分かるようにするための変数
            string expSubject = "";
            int n = 0;

            // スレッドのロックをかける
            lock (lockobj) {
                if (File.Exists(Application.StartupPath + @"\Mail.dat")) {
                    try {
                        // ファイルストリームをストリームリーダに関連付ける
                        using (var reader = new StreamReader(Application.StartupPath + @"\Mail.dat", Encoding.UTF8)) {
                            // GetHederFieldとHeaderプロパティを使うためPop3クラスを作成する
                            using (var pop = new Pop3()) {
                                // データを読み出す
                                foreach (var mailList in collectionMail) {
                                    try {
                                        // メールの件数を読み出す
                                        n = Int32.Parse(reader.ReadLine());
                                    }
                                    catch (Exception) {
                                        // エラーフラグをtrueに変更する
                                        errorFlag = true;

                                        MessageBox.Show("メール件数とメールデータの数が一致していません。\n件数またはデータレコードをテキストエディタで修正してください。", "Akane Mail", MessageBoxButtons.OK, MessageBoxIcon.Stop);

                                        return;
                                    }

                                    // メールを取得する
                                    for (int j = 0; j < n; j++) {
                                        // 送信メールのみ必要な項目
                                        string address = reader.ReadLine();
                                        string subject = reader.ReadLine();

                                        // 予期せぬエラーの時にメッセージボックスに表示する件名
                                        expSubject = subject;

                                        // ヘッダを取得する
                                        string header = "";
                                        string hd = reader.ReadLine();

                                        // 区切り文字が来るまで文字列を連結する
                                        while (hd != "\x03") {
                                            header += hd + "\r\n";
                                            hd = reader.ReadLine();
                                        }

                                        // 本文を取得する
                                        string body = "";
                                        string b = reader.ReadLine();

                                        // エラー文字区切りの時対策
                                        bool err_parse = false;

                                        // 区切り文字が来るまで文字列を連結する
                                        while (b != "\x03") {
                                            // 区切り文字が本文の後ろについてしまったとき
                                            if (b.Contains("\x03") && b != "\x03") {
                                                // 区切り文字を取り除く
                                                err_parse = true;
                                                b = b.Replace("\x03", "");
                                            }

                                            body += b + "\r\n";

                                            // 区切り文字が検出されたときは区切り文字を取り除いてループから抜ける
                                            if (err_parse) {
                                                break;
                                            }

                                            b = reader.ReadLine();
                                        }

                                        // 受信・送信日時を取得する
                                        string date = reader.ReadLine();

                                        // メールサイズを取得する(送信メールは0byte扱い)
                                        string size = reader.ReadLine();

                                        // UIDLを取得する(送信メールは無視)
                                        string uidl = reader.ReadLine();

                                        // 添付ファイル名を取得する(受信メールは無視)
                                        string attach = reader.ReadLine();

                                        // 既読・未読フラグを取得する
                                        bool notReadYet = (reader.ReadLine() == "True");

                                        // CCのアドレスを取得する
                                        string cc = reader.ReadLine();

                                        // BCCを取得する(受信メールは無視)
                                        string bcc = reader.ReadLine();

                                        // 重要度を取得する
                                        string priority = reader.ReadLine();

                                        // 旧ファイルを読み込んでいるとき
                                        if (priority != "urgent" && priority != "normal" && priority != "non-urgent") {

                                            // エラーフラグをtrueに変更する
                                            errorFlag = true;

                                            MessageBox.Show("Version 1.10以下のファイルを読み込もうとしています。\nメールデータ変換ツールで変換してから読み込んでください。", "Akane Mail", MessageBoxButtons.OK, MessageBoxIcon.Stop);

                                            return;
                                        }

                                        // 変換フラグを取得する(旧バージョンからのデータ移行)
                                        string convert = reader.ReadLine();

                                        // ヘッダーがあった場合はそちらを優先する
                                        if (header.Length > 0) {
                                            // ヘッダープロパティにファイルから取得したヘッダを格納する
                                            pop.Header = header;

                                            // アドレスを取得する
                                            pop.GetDecodeHeaderField("From:");
                                            address = pop.Field ?? address;

                                            // 件名を取得する
                                            pop.GetDecodeHeaderField("Subject:");
                                            subject = pop.Field ?? subject;

                                            // ヘッダからCCアドレスを取得する
                                            pop.GetDecodeHeaderField("Cc:");
                                            cc = pop.Field ?? cc;

                                            // ヘッダから重要度を取得する
                                            priority = Mail.ParsePriority(header);
                                        }

                                        // メール格納配列に格納する
                                        var mail = new Mail(address, header, subject, body, attach, date, size, uidl, notReadYet, convert, cc, bcc, priority);
                                        mailList.Add(mail);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception exp) {
                        MessageBox.Show("予期しないエラーが発生しました。\n" + "件名:" + expSubject + "\n" + "エラー詳細 : \n" + exp.Message, "Akane Mail", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// 添付ファイル付きメールの展開
        /// </summary>
        /// <param name="mail"></param>
        private void GetAttachMail(Mail mail)
        {
            // 添付ファイル保存対象フォルダを選択する
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) {
                try {
                    // 添付ファイルクラスを作成する
                    nMail.Attachment attach = new nMail.Attachment();

                    // 保存パスを設定する
                    attach.Path = folderBrowserDialog1.SelectedPath;

                    // 添付ファイル展開用のテンポラリファイルを作成する
                    string tmpFileName = Path.GetTempFileName();
                    using (var writer = new StreamWriter(tmpFileName)) {
                        writer.Write(mail.header);
                        writer.Write("\r\n");
                        writer.Write(mail.body);
                    }

                    // テンポラリファイルを開いて添付ファイルを開く
                    using (var reader = new StreamReader(tmpFileName)) {
                        string header = reader.ReadToEnd();
                        // ヘッダと本文付きの文字列を添付クラスに追加する
                        attach.Add(header);
                    }
                    // 添付ファイルを保存する
                    attach.Save();

                    MessageBox.Show(attach.Path + "に添付ファイル" + attach.FileName + "を保存しました。", "添付ファイルの取り出し", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (nMailException nex) {
                    string message = "";
                    switch (nex.ErrorCode) {
                        case nMail.Attachment.ErrorFileOpen:
                            message = "添付ファイルがオープンできません。";
                            break;
                        case nMail.Attachment.ErrorInvalidNo:
                            message = "分割されたメールの順番が正しくないか、該当しないファイルが入っています。";
                            break;
                        case nMail.Attachment.ErrorPartial:
                            message = "分割されたメールが全て揃っていません";
                            break;
                        default:
                            break;
                    }
                    MessageBox.Show(message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                catch (Exception ex) {
                    MessageBox.Show(String.Format("エラー メッセージ:{0:s}", ex.Message), "エラー", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
        }
Esempio n. 11
0
        private void menuSendMail_Click(object sender, EventArgs e)
        {
            string size = "";
            string priority = "";

            // アドレスまたは本文が未入力のとき
            if (textAddress.Text == "" || textBody.Text == "") {
                if (textAddress.Text == "") {
                    // アドレス未入力エラーメッセージを表示する
                    MessageBox.Show("宛先が入力されていません。", "直接送信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (textBody.Text == "") {
                    // 本文未入力エラーメッセージを表示する
                    MessageBox.Show("本文が入力されていません。", "直接送信", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }

            // 件名がないときは件名に(無題)を設定する
            if (textSubject.Text == "") {
                textSubject.Text = "(無題)";
            }

            // 優先度の設定をする
            priority = mailPriority[comboPriority.Text];

            // 文面の末尾が\r\nでないときは\r\nを付加する
            if (!textBody.Text.EndsWith("\r\n")) {
                textBody.Text += "\r\n";
            }

            CleanAttach();

            attachName = GetAttaches();

            // 送信メールサイズを取得する
            size = GetMailSize();

            // 直接送信
            MainForm.DirectSendMail(this.textAddress.Text, this.textCc.Text, this.textBcc.Text, this.textSubject.Text, this.textBody.Text, attachName, priority);
            string date = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();

            var sendMail = new Mail(this.textAddress.Text, "", this.textSubject.Text, this.textBody.Text, this.attachName, date, size, "", false, "", this.textCc.Text, this.textBcc.Text, priority);
            // コレクションに追加する
            SendList.Add(sendMail);

            BeforeClosing(MainForm);

            this.Close();
        }
Esempio n. 12
0
        private void menuSendMailBox_Click(object sender, EventArgs e)
        {
            string size = "";
            string priority = "";

            // アドレスまたは本文が未入力のとき
            if (textAddress.Text == "" || textBody.Text == "") {
                if (textAddress.Text == "") {
                    // アドレス未入力エラーメッセージを表示する
                    MessageBox.Show("宛先が入力されていません。", "送信箱に入れる", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (textBody.Text == "") {
                    // 本文未入力エラーメッセージを表示する
                    MessageBox.Show("本文が入力されていません。", "送信箱に入れる", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }

            // 件名がないときは件名に(無題)を設定する
            if (textSubject.Text == "") {
                textSubject.Text = "(無題)";
            }

            // 優先度の設定をする
            priority = mailPriority[comboPriority.Text];

            // 文面の末尾が\r\nでないときは\r\nを付加する
            if (!textBody.Text.EndsWith("\r\n")) {
                textBody.Text += "\r\n";
            }

            CleanAttach();

            attachName = GetAttaches();

            // 未送信メールは作成日時を格納するようにする(未送信という文字列だと日付ソートでエラーになる)
            string date = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString();

            // 編集フラグがOffのとき
            if (!IsEdit) {
                // 送信メールサイズを取得する
                size = GetMailSize();

                // Form1からのコレクションに追加してリスト更新する
                var newMail = new Mail(this.textAddress.Text, "", this.textSubject.Text, this.textBody.Text, attachName, date, size, "", true, "", this.textCc.Text, this.textBcc.Text, priority);
                SendList.Add(newMail);
            }
            else {
                // 選択したメールの内容を書き換える
                // 送信リストに入れている情報を書き換える
                size = GetMailSize();
                SendList[ListTag].subject = textSubject.Text;
                SendList[ListTag].address = textAddress.Text;
                SendList[ListTag].body = textBody.Text;
                SendList[ListTag].attach = attachName;
                SendList[ListTag].date = date;
                SendList[ListTag].size = size;
                SendList[ListTag].notReadYet = true;
                SendList[ListTag].cc = textCc.Text;
                SendList[ListTag].bcc = textBcc.Text;
                SendList[ListTag].priority = priority;

                // Becky!と同じように更新後はテキストも変更
                MainForm.textBody.Text = textBody.Text;
            }

            BeforeClosing(MainForm);

            this.Close();
        }
Esempio n. 13
0
        /// <summary>
        /// メールデータをファイルから読み込みます。
        /// </summary>
        public void MailDataLoad()
        {
            // 予期せぬエラーの時にメールの本文が分かるようにするための変数
            string expSubject = "";
            int    n          = 0;
            var    lockobj    = new object();

            // スレッドのロックをかける
            lock (lockobj) {
                if (File.Exists(Application.StartupPath + @"\Mail.dat"))
                {
                    try {
                        // ファイルストリームをストリームリーダに関連付ける
                        using (var reader = new StreamReader(Application.StartupPath + @"\Mail.dat", Encoding.UTF8)) {
                            var folders = new MailFolder[] { _receive, _send, _trash };
                            // GetHederFieldとHeaderプロパティを使うためPop3クラスを作成する
                            using (var pop = new Pop3()) {
                                // データを読み出す
                                foreach (var folder in folders)
                                {
                                    try {
                                        // メールの件数を読み出す
                                        n = Int32.Parse(reader.ReadLine());
                                    }
                                    catch (Exception e) {
                                        var message = "メール件数とメールデータの数が一致していません。\n件数またはデータレコードをテキストエディタで修正してください。";
                                        MessageBox.Show(message, "Akane Mail", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                        throw new MailLoadException(message, e);
                                    }

                                    // メールを取得する
                                    for (int j = 0; j < n; j++)
                                    {
                                        // 送信メールのみ必要な項目
                                        string address = reader.ReadLine();
                                        string subject = reader.ReadLine();

                                        // 予期せぬエラーの時にメッセージボックスに表示する件名
                                        expSubject = subject;

                                        // ヘッダを取得する
                                        string header = "";
                                        string hd     = reader.ReadLine();

                                        // 区切り文字が来るまで文字列を連結する
                                        while (hd != "\x03")
                                        {
                                            header += hd + "\r\n";
                                            hd      = reader.ReadLine();
                                        }

                                        // 本文を取得する
                                        string body = "";
                                        string b    = reader.ReadLine();

                                        // エラー文字区切りの時対策
                                        bool err_parse = false;

                                        // 区切り文字が来るまで文字列を連結する
                                        while (b != "\x03")
                                        {
                                            // 区切り文字が本文の後ろについてしまったとき
                                            if (b.Contains("\x03") && b != "\x03")
                                            {
                                                // 区切り文字を取り除く
                                                err_parse = true;
                                                b         = b.Replace("\x03", "");
                                            }

                                            body += b + "\r\n";

                                            // 区切り文字が検出されたときは区切り文字を取り除いてループから抜ける
                                            if (err_parse)
                                            {
                                                break;
                                            }

                                            b = reader.ReadLine();
                                        }

                                        // 受信・送信日時を取得する
                                        string date = reader.ReadLine();

                                        // メールサイズを取得する(送信メールは0byte扱い)
                                        string size = reader.ReadLine();

                                        // UIDLを取得する(送信メールは無視)
                                        string uidl = reader.ReadLine();

                                        // 添付ファイル名を取得する(受信メールは無視)
                                        string attach = reader.ReadLine();

                                        // 既読・未読フラグを取得する
                                        bool notReadYet = (reader.ReadLine() == "True");

                                        // CCのアドレスを取得する
                                        string cc = reader.ReadLine();

                                        // BCCを取得する(受信メールは無視)
                                        string bcc = reader.ReadLine();

                                        // 重要度を取得する
                                        string priority = reader.ReadLine();

                                        // 旧ファイルを読み込んでいるとき
                                        if (priority != "urgent" && priority != "normal" && priority != "non-urgent")
                                        {
                                            var message = "Version 1.10以下のファイルを読み込もうとしています。\nメールデータ変換ツールで変換してから読み込んでください。";
                                            MessageBox.Show(message, "Akane Mail", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                            throw new MailLoadException(message);
                                        }

                                        // 変換フラグを取得する(旧バージョンからのデータ移行)
                                        string convert = reader.ReadLine();

                                        // ヘッダーがあった場合はそちらを優先する
                                        if (header.Length > 0)
                                        {
                                            // ヘッダープロパティにファイルから取得したヘッダを格納する
                                            pop.Header = header;

                                            // アドレスを取得する
                                            pop.GetDecodeHeaderField("From:");
                                            address = pop.Field ?? address;

                                            // 件名を取得する
                                            pop.GetDecodeHeaderField("Subject:");
                                            subject = pop.Field ?? subject;

                                            // ヘッダからCCアドレスを取得する
                                            pop.GetDecodeHeaderField("Cc:");
                                            cc = pop.Field ?? cc;

                                            // ヘッダから重要度を取得する
                                            priority = MailPriority.Parse(header);
                                        }

                                        // メール格納配列に格納する
                                        var mail = new Mail(address, header, subject, body, attach, date, size, uidl, notReadYet, convert, cc, bcc, priority);
                                        folder.Add(mail);
                                    }
                                }
                            }
                        }
                    }
                    catch (MailLoadException) {
                        throw;
                    }
                    catch (Exception exp) {
                        MessageBox.Show("予期しないエラーが発生しました。\n" + "件名:" + expSubject + "\n" + "エラー詳細 : \n" + exp.Message, "Akane Mail", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        throw new MailLoadException("予期しないエラーが発生しました", exp);
                    }
                }
            }
        }