This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 506
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* email API initial commit UWP OK * Email Sample and Device Tests * API according to comments * Android Composing finished * Update the Email API * Update the tests - removed the emil tests as this will leave the current app * Update the tests - removed the emil tests as this will leave the current app * Add base for email attachments * Removing attachments as this is not as simple as one might expect... * Removing usless email tests * Return fast * Update Email.uwp.cs * Added the empty email docs * Warnings instead of messages for missing docs as this is serious * This should be private * Updated existing docs to match their APIs * Added the email docs * Updated the samples description * Fix test email address
- Loading branch information
1 parent
877d135
commit 4a110c7
Showing
30 changed files
with
688 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Microsoft.Caboodle; | ||
using Xunit; | ||
|
||
namespace Caboodle.Tests | ||
{ | ||
public class Email_Tests | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System.Threading.Tasks; | ||
using Android.Content; | ||
using Android.OS; | ||
using Android.Text; | ||
|
||
namespace Microsoft.Caboodle | ||
{ | ||
public static partial class Email | ||
{ | ||
static readonly EmailMessage testEmail = | ||
new EmailMessage("Testing Caboodle", "This is a test email.", "caboodle@example.org"); | ||
|
||
internal static bool IsComposeSupported | ||
=> Platform.IsIntentSupported(CreateIntent(testEmail)); | ||
|
||
static Task PlatformComposeAsync(EmailMessage message) | ||
{ | ||
var intent = CreateIntent(message) | ||
.SetFlags(ActivityFlags.ClearTop) | ||
.SetFlags(ActivityFlags.NewTask); | ||
|
||
Platform.CurrentContext.StartActivity(intent); | ||
|
||
return Task.FromResult(true); | ||
} | ||
|
||
static Intent CreateIntent(EmailMessage message) | ||
{ | ||
var intent = new Intent(Intent.ActionSend); | ||
intent.SetType("message/rfc822"); | ||
|
||
if (!string.IsNullOrEmpty(message?.Body)) | ||
{ | ||
if (message?.BodyFormat == EmailBodyFormat.Html) | ||
{ | ||
ISpanned html; | ||
if (Platform.HasApiLevel(BuildVersionCodes.N)) | ||
{ | ||
html = Html.FromHtml(message.Body, FromHtmlOptions.ModeLegacy); | ||
} | ||
else | ||
{ | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
html = Html.FromHtml(message.Body); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
} | ||
intent.PutExtra(Intent.ExtraText, html); | ||
} | ||
else | ||
{ | ||
intent.PutExtra(Intent.ExtraText, message.Body); | ||
} | ||
} | ||
if (!string.IsNullOrEmpty(message?.Subject)) | ||
intent.PutExtra(Intent.ExtraSubject, message.Subject); | ||
if (message.To?.Count > 0) | ||
intent.PutExtra(Intent.ExtraEmail, message.To.ToArray()); | ||
if (message.Cc?.Count > 0) | ||
intent.PutExtra(Intent.ExtraCc, message.Cc.ToArray()); | ||
if (message.Bcc?.Count > 0) | ||
intent.PutExtra(Intent.ExtraBcc, message.Bcc.ToArray()); | ||
|
||
return intent; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Threading.Tasks; | ||
using MessageUI; | ||
|
||
namespace Microsoft.Caboodle | ||
{ | ||
public static partial class Email | ||
{ | ||
internal static bool IsComposeSupported | ||
=> MFMailComposeViewController.CanSendMail; | ||
|
||
static Task PlatformComposeAsync(EmailMessage message) | ||
{ | ||
// do this first so we can throw as early as possible | ||
var parentController = Platform.GetCurrentViewController(); | ||
|
||
// create the controller | ||
var controller = new MFMailComposeViewController(); | ||
if (!string.IsNullOrEmpty(message?.Body)) | ||
controller.SetMessageBody(message.Body, message?.BodyFormat == EmailBodyFormat.Html); | ||
if (!string.IsNullOrEmpty(message?.Subject)) | ||
controller.SetSubject(message.Subject); | ||
if (message?.To.Count > 0) | ||
controller.SetToRecipients(message.To.ToArray()); | ||
if (message?.Cc.Count > 0) | ||
controller.SetCcRecipients(message.Cc.ToArray()); | ||
if (message?.Bcc.Count > 0) | ||
controller.SetBccRecipients(message.Bcc.ToArray()); | ||
|
||
// show the controller | ||
var tcs = new TaskCompletionSource<bool>(); | ||
controller.Finished += (sender, e) => | ||
{ | ||
controller.DismissViewController(true, null); | ||
tcs.SetResult(e.Result == MFMailComposeResult.Sent); | ||
}; | ||
parentController.PresentViewController(controller, true, null); | ||
|
||
return tcs.Task; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Caboodle | ||
{ | ||
public static partial class Email | ||
{ | ||
internal static bool IsComposeSupported => false; | ||
|
||
static Task PlatformComposeAsync(EmailMessage message) => | ||
throw new NotImplementedInReferenceAssemblyException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.Caboodle | ||
{ | ||
public static partial class Email | ||
{ | ||
public static Task ComposeAsync() | ||
=> ComposeAsync(null); | ||
|
||
public static Task ComposeAsync(string subject, string body, params string[] to) | ||
=> ComposeAsync(new EmailMessage(subject, body, to)); | ||
|
||
public static Task ComposeAsync(EmailMessage message) | ||
{ | ||
if (!IsComposeSupported) | ||
throw new FeatureNotSupportedException(); | ||
|
||
return PlatformComposeAsync(message); | ||
} | ||
} | ||
|
||
public class EmailMessage | ||
{ | ||
public EmailMessage() | ||
{ | ||
} | ||
|
||
public EmailMessage(string subject, string body, params string[] to) | ||
{ | ||
To = to?.ToList() ?? new List<string>(); | ||
} | ||
|
||
public string Subject { get; set; } | ||
|
||
public string Body { get; set; } | ||
|
||
public EmailBodyFormat BodyFormat { get; set; } | ||
|
||
public List<string> To { get; set; } = new List<string>(); | ||
|
||
public List<string> Cc { get; set; } = new List<string>(); | ||
|
||
public List<string> Bcc { get; set; } = new List<string>(); | ||
} | ||
|
||
public enum EmailBodyFormat | ||
{ | ||
PlainText, | ||
Html | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Windows.ApplicationModel.Email; | ||
using Windows.Foundation.Metadata; | ||
|
||
using NativeEmailMessage = Windows.ApplicationModel.Email.EmailMessage; | ||
|
||
namespace Microsoft.Caboodle | ||
{ | ||
public static partial class Email | ||
{ | ||
internal static bool IsComposeSupported | ||
=> ApiInformation.IsTypePresent("Windows.ApplicationModel.Email.EmailManager"); | ||
|
||
static async Task PlatformComposeAsync(EmailMessage message) | ||
{ | ||
if (message != null && message.BodyFormat != EmailBodyFormat.PlainText) | ||
throw new FeatureNotSupportedException("UWP can only compose plain text email messages."); | ||
|
||
var nativeMessage = new NativeEmailMessage(); | ||
if (!string.IsNullOrEmpty(message?.Body)) | ||
nativeMessage.Body = message.Body; | ||
if (!string.IsNullOrEmpty(message?.Subject)) | ||
nativeMessage.Subject = message.Subject; | ||
Sync(message?.To, nativeMessage.To); | ||
Sync(message?.Cc, nativeMessage.CC); | ||
Sync(message?.Bcc, nativeMessage.Bcc); | ||
|
||
await EmailManager.ShowComposeNewEmailAsync(nativeMessage); | ||
} | ||
|
||
static void Sync(List<string> recipients, IList<EmailRecipient> nativeRecipients) | ||
{ | ||
if (recipients == null) | ||
return; | ||
|
||
foreach (var recipient in recipients) | ||
{ | ||
nativeRecipients.Add(new EmailRecipient(recipient)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Caboodle; | ||
using Xunit; | ||
|
||
namespace Caboodle.DeviceTests | ||
{ | ||
public class Email_Tests | ||
{ | ||
} | ||
} |
Oops, something went wrong.