Без опису

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