forked from p8cakes/CorpMailman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mail.cs
213 lines (162 loc) · 6.9 KB
/
Mail.cs
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/****************************** Module Header ******************************
* Module Name: CorpMailman Windows Service project.
* Project: CorpMailman: Windows Service to send out emails project.
*
* Mail class to collect together all information related to an email we need to send.
*
* Revisions:
* 1. Sundar Krishnamurthy sundar_k@hotmail.com 8/27/2015 Initial file created.
***************************************************************************/
namespace CorpMailman {
#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
#endregion
#region Mail class
/// <summary>
/// Mail class to collect together all information related to an email we need to send
/// </summary>
internal class Mail {
#region Members
/// <summary>List of </summary>
private List<MailAttachment> attachments;
/// <summary>List of Target To: Addresses</summary>
private List<string> toAddresses;
/// <summary>List of CC: Addresses, if any</summary>
private List<string> ccAddresses;
/// <summary>List of BCC: Addresses, if any</summary>
private List<string> bccAddresses;
#endregion
#region Constructor
internal Mail() {
this.attachments = new List<MailAttachment>();
}
#endregion
#region Properties
/// <summary>Mail ID</summary>
internal uint? MailId { get; set; }
/// <summary>From Address</summary>
internal string From { get; set; }
/// <summary>Direct</summary>
internal bool Direct { get; set; }
/// <summary>Importance</summary>
internal bool Importance { get; set; }
/// <summary>Subject</summary>
internal string Subject { get; set; }
/// <summary>Created timestamp (usually UTC)</summary>
internal DateTime? Created { get; set; }
/// <summary>Mail send timestamp value (should be UTC)</summary>
internal DateTime? Timestamp { get; set; }
/// <summary>Subject Prefix</summary>
internal string SubjectPrefix { get; set; }
/// <summary>Whether this has any attachments</summary>
internal bool? HasAttachments { get; set; }
/// <summary>Body</summary>
internal string Body { get; set; }
/// <summary>Mark mail as ready to send</summary>
internal bool MarkMailAsReady { get; set; }
/// <summary>To Addresses, read from database</summary>
internal string ToAddresses {
get {
var toAddress = null as string;
if (this.toAddresses != null) {
var builder = new StringBuilder();
foreach (var address in this.toAddresses) {
if (builder.Length > 0) {
builder.Append(Constants.Comma);
}
builder.Append(address);
}
toAddress = builder.ToString();
builder.Remove(0, builder.Length);
}
return toAddress;
}
set {
if (this.toAddresses == null) {
this.toAddresses = new List<string>();
var toAddressArray = value.Split(Constants.CommaArray);
foreach (var toAddress in toAddressArray) {
this.toAddresses.Add(toAddress.Trim());
}
}
}
}
/// <summary>CC Addresses, read from database</summary>
internal string CcAddresses {
get {
var ccAddress = null as string;
if (this.ccAddresses != null) {
var builder = new StringBuilder();
foreach (var address in this.ccAddresses) {
if (builder.Length > 0) {
builder.Append(Constants.Comma);
}
builder.Append(address);
}
ccAddress = builder.ToString();
builder.Remove(0, builder.Length);
}
return ccAddress;
}
set {
if ((this.ccAddresses == null) && (value != null)) {
this.ccAddresses = new List<string>();
var ccAddressArray = value.Split(Constants.CommaArray);
foreach (var ccAddress in ccAddressArray) {
this.ccAddresses.Add(ccAddress.Trim());
}
}
}
}
/// <summary>BCC Addresses, read from database</summary>
internal string BccAddresses {
get {
var bccAddress = null as string;
if (this.bccAddresses != null) {
var builder = new StringBuilder();
foreach (var address in this.bccAddresses) {
if (builder.Length > 0) {
builder.Append(Constants.Comma);
}
builder.Append(address);
}
bccAddress = builder.ToString();
builder.Remove(0, builder.Length);
}
return bccAddress;
}
set {
if ((this.bccAddresses == null) && (value != null)) {
this.bccAddresses = new List<string>();
var bccAddressArray = value.Split(Constants.CommaArray);
foreach (var bccAddress in bccAddressArray) {
this.bccAddresses.Add(bccAddress.Trim());
}
}
}
}
/// <summary>Get the list of addresses we need to send this mail out to</summary>
internal List<string> ToAddressList { get { return this.toAddresses; } }
/// <summary>Get the list of cc: addresses we need to send this mail out to (if any)</summary>
internal List<string> CcAddressList { get { return this.ccAddresses; } }
/// <summary>Get the list of bcc: addresses we need to send this mail out to (if any)</summary>
internal List<string> BccAddressList { get { return this.bccAddresses; } }
/// <summary>Gets the list of MailAttachments</summary>
internal List<MailAttachment> Attachments { get { return this.attachments; } }
#endregion
#region Methods
#region Public/internal Methods
/// <summary>
/// Add the MailAttachment to list of attachments
/// </summary>
/// <param name="attachment">MailAttachment instance</param>
internal void AddAttachment(MailAttachment attachment) {
this.attachments.Add(attachment);
}
#endregion
#endregion
}
#endregion
}