forked from pmengal/MailSystem.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccountSettings.cs
More file actions
325 lines (267 loc) · 8.48 KB
/
AccountSettings.cs
File metadata and controls
325 lines (267 loc) · 8.48 KB
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Windows.Forms;
/// <summary>
/// Summary description for AccountSettings
/// </summary>
///
public enum AccountType
{
POP3, IMAP
}
[Serializable]
public class AccountSettings : IList<AccountSettings.AccountInfo>
{
// Private Members and Public properties
[Serializable]
public class AccountInfo
{
private string emailAddress;
private string password;
private string displayName;
private string incomingMailServer;
private string outgoingServer;
private string loginId;
private int portIncomingServer;
private int portOutgoingServer;
private bool isIncomeSecureConnection;
private bool isOutgoingSecureConnection;
private bool isOutgoingWithAuthentication;
private bool portIncomingChecked;
private bool portOutgoingChecked;
private Guid _AccountID;
#region gets e sets
public bool PortIncomingChecked
{
get { return portIncomingChecked; }
set { portIncomingChecked = value; }
}
public bool PortOutgoingChecked
{
get { return portOutgoingChecked; }
set { portOutgoingChecked = value; }
}
public string EmailAddress
{
get { return emailAddress; }
set { emailAddress = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public string DisplayName
{
get { return displayName; }
set { displayName = value; }
}
public string IncomingMailServer
{
get { return incomingMailServer; }
set { incomingMailServer = value; }
}
public string OutgoingServer
{
get { return outgoingServer; }
set { outgoingServer = value; }
}
public string LoginId
{
get { return loginId; }
set { loginId = value; }
}
public int PortIncomingServer
{
get { return portIncomingServer; }
set { portIncomingServer = value; }
}
public int PortOutgoingServer
{
get { return portOutgoingServer; }
set { portOutgoingServer = value; }
}
public bool IsIncomeSecureConnection
{
get { return isIncomeSecureConnection; }
set { isIncomeSecureConnection = value; }
}
public bool IsOutgoingSecureConnection
{
get { return isOutgoingSecureConnection; }
set { isOutgoingSecureConnection = value; }
}
public bool IsOutgoingWithAuthentication
{
get { return isOutgoingWithAuthentication; }
set { isOutgoingWithAuthentication = value; }
}
public Guid ID
{
get { return _AccountID; }
set { _AccountID = value; }
}
#endregion
}
private List<AccountInfo> m_aAccInfoList;
/// <summary>
/// Default constructor
/// </summary>
public AccountSettings()
{
m_aAccInfoList = new List<AccountInfo>();
}
/// <summary>
/// Get a list of account information
/// </summary>
public AccountInfo[] Accounts
{
get
{
if (m_aAccInfoList != null)
return m_aAccInfoList.ToArray();
return null;
}
}
/// <summary>
/// Add an account to the list.
/// </summary>
/// <param name="ai"></param>
public Guid AddAccount(AccountInfo ai)
{
if (m_aAccInfoList == null)
m_aAccInfoList = new List<AccountInfo>();
ai.ID = Guid.NewGuid();
m_aAccInfoList.Add(ai);
return ai.ID;
}
/// <summary>
/// Saves the Email accont settings to a file.
/// </summary>
/// <param name="file">The file path to save to.</param>
/// <param name="c">AccountSettings object.</param>
public static void Save(string file, AccountSettings c)
{
try
{
if (File.Exists(file))
File.Delete(file);
// TODO: MAke this binary
System.Xml.Serialization.XmlSerializer xs
= new System.Xml.Serialization.XmlSerializer(c.GetType());
StreamWriter writer = File.CreateText(file);
xs.Serialize(writer, c);
writer.Flush();
writer.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// Retrieves the Email Account Settings from a file.
/// </summary>
/// <param name="file">File path to load from.</param>
/// <returns>An instance of AccountSettings object.</returns>
public static AccountSettings Load(string file)
{
if (!File.Exists(file))
{
AccountSettings cfg = new AccountSettings();
Save(file, cfg);
return cfg;
}
// TODO: MAke this binary
System.Xml.Serialization.XmlSerializer xs
= new System.Xml.Serialization.XmlSerializer(
typeof(AccountSettings));
StreamReader reader = File.OpenText(file);
AccountSettings c = new AccountSettings();
try
{
c = (AccountSettings)xs.Deserialize(reader);
}
catch (Exception)
{
}
reader.Close();
return c;
}
#region IList<AccountInfo> Members
public int IndexOf(AccountSettings.AccountInfo item)
{
throw new NotImplementedException();
}
public void Insert(int index, AccountSettings.AccountInfo item)
{
throw new NotImplementedException();
}
public void RemoveAt(int index)
{
throw new NotImplementedException();
}
public AccountSettings.AccountInfo this[int index]
{
get
{
return Accounts[index];
}
set
{
throw new NotImplementedException();
}
}
#endregion
#region ICollection<AccountInfo> Members
public void Add(AccountSettings.AccountInfo item)
{
this.m_aAccInfoList.Add(item);
}
public void Clear()
{
this.m_aAccInfoList.Clear();
}
public bool Contains(AccountSettings.AccountInfo item)
{
return this.m_aAccInfoList.Contains(item);
}
public void CopyTo(AccountSettings.AccountInfo[] array, int arrayIndex)
{
this.m_aAccInfoList.CopyTo(array, arrayIndex);
}
public int Count
{
get { return this.m_aAccInfoList.Count; }
}
public bool IsReadOnly
{
get { return true; }
}
public bool Remove(AccountSettings.AccountInfo item)
{
return this.m_aAccInfoList.Remove(item);
}
#endregion
#region IEnumerable<AccountInfo> Members
public IEnumerator<AccountSettings.AccountInfo> GetEnumerator()
{
return this.m_aAccInfoList.GetEnumerator();
}
#endregion
#region IEnumerable Members
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return this.m_aAccInfoList.GetEnumerator();
}
#endregion
}