Bladeren bron

Added notification image

Kenric Nugteren 4 maanden geleden
bovenliggende
commit
5691b3b46e

+ 24 - 6
inabox.mailer.exchange/ExchangeMailer.cs

@@ -17,7 +17,7 @@ namespace InABox.Mail
     
     public class ExchangeMailer : CoreMailer<ExchangeMailFolder, ExchangeMailSummary, ExchangeMailMessage>
     {
-        private ExchangeService Service;
+        private ExchangeService? Service;
 
         private ExchangeVersion Version = ExchangeVersion.Exchange2007_SP1;
 
@@ -85,12 +85,20 @@ namespace InABox.Mail
                 else
                 {
                     Service.Credentials = new WebCredentials(MailboxUserName, MailboxPassword, MailboxDomain);
-                    Service.Url = new Uri(string.Format("https://{0}:{1}/EWS/Exchange.asmx", MailboxHost, MailboxPort == 0 ? 443 : MailboxPort));
+                    if (MailboxHost.IsNullOrWhiteSpace())
+                    {
+                        Service.AutodiscoverUrl(MailboxUserName, RedirectionUrlValidationCallback);
+                    }
+                    else
+                    {
+                        Service.Url = new Uri(string.Format("https://{0}:{1}/EWS/Exchange.asmx", MailboxHost, MailboxPort == 0 ? 443 : MailboxPort));
+                    }
                 }
                 return true;
             }
             catch (Exception err)
             {
+                CoreUtils.LogException("", err);
                 Service = null;
                 return false;
             }
@@ -100,6 +108,11 @@ namespace InABox.Mail
         {
             return Service != null;
         }
+        
+        private ExchangeService GetService()
+        {
+            return Service ?? throw new Exception("Not Connected");
+        }
 
         protected override bool DoSendMessage(ExchangeMailMessage message)
         {
@@ -118,20 +131,24 @@ namespace InABox.Mail
 
                 email.Subject = message.Subject;
                 email.Body = new MessageBody(BodyType.Text, message.Body);
-                email.SendAndSaveCopy();
+                email.SendAndSaveCopy().ContinueWith(MessageSent);
                 result = true;
             }
 
             return result;
         }
 
+        private void MessageSent(System.Threading.Tasks.Task task)
+        {
+        }
+
         protected override ExchangeMailFolder DoFindFolder(ExchangeMailFolder parent, string name)
         {
             FindFoldersResults results = null;
             if (parent == null)
-                results = Service.FindFolders(WellKnownFolderName.Inbox, new FolderView(int.MaxValue)).Result;
+                results = GetService().FindFolders(WellKnownFolderName.Inbox, new FolderView(int.MaxValue)).Result;
             else
-                results = Service.FindFolders(parent.Folder.Id, new FolderView(int.MaxValue)).Result;
+                results = GetService().FindFolders(parent.Folder.Id, new FolderView(int.MaxValue)).Result;
             var result = results.FirstOrDefault(x => x.DisplayName.Equals(name));
             return new ExchangeMailFolder(result);
         }
@@ -155,7 +172,7 @@ namespace InABox.Mail
 
         protected override IEnumerable<ExchangeMailMessage> DoGetMessages(ExchangeMailFolder folder)
         {
-            var parent = folder != null ? folder.Folder : Service.FindFolders(WellKnownFolderName.Inbox, new FolderView(1)).Result.FirstOrDefault();
+            var parent = folder != null ? folder.Folder : GetService().FindFolders(WellKnownFolderName.Inbox, new FolderView(1)).Result.FirstOrDefault();
             if (parent != null)
             {
                 FindItemsResults<Item> items = parent.FindItems(new ItemView(int.MaxValue)).Result;
@@ -168,6 +185,7 @@ namespace InABox.Mail
                     }
                     catch (Exception e)
                     {
+                        CoreUtils.LogException("", e);
                     }
 
                 return results;

+ 4 - 0
inabox.wpf/InABox.Wpf.csproj

@@ -82,6 +82,7 @@
         <None Remove="Resources\menu.png" />
         <None Remove="Resources\merge.png" />
         <None Remove="Resources\next.png" />
+        <None Remove="Resources\notification.png" />
         <None Remove="Resources\Numbering16.png" />
         <None Remove="Resources\Numbering_LowLetter_Brace.png" />
         <None Remove="Resources\Numbering_LowLetter_Dot.png" />
@@ -333,6 +334,9 @@
       <Resource Include="Resources\next.png">
         <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
       </Resource>
+      <Resource Include="Resources\notification.png">
+        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+      </Resource>
       <Resource Include="Resources\Numbering16.png">
         <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
       </Resource>

+ 10 - 0
inabox.wpf/Resources.Designer.cs

@@ -690,6 +690,16 @@ namespace InABox.Wpf {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized resource of type System.Drawing.Bitmap.
+        /// </summary>
+        public static System.Drawing.Bitmap notification {
+            get {
+                object obj = ResourceManager.GetObject("notification", resourceCulture);
+                return ((System.Drawing.Bitmap)(obj));
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized resource of type System.Drawing.Bitmap.
         /// </summary>

+ 3 - 0
inabox.wpf/Resources.resx

@@ -307,6 +307,9 @@
   <data name="next" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>Resources\next.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>
+  <data name="notification" type="System.Resources.ResXFileRef, System.Windows.Forms">
+    <value>Resources\notification.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
+  </data>
   <data name="Numbering16" type="System.Resources.ResXFileRef, System.Windows.Forms">
     <value>Resources\Numbering16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
   </data>

BIN
inabox.wpf/Resources/notification.png