OSDN Git Service

送信済み動作拡張
authorT.N <dangerouswoo@gmail.com>
Tue, 31 Aug 2021 06:15:02 +0000 (15:15 +0900)
committerT.N <dangerouswoo@gmail.com>
Tue, 31 Aug 2021 06:15:02 +0000 (15:15 +0900)
機能有無、フォルダ指定

MailDivSender/Properties/Settings.Designer.cs
MailDivSender/SenderForm.cs
MailDivSender/ServerSettingDlg.Designer.cs
MailDivSender/ServerSettingDlg.cs

index 611200e..7e9868d 100644 (file)
@@ -70,7 +70,37 @@ namespace MailDivSender.Properties {
                 this["Imap4Port"] = value;
             }
         }
-        
+
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("False")]
+        public bool Imap4Enable
+        {
+            get
+            {
+                return ((bool)(this["Imap4Enable"]));
+            }
+            set
+            {
+                this["Imap4Enable"] = value;
+            }
+        }
+
+        [global::System.Configuration.UserScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("Sent")]
+        public string Imap4Sentfolder
+        {
+            get
+            {
+                return ((string)(this["Imap4Sentfolder"]));
+            }
+            set
+            {
+                this["Imap4Sentfolder"] = value;
+            }
+        }
+
         [global::System.Configuration.UserScopedSettingAttribute()]
         [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
         [global::System.Configuration.DefaultSettingValueAttribute("")]
index 2f753d5..607a868 100644 (file)
@@ -25,6 +25,16 @@ namespace MailDivSender
         public string Imap4Server = string.Empty;
 
         /// <summary>
+        /// IMAP4有無
+        /// </summary>
+        public bool Imap4Enable = false;
+
+        /// <summary>
+        /// IMAP4送信済みフォルダ
+        /// </summary>
+        public string Imap4Sentfolder = "Sent";
+
+        /// <summary>
         /// SMTPサーバー
         /// </summary>
         public string SMTPServer = string.Empty;
@@ -222,14 +232,17 @@ namespace MailDivSender
 
                         using (var imapclient = new ImapClient())
                         {
-                            imapclient.Authenticated += (obj, args) =>
+                            if (Imap4Enable == true)
                             {
-                                var acc = imapclient.Inbox.Open(FolderAccess.ReadWrite);
-                                sentfolder = imapclient.Inbox.GetSubfolder("Sent");
-                            };
+                                imapclient.Authenticated += (obj, args) =>
+                                {
+                                    var acc = imapclient.Inbox.Open(FolderAccess.ReadWrite);
+                                    sentfolder = imapclient.Inbox.GetSubfolder(Imap4Sentfolder);
+                                };
 
-                            imapclient.Connect(Imap4Server, ImapPort, MailKit.Security.SecureSocketOptions.Auto);
-                            imapclient.Authenticate(User, Password);
+                                imapclient.Connect(Imap4Server, ImapPort, MailKit.Security.SecureSocketOptions.Auto);
+                                imapclient.Authenticate(User, Password);
+                            }
 
                             foreach (var filepath in filelist)
                             {
@@ -279,8 +292,11 @@ namespace MailDivSender
 
                                 Invoke((Action)(() => { StatusLbl.Text = $"送信済追加中 {filepath}"; }));
 
-                                //送信済
-                                sentfolder.Append(message);
+                                if (Imap4Enable == true)
+                                {
+                                    //送信済
+                                    sentfolder.Append(message);
+                                }
 
                                 Invoke((Action)(() => { StatusLbl.Text = $"完了 {filepath}"; }));
 
@@ -444,7 +460,9 @@ namespace MailDivSender
         protected void LoadSetting()
         {
             Imap4Server = Properties.Settings.Default.Imap4Server;
+            Imap4Enable = Properties.Settings.Default.Imap4Enable;
             ImapPort = Properties.Settings.Default.Imap4Port;
+            Imap4Sentfolder = Properties.Settings.Default.Imap4Sentfolder;
             SMTPServer = Properties.Settings.Default.SMTPServer;
             SMTPPort = Properties.Settings.Default.SMTPPort;
             User = Properties.Settings.Default.User;
index ea4282c..aa558d7 100644 (file)
             this.OkBtn = new System.Windows.Forms.Button();
             this.CancelBtn = new System.Windows.Forms.Button();
             this.Imap4Grp = new System.Windows.Forms.GroupBox();
-            this.SMTPGrp = new System.Windows.Forms.GroupBox();
-            this.label3 = new System.Windows.Forms.Label();
-            this.label4 = new System.Windows.Forms.Label();
-            this.Imap4ServerTxt = new System.Windows.Forms.TextBox();
             this.Imap4ServerPort = new System.Windows.Forms.NumericUpDown();
+            this.Imap4ServerTxt = new System.Windows.Forms.TextBox();
+            this.label4 = new System.Windows.Forms.Label();
+            this.label3 = new System.Windows.Forms.Label();
+            this.SMTPGrp = new System.Windows.Forms.GroupBox();
             this.SMTPServerPort = new System.Windows.Forms.NumericUpDown();
             this.SMTPServerTxt = new System.Windows.Forms.TextBox();
             this.label5 = new System.Windows.Forms.Label();
             this.label6 = new System.Windows.Forms.Label();
             this.SignatureTxt = new System.Windows.Forms.TextBox();
             this.label7 = new System.Windows.Forms.Label();
+            this.Imap4EnableChk = new System.Windows.Forms.CheckBox();
+            this.Imap4SentfolderTxt = new System.Windows.Forms.TextBox();
+            this.label8 = new System.Windows.Forms.Label();
             this.Imap4Grp.SuspendLayout();
-            this.SMTPGrp.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.Imap4ServerPort)).BeginInit();
+            this.SMTPGrp.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.SMTPServerPort)).BeginInit();
             this.SuspendLayout();
             // 
@@ -87,8 +90,9 @@
             // 
             // OkBtn
             // 
+            this.OkBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.OkBtn.DialogResult = System.Windows.Forms.DialogResult.OK;
-            this.OkBtn.Location = new System.Drawing.Point(593, 341);
+            this.OkBtn.Location = new System.Drawing.Point(593, 387);
             this.OkBtn.Name = "OkBtn";
             this.OkBtn.Size = new System.Drawing.Size(75, 23);
             this.OkBtn.TabIndex = 4;
             // 
             // CancelBtn
             // 
+            this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
             this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
-            this.CancelBtn.Location = new System.Drawing.Point(674, 341);
+            this.CancelBtn.Location = new System.Drawing.Point(674, 387);
             this.CancelBtn.Name = "CancelBtn";
             this.CancelBtn.Size = new System.Drawing.Size(75, 23);
             this.CancelBtn.TabIndex = 4;
             // 
             // Imap4Grp
             // 
+            this.Imap4Grp.Controls.Add(this.label8);
+            this.Imap4Grp.Controls.Add(this.Imap4SentfolderTxt);
+            this.Imap4Grp.Controls.Add(this.Imap4EnableChk);
             this.Imap4Grp.Controls.Add(this.Imap4ServerPort);
             this.Imap4Grp.Controls.Add(this.Imap4ServerTxt);
             this.Imap4Grp.Controls.Add(this.label4);
             this.Imap4Grp.Controls.Add(this.label3);
             this.Imap4Grp.Location = new System.Drawing.Point(16, 117);
             this.Imap4Grp.Name = "Imap4Grp";
-            this.Imap4Grp.Size = new System.Drawing.Size(319, 100);
+            this.Imap4Grp.Size = new System.Drawing.Size(319, 145);
             this.Imap4Grp.TabIndex = 5;
             this.Imap4Grp.TabStop = false;
             this.Imap4Grp.Text = "Imap4";
             // 
-            // SMTPGrp
-            // 
-            this.SMTPGrp.Controls.Add(this.SMTPServerPort);
-            this.SMTPGrp.Controls.Add(this.SMTPServerTxt);
-            this.SMTPGrp.Controls.Add(this.label5);
-            this.SMTPGrp.Controls.Add(this.label6);
-            this.SMTPGrp.Location = new System.Drawing.Point(16, 223);
-            this.SMTPGrp.Name = "SMTPGrp";
-            this.SMTPGrp.Size = new System.Drawing.Size(319, 100);
-            this.SMTPGrp.TabIndex = 6;
-            this.SMTPGrp.TabStop = false;
-            this.SMTPGrp.Text = "SMTP";
-            // 
-            // label3
-            // 
-            this.label3.AutoSize = true;
-            this.label3.Location = new System.Drawing.Point(6, 15);
-            this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(38, 12);
-            this.label3.TabIndex = 1;
-            this.label3.Text = "Server";
-            // 
-            // label4
-            // 
-            this.label4.AutoSize = true;
-            this.label4.Location = new System.Drawing.Point(6, 56);
-            this.label4.Name = "label4";
-            this.label4.Size = new System.Drawing.Size(26, 12);
-            this.label4.TabIndex = 2;
-            this.label4.Text = "Port";
-            // 
-            // Imap4ServerTxt
-            // 
-            this.Imap4ServerTxt.Location = new System.Drawing.Point(8, 32);
-            this.Imap4ServerTxt.Name = "Imap4ServerTxt";
-            this.Imap4ServerTxt.Size = new System.Drawing.Size(300, 19);
-            this.Imap4ServerTxt.TabIndex = 3;
-            // 
             // Imap4ServerPort
             // 
             this.Imap4ServerPort.Location = new System.Drawing.Point(8, 73);
             0,
             0});
             // 
+            // Imap4ServerTxt
+            // 
+            this.Imap4ServerTxt.Location = new System.Drawing.Point(8, 32);
+            this.Imap4ServerTxt.Name = "Imap4ServerTxt";
+            this.Imap4ServerTxt.Size = new System.Drawing.Size(300, 19);
+            this.Imap4ServerTxt.TabIndex = 3;
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Location = new System.Drawing.Point(6, 56);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(26, 12);
+            this.label4.TabIndex = 2;
+            this.label4.Text = "Port";
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Location = new System.Drawing.Point(6, 15);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(38, 12);
+            this.label3.TabIndex = 1;
+            this.label3.Text = "Server";
+            // 
+            // SMTPGrp
+            // 
+            this.SMTPGrp.Controls.Add(this.SMTPServerPort);
+            this.SMTPGrp.Controls.Add(this.SMTPServerTxt);
+            this.SMTPGrp.Controls.Add(this.label5);
+            this.SMTPGrp.Controls.Add(this.label6);
+            this.SMTPGrp.Location = new System.Drawing.Point(16, 268);
+            this.SMTPGrp.Name = "SMTPGrp";
+            this.SMTPGrp.Size = new System.Drawing.Size(319, 100);
+            this.SMTPGrp.TabIndex = 6;
+            this.SMTPGrp.TabStop = false;
+            this.SMTPGrp.Text = "SMTP";
+            // 
             // SMTPServerPort
             // 
             this.SMTPServerPort.Location = new System.Drawing.Point(11, 73);
             // 
             // SignatureTxt
             // 
+            this.SignatureTxt.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Right)));
             this.SignatureTxt.Location = new System.Drawing.Point(366, 32);
             this.SignatureTxt.Multiline = true;
             this.SignatureTxt.Name = "SignatureTxt";
-            this.SignatureTxt.Size = new System.Drawing.Size(382, 290);
+            this.SignatureTxt.Size = new System.Drawing.Size(382, 336);
             this.SignatureTxt.TabIndex = 7;
             // 
             // label7
             this.label7.TabIndex = 8;
             this.label7.Text = "署名";
             // 
+            // Imap4EnableChk
+            // 
+            this.Imap4EnableChk.AutoSize = true;
+            this.Imap4EnableChk.Location = new System.Drawing.Point(250, 74);
+            this.Imap4EnableChk.Name = "Imap4EnableChk";
+            this.Imap4EnableChk.Size = new System.Drawing.Size(58, 16);
+            this.Imap4EnableChk.TabIndex = 5;
+            this.Imap4EnableChk.Text = "Enable";
+            this.Imap4EnableChk.UseVisualStyleBackColor = true;
+            // 
+            // Imap4SentfolderTxt
+            // 
+            this.Imap4SentfolderTxt.Location = new System.Drawing.Point(8, 117);
+            this.Imap4SentfolderTxt.Name = "Imap4SentfolderTxt";
+            this.Imap4SentfolderTxt.Size = new System.Drawing.Size(300, 19);
+            this.Imap4SentfolderTxt.TabIndex = 6;
+            // 
+            // label8
+            // 
+            this.label8.AutoSize = true;
+            this.label8.Location = new System.Drawing.Point(6, 102);
+            this.label8.Name = "label8";
+            this.label8.Size = new System.Drawing.Size(64, 12);
+            this.label8.TabIndex = 7;
+            this.label8.Text = "Sent Folder";
+            // 
             // ServerSettingDlg
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(761, 376);
+            this.ClientSize = new System.Drawing.Size(761, 424);
             this.Controls.Add(this.label7);
             this.Controls.Add(this.SignatureTxt);
             this.Controls.Add(this.SMTPGrp);
             this.Load += new System.EventHandler(this.ServerSettingDlg_Load);
             this.Imap4Grp.ResumeLayout(false);
             this.Imap4Grp.PerformLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.Imap4ServerPort)).EndInit();
             this.SMTPGrp.ResumeLayout(false);
             this.SMTPGrp.PerformLayout();
-            ((System.ComponentModel.ISupportInitialize)(this.Imap4ServerPort)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.SMTPServerPort)).EndInit();
             this.ResumeLayout(false);
             this.PerformLayout();
         private System.Windows.Forms.Label label6;
         private System.Windows.Forms.TextBox SignatureTxt;
         private System.Windows.Forms.Label label7;
+        private System.Windows.Forms.CheckBox Imap4EnableChk;
+        private System.Windows.Forms.Label label8;
+        private System.Windows.Forms.TextBox Imap4SentfolderTxt;
     }
 }
\ No newline at end of file
index 29d8839..9b65b6f 100644 (file)
@@ -43,6 +43,8 @@ namespace MailDivSender
             Properties.Settings.Default.Pass = PassTxt.Text;
             Properties.Settings.Default.Imap4Server = Imap4ServerTxt.Text;
             Properties.Settings.Default.Imap4Port = (int)Imap4ServerPort.Value;
+            Properties.Settings.Default.Imap4Enable = Imap4EnableChk.Checked;
+            Properties.Settings.Default.Imap4Sentfolder = Imap4SentfolderTxt.Text;
             Properties.Settings.Default.SMTPServer = SMTPServerTxt.Text;
             Properties.Settings.Default.SMTPPort = (int)SMTPServerPort.Value;
             Properties.Settings.Default.Signature = SignatureTxt.Text;
@@ -59,6 +61,8 @@ namespace MailDivSender
             PassTxt.Text = Properties.Settings.Default.Pass;
             Imap4ServerTxt.Text = Properties.Settings.Default.Imap4Server;
             Imap4ServerPort.Value = Properties.Settings.Default.Imap4Port;
+            Imap4EnableChk.Checked = Properties.Settings.Default.Imap4Enable;
+            Imap4SentfolderTxt.Text = Properties.Settings.Default.Imap4Sentfolder;
             SMTPServerTxt.Text = Properties.Settings.Default.SMTPServer;
             SMTPServerPort.Value = Properties.Settings.Default.SMTPPort;
             SignatureTxt.Text = Properties.Settings.Default.Signature;