ExchangeMailMessage.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using Microsoft.Exchange.WebServices.Data;
  2. namespace InABox.Mail
  3. {
  4. public class ExchangeMailSummary : ICoreMailSummary
  5. {
  6. public string ID => throw new NotImplementedException();
  7. public DateTime Date => throw new NotImplementedException();
  8. public string From
  9. {
  10. get => throw new NotImplementedException();
  11. set => throw new NotImplementedException();
  12. }
  13. public string Subject
  14. {
  15. get => throw new NotImplementedException();
  16. set => throw new NotImplementedException();
  17. }
  18. public IEnumerable<string> To
  19. {
  20. get => throw new NotImplementedException();
  21. set => throw new NotImplementedException();
  22. }
  23. }
  24. public class ExchangeMailMessage : ICoreMailMessage
  25. {
  26. private Tuple<string, byte[]>[] _attachments = { };
  27. private ExchangeMailMessage()
  28. {
  29. }
  30. public ExchangeMailMessage(EmailMessage message)
  31. {
  32. Message = message;
  33. }
  34. public EmailMessage Message { get; }
  35. public void Save()
  36. {
  37. Message.Save();
  38. }
  39. public string ID
  40. {
  41. get => Message.Id.UniqueId;
  42. set => throw new NotImplementedException();
  43. }
  44. public DateTime Date
  45. {
  46. get => Message.DateTimeReceived;
  47. set => throw new NotImplementedException();
  48. }
  49. public string From
  50. {
  51. get => Message.From.Address;
  52. set => Message.From.Address = value;
  53. }
  54. public IEnumerable<string> To
  55. {
  56. get { return Message.ToRecipients.Select(x => x.Address); }
  57. set
  58. {
  59. Message.ToRecipients.Clear();
  60. Message.ToRecipients.AddRange(value);
  61. }
  62. }
  63. public IEnumerable<string> CC
  64. {
  65. get { return Message.CcRecipients.Select(x => x.Address); }
  66. set
  67. {
  68. Message.CcRecipients.Clear();
  69. Message.CcRecipients.AddRange(value);
  70. }
  71. }
  72. public IEnumerable<string> BCC
  73. {
  74. get { return Message.BccRecipients.Select(x => x.Address); }
  75. set
  76. {
  77. Message.BccRecipients.Clear();
  78. Message.BccRecipients.AddRange(value);
  79. }
  80. }
  81. public string Subject
  82. {
  83. get => Message.Subject;
  84. set => Message.Subject = value;
  85. }
  86. public string Body
  87. {
  88. get => Message.Body;
  89. set => Message.Body = value;
  90. }
  91. public IEnumerable<Tuple<string, byte[]>> Attachments
  92. {
  93. get => _attachments;
  94. set
  95. {
  96. _attachments = value.ToArray();
  97. Message.Attachments.Clear();
  98. foreach (var attach in value)
  99. Message.Attachments.AddFileAttachment(attach.Item1, attach.Item2);
  100. }
  101. }
  102. public bool IsHTML
  103. {
  104. get => Message.Body.BodyType == BodyType.HTML;
  105. set => Message.Body.BodyType = value ? BodyType.HTML : BodyType.Text;
  106. }
  107. }
  108. }