1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
/*
Copyright 2013-2015 appPlant UG
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
using De.APPPlant.Cordova.Plugin.EmailComposer;
using Microsoft.Phone.Tasks;
using System;
using System.Linq;
using WPCordovaClassLib.Cordova;
using WPCordovaClassLib.Cordova.Commands;
using WPCordovaClassLib.Cordova.JSON;
namespace Cordova.Extension.Commands
{
/// <summary>
/// Implementes access to email composer task
/// http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394003(v=vs.105).aspx
/// </summary>
public class EmailComposer : BaseCommand
{
/// <summary>
/// Überprüft, ob Emails versendet werden können.
/// </summary>
public void isAvailable(string jsonArgs)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, true));
}
/// <summary>
/// Öffnet den Email-Kontroller mit vorausgefüllten Daten.
/// </summary>
public void open(string jsonArgs)
{
string[] args = JsonHelper.Deserialize<string[]>(jsonArgs);
Options options = JsonHelper.Deserialize<Options>(args[0]);
EmailComposeTask draft = GetDraftWithProperties(options);
DispatchCommandResult(new PluginResult(PluginResult.Status.OK, true));
OpenDraft(draft);
}
/// </summary>
/// Erstellt den Email-Composer und fügt die übergebenen Eigenschaften ein.
/// </summary>
private EmailComposeTask GetDraftWithProperties(Options options)
{
EmailComposeTask draft = new EmailComposeTask();
SetSubject(options.Subject, draft);
SetBody(options.Body, options.IsHtml, draft);
SetTo(options.To, draft);
SetCc(options.Cc, draft);
SetBcc(options.Bcc, draft);
SetAttachments(options.Attachments, draft);
return draft;
}
/// </summary>
/// Zeigt den ViewController zum Versenden/Bearbeiten der Mail an.
/// </summary>
private void OpenDraft(EmailComposeTask draft)
{
draft.Show();
}
/// </summary>
/// Setzt den Subject der Mail.
/// </summary>
private void SetSubject(string subject, EmailComposeTask draft)
{
draft.Subject = subject;
}
/// </summary>
/// Setzt den Body der Mail.
/// </summary>
private void SetBody(string body, Boolean isHTML, EmailComposeTask draft)
{
draft.Body = body;
}
/// </summary>
/// Setzt die Empfänger der Mail.
/// </summary>
private void SetTo(string[] recipients, EmailComposeTask draft)
{
draft.To = string.Join(",", recipients);
}
/// </summary>
/// Setzt die CC-Empfänger der Mail.
/// </summary>
private void SetCc(string[] recipients, EmailComposeTask draft)
{
draft.Cc = string.Join(",", recipients);
}
/// </summary>
/// Setzt die BCC-Empfänger der Mail.
/// </summary>
private void SetBcc(string[] recipients, EmailComposeTask draft)
{
draft.Bcc = string.Join(",", recipients);
}
/// </summary>
/// Fügt die Anhände zur Mail hinzu.
/// </summary>
private void SetAttachments(string[] attachments, EmailComposeTask draft)
{
// Not supported on WP8.0 and WP8.1 Silverlight
}
}
}
|