-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSmartmessagesAPI.cs
729 lines (640 loc) · 26.8 KB
/
SmartmessagesAPI.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
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.IO;
using System.Text;
using System.Security.Cryptography;
using System.Xml;
/// <summary>
/// Summary description for SmartmessagesAPI
/// </summary>
public class SmartmessagesAPI
{
/// <summary>
/// The authenticated access key for this session
/// </summary>
protected string accesskey = String.Empty;
/// <summary>
/// The API endpoint to direct requests at, set during login
/// </summary>
protected string endpoint = String.Empty;
/// <summary>
/// Whether we have logged in successfully
/// </summary>
public bool connected = false;
/// <summary>
/// Timestamp of when this session expires
/// </summary>
public int expires = 0;
/// <summary>
/// The user name used to log in to the API, usually an email address
/// </summary>
public string accountname = String.Empty;
/// <summary>
/// The most recent status message received from the API - true for success, false otherwise
/// </summary>
public bool laststatus = true;
/// <summary>
/// The most recent error code received. 0 if no error.
/// </summary>
public int errorcode = 0;
/// <summary>
/// The most recent message received in an API response. Does not necessarily indicate an error,
/// may have some other informational content.
/// </summary>
public string message = String.Empty;
/// <summary>
/// Whether to run in debug mode. With this enabled, all requests and responses generate descriptive output
/// </summary>
public bool debug = false;
/// <summary>
/// Constructor, creates a new Smartmessages API instance with debugging set to false
/// </summary>
public SmartmessagesAPI()
{
this.debug = false;
}
/// <summary>
/// Constructor override, creates a new Smartmessages API instance with debug option
/// </summary>
public SmartmessagesAPI(bool debug)
{
this.debug = debug;
}
/// <summary>
/// Open a session with the Smartmessages API
/// Throws an exception if login fails
/// @param string user - The user name (usually an email address)
/// @param string password
/// @param string apikey - The API key as shown on the settings page of the smartmessages UI
/// @return boolean true if login was successful
/// @access public
/// </summary>
public bool login(string user, string pass, string apikey)
{
string baseurl = "https://www.smartmessages.net/api/";
return login(user, pass, apikey, baseurl);
}
/// <summary>
/// Open a session with the Smartmessages API
/// Throws an exception if login fails
/// @param string user - The user name (usually an email address)
/// @param string password
/// @param string apikey - The API key as shown on the settings page of the smartmessages UI
/// @param string baseurl - The initial entry point for the Smartmessage API
/// @return boolean true if login was successful
/// @access public
/// </summary>
public bool login(string user, string pass, string apikey, string baseurl)
{
Hashtable request_params = new Hashtable();
request_params["username"] = user;
request_params["password"] = pass;
request_params["apikey"] = apikey;
request_params["outputformat"] = "xml";
string response = dorequest("login", request_params, baseurl);
DataSet ds = new DataSet("login");
ds.ReadXml(new StringReader(response));
this.connected = true;
this.accesskey = ds.Tables["response"].Rows[0]["accesskey"].ToString().Trim();
this.endpoint = ds.Tables["response"].Rows[0]["endpoint"].ToString().Trim();
this.expires = int.Parse(ds.Tables["response"].Rows[0]["expires"].ToString().Trim());
this.accountname = ds.Tables["response"].Rows[0]["accountname"].ToString().Trim();
return true;
}
/// <summary>
/// Close a session with the Smartmessages API
/// @access public
/// </summary>
public void logout()
{
dorequest("logout");
this.connected = false;
this.accesskey = String.Empty;
this.expires = 0;
}
/// <summary>
/// Does nothing, but keeps a connection open and extends the session expiry time
/// @access public
/// </summary>
public bool ping()
{
string response = dorequest("ping");
DataSet ds = new DataSet("ping");
ds.ReadXml(new StringReader(response));
return ds.Tables["response"].Rows[0]["status"].ToString()=="0"?false:true;
}
/// <summary>
/// Subscribe an address to a list
/// @see getlists()
/// @param string address The email address
/// @param integer listid The ID of the list to subscribe the user to
/// @param string dear A preferred greeting that's not necessarily their actual name, such as 'Scooter', 'Mrs Smith', 'Mr President'
/// @param string firstname
/// @param string lastname
/// @return boolean true if subscribe was successful
/// @access public
/// </summary>
public bool subscribe(string address, string listid, string dear, string firstname, string lastname) {
if (address.Trim() == "" || int.Parse(listid) <= 0) {
throw new SmartmessagesAPIException("Invalid subscribe parameters");
}
Hashtable request_params = new Hashtable();
request_params["address"] = address;
request_params["listid"] = listid;
request_params["dear"] = dear;
request_params["firstname"] = firstname;
request_params["lastname"] = lastname;
string response = dorequest("subscribe", request_params);
DataSet ds = new DataSet("subscribe");
ds.ReadXml(new StringReader(response));
return ds.Tables["response"].Rows[0]["status"].ToString()=="0"?false:true;
}
public bool subscribe(string address, string listid)
{
return subscribe(address, listid, "", "", "");
}
/// <summary>
/// Unsubscribe an address from a list
/// @see getlists()
/// @param string address The email address
/// @param integer listid The ID of the list to unsubscribe the user from
/// @return boolean true if unsubscribe was successful
/// @access public
/// </summary>
public bool unsubscribe(string address, string listid) {
if (address.Trim() == "" || int.Parse(listid) <= 0) {
throw new SmartmessagesAPIException("Invalid unsubscribe parameters");
}
Hashtable request_params = new Hashtable();
request_params["address"] = address;
request_params["listid"] = listid;
string response = dorequest("unsubscribe", request_params);
DataSet ds = new DataSet("unsubscribe");
ds.ReadXml(new StringReader(response));
return ds.Tables["response"].Rows[0]["status"].ToString()=="0"?false:true;
}
/// <summary>
/// Get the details of all the mailing lists in your account
/// @return DataTable
/// @access public
/// </summary>
public DataTable getlists() {
string response = dorequest("getlists");
DataSet ds = new DataSet("getlists");
ds.ReadXml(new StringReader(response));
return ds.Tables["element"];
}
/**
* Get info about a recipient
* @param string address The email address
* @return array Info about the user
* @access public
*/
public DataSet getuserinfo(string address) {
if (address.Trim() == "") {
throw new SmartmessagesAPIException("Invalid email address");
}
Hashtable request_params = new Hashtable();
request_params["address"] = address;
string response = dorequest("getuserinfo", request_params);
DataSet ds = new DataSet("getuserinfo");
ds.ReadXml(new StringReader(response));
return ds;
}
/**
* Set info about a recipient
* @see getuserinfo()
* @param string address The email address
* @param array userinfo Array of user properties in the same format as returned by getuserinfo()
* @return boolean true on success
* @access public
*/
public bool setuserinfo(string address, string userinfo) {
if (address.Trim() == "") {
throw new SmartmessagesAPIException("Invalid email address");
}
string request_params = "address=" + address + "&" + userinfo;
string response = dorequest("setuserinfo", request_params);
DataSet ds = new DataSet("setuserinfo");
ds.ReadXml(new StringReader(response));
return ds.Tables["response"].Rows[0]["status"].ToString() == "0" ? false : true;
}
/// <summary>
/// Get a list of everyone that has reported messages from you as spam
/// Only available from some ISPs, notably hotmail and AOL
/// @return DataSet
/// @access public
/// </summary>
public DataSet getspamreporters() {
string response = dorequest("getspamreporters");
DataSet ds = new DataSet("spamreporters");
ds.ReadXml(new StringReader(response));
return ds;
}
/// <summary>
/// Get your current default import field order list
/// @return array
/// @access public
/// </summary>
public DataTable getfieldorder() {
string response = dorequest("getfieldorder");
DataSet ds = new DataSet("getfieldorder");
ds.ReadXml(new StringReader(response));
return ds.Tables["element"];
}
/// <summary>
/// Get your current default import field order list
/// The field list MUST include emailaddress
/// Any invalid or unknown names will be ignored
/// @see getfieldorder()
/// @param array $fields Simple array of field names
/// @return array The array of field names that was set, after filtering
/// @access public
/// </summary>
public DataTable setfieldorder(string fields) {
if (fields == String.Empty || fields.IndexOf("emailaddress") == -1) {
throw new SmartmessagesAPIException("Invalid field order");
}
Hashtable request_params = new Hashtable();
request_params["fields"] = fields.Replace(",","%2C");
string response = dorequest("setfieldorder", request_params);
DataSet ds = new DataSet("setfieldorder");
ds.ReadXml(new StringReader(response));
return ds.Tables["element"];
}
/// <summary>
/// Get a list of everyone that has unsubscribed from the specified mailing list
/// @return DataTable
/// @access public
/// </summary>
public DataTable getlistunsubs(string listid) {
if (int.Parse(listid) <= 0) {
throw new SmartmessagesAPIException("Invalid list id");
}
Hashtable request_params = new Hashtable();
request_params["listid"] = listid;
string response = dorequest("getlistunsubs", request_params);
DataSet ds = new DataSet("getlistunsubs");
ds.ReadXml(new StringReader(response));
return ds.Tables["element"];
}
/// <summary>
/// Upload a mailing list
/// @see getlists()
/// @see getfieldorder()
/// @see getuploadinfo()
/// @param string listid The ID of the list to upload into
/// @param string listfilename A path to a local file containing your mailing list in CSV format (may also be zipped)
/// @param string source For audit trail purposes, you must populate this with a note of where this list came from
/// @param boolean definitive If set to true, overwrite any existing data in the fields included in the file, otherwise existing data will not be touched, but recipients will still be added to the list
/// @param boolean replace Whether to empty the list before uploading this list
/// @param boolean fieldorderfirstline Set to true if the first line of the file contains field names
/// @return integer|boolean On success, the upload ID for passing to getuploadinfo(), otherwise boolean false
/// @access public
/// </summary>
public object uploadlist(string listid, string listfilename, string source, bool definitive, bool replace, bool fieldorderfirstline) {
if (int.Parse(listid) <= 0) {
throw new SmartmessagesAPIException("Invalid list id");
}
if (!File.Exists(listfilename)) {
throw new SmartmessagesAPIException("File does not exist!");
}
if (filesize(listfilename) < 6) { //This is the smallest a single external email address could possibly be
throw new SmartmessagesAPIException("File does not contain any data!");
}
Hashtable request_params = new Hashtable();
request_params["method"] = "uploadlist";
request_params["listid"] = listid;
request_params["source"] = source;
request_params["definitive"] = definitive==true?"true":"false";
request_params["replace"] = replace==true?"true":"false";
request_params["fieldorderfirstline"] = fieldorderfirstline==true?"true":"false";
Hashtable files = new Hashtable();
files[listfilename] = listfilename;
string response = dorequest("uploadlist", request_params, null, true, files);
DataSet ds = new DataSet("uploadlist");
ds.ReadXml(new StringReader(response));
//Return the upload ID on success, or false if it failed
if(ds.Tables["response"].Rows[0]["status"].ToString()=="0")
return false;
else
return ds.Tables["response"].Rows[0]["uploadid"].ToString();
}
/// <summary>
/// Get info on a previous list upload
/// @see getlists()
/// @see getfieldorder()
/// @see uploadlist()
/// @param string listid The ID of the list the upload belongs to
/// @param string uploadid The ID of the upload (as returned from uploadlist())
/// @return DataTable A list of upload properties. Includes lists of bad or invalid addresses, source tracking field
/// @access public
/// </summary>
public DataTable getuploadinfo(string listid, string uploadid) {
if (int.Parse(listid) <= 0 || int.Parse(uploadid) <= 0) {
throw new SmartmessagesAPIException("Invalid getuploadinfo parameters");
}
Hashtable request_params = new Hashtable();
request_params["listid"] = listid;
request_params["uploadid"] = uploadid;
string response = dorequest("getuploadinfo", request_params);
DataSet ds = new DataSet("getuploadinfo");
ds.ReadXml(new StringReader(response));
return ds.Tables["element"];
}
/// <summary>
/// Get info on all previous list uploads
/// Only gives basic info on each upload, more detail can be obtained using getuploadinfo()
/// @see getlists()
/// @see uploadlist()
/// @see getuploadinfo()
/// @param integer listid The ID of the list the upload belongs to
/// @return DataTable An array of uploads with properties for each.
/// @access public
/// </summary>
public DataTable getuploads(string listid) {
if (int.Parse(listid) <= 0) {
throw new SmartmessagesAPIException("Invalid getuploads parameters");
}
Hashtable request_params = new Hashtable();
request_params["listid"] = listid;
string response = dorequest("getuploads", request_params);
DataSet ds = new DataSet("getuploads");
ds.ReadXml(new StringReader(response));
return ds.Tables["element"];
}
/// <summary>
/// Cancel a pending or in-progress upload
/// Cancelled uploads are deleted, so won't appear in getuploads()
/// Deletions are asynchronous, so won't happen immediately
/// @see getlists()
/// @see uploadlist()
/// @param string listid The ID of the list the upload belongs to
/// @param string uploadid The ID of the upload (as returned from uploadlist())
/// @return boolean true on success
/// @access public
/// </summary>
public bool cancelupload(string listid, string uploadid) {
if (int.Parse(listid) <= 0 || int.Parse(uploadid) <= 0) {
throw new SmartmessagesAPIException("Invalid getuploadinfo parameters");
}
Hashtable request_params = new Hashtable();
request_params["listid"] = listid;
request_params["uploadid"] = uploadid;
string response = dorequest("cancelupload", request_params);
DataSet ds = new DataSet("cancelupload");
ds.ReadXml(new StringReader(response));
return ds.Tables["response"].Rows[0]["status"].ToString()=="0"?false:true;
}
/// <summary>
/// Get the callback URL for your account
/// Read our support wiki for more details on this
/// @return string
/// @access public
/// </summary>
public string getcallbackurl() {
string response = dorequest("getcallbackurl");
DataSet ds = new DataSet("getcallbackurl");
ds.ReadXml(new StringReader(response));
return ds.Tables["response"].Rows[0]["url"].ToString();
}
/// <summary>
/// Set the callback URL for your account
/// Read our support wiki for more details on this
/// @param string url The URL of your callback script (this will be on YOUR web server, not ours)
/// @return true on success
/// @access public
/// </summary>
public bool setcallbackurl(string url) {
if (url.Trim() == "") {
throw new SmartmessagesAPIException("Invalid setcallbackurl url");
}
Hashtable request_params = new Hashtable();
request_params["url"] = url;
string response = dorequest("setcallbackurl", request_params);
DataSet ds = new DataSet("setcallbackurl");
ds.ReadXml(new StringReader(response));
return ds.Tables["response"].Rows[0]["status"].ToString()=="0"?false:true;
}
/// <summary>
/// Simple address validator
/// It's more efficient to use a function on your own site to do this, but using this will ensure that any address you add to a list will also be accepted by us
/// If you encounter an address that we reject that you think we shouldn't, please tell us!
/// Read our support wiki for more details on this
/// @return boolean
/// @access public
/// </summary>
public bool validateaddress(string address) {
Hashtable request_params = new Hashtable();
request_params["address"] = address;
string response = dorequest("validateaddress", request_params);
DataSet ds = new DataSet("validateaddress");
ds.ReadXml(new StringReader(response));
return ds.Tables["response"].Rows[0]["valid"].ToString() == "0" ? false : true;
}
protected string dorequest(string command)
{
Hashtable request_params = new Hashtable();
return dorequest(command, request_params, String.Empty, false, new Hashtable());
}
protected string dorequest(string command, Hashtable request_params)
{
return dorequest(command, request_params, String.Empty, false, new Hashtable());
}
protected string dorequest(string command, Hashtable request_params, string urloverride)
{
return dorequest(command, request_params, urloverride, false, new Hashtable());
}
protected string dorequest(string command, Hashtable request_params, string urloverride, bool post, Hashtable files)
{
string response = "";
//All commands except login need an accesskey
if (this.accesskey != String.Empty) {
if (!request_params.ContainsKey("accesskey"))
request_params.Add("accesskey", this.accesskey);
}
if(!request_params.ContainsKey("outputformat"))
request_params.Add("outputformat", "xml"); // XML is default output format
string url = "";
if (urloverride == String.Empty || urloverride == null) {
if (this.endpoint == String.Empty) {
//We can't connect
throw new SmartmessagesAPIException("Missing Smartmessages API URL");
} else {
url = this.endpoint;
}
} else {
url = urloverride;
}
url += command;
//Make the request
if (post) {
if (this.debug) {
HttpContext.Current.Response.Write("<h1>POST Request (" + htmlspecialchars(command) + "):</h1><p>" + htmlspecialchars(url) + "</p>\n");
}
response = do_post_request(url, request_params, files);
} else {
if (request_params != null && request_params.Count > 0) {
url += '?' + http_build_query(request_params);
}
if (this.debug) {
HttpContext.Current.Response.Write("<h1>GET Request (" + htmlspecialchars(command) +"):</h1><p>" + htmlspecialchars(url) + "</p>\n");
}
response = url_get_contents(url);
}
return response;
}
protected string dorequest(string command, string request_params)
{
string response = "";
//All commands except login need an accesskey
if (request_params.IndexOf("accesskey") == -1)
request_params += "&accesskey=" + this.accesskey;
if(request_params.IndexOf("outputformat") == -1)
request_params += "&outputformat=xml"; // XML is default output format
string url = "";
if (this.endpoint == String.Empty) {
//We can't connect
throw new SmartmessagesAPIException("Missing Smartmessages API URL");
} else {
url = this.endpoint;
}
url += command;
//Make the request
if (request_params != null && request_params != String.Empty) {
url += '?' + request_params.Replace("[", "%5B").Replace("]", "%5D");
}
if (this.debug) {
HttpContext.Current.Response.Write("<h1>GET Request (" + htmlspecialchars(command) +"):</h1><p>" + htmlspecialchars(url) + "</p>\n");
}
response = url_get_contents(url);
return response;
}
private string do_post_request(string url, Hashtable postdata, Hashtable files)
{
string response = "";
string data = "";
string boundary = "---------------------" + md5(rand(0,32000)).Substring(0, 10);
//Collect Postdata
foreach(string key in postdata.Keys) {
data += "--" + boundary + "\n";
data += "Content-Disposition: form-data; name=\"" + key + "\"\n\n" + postdata[key].ToString() + "\n";
}
data += "--" + boundary + "\n";
//Collect Filedata
foreach(string key in files.Keys) {
string file = files[key].ToString();
string filename = basename(file);
data += "Content-Disposition: form-data; name=\""+ filename + "\"; filename=\"" + filename + "\"\n";
data += "Content-Type: application/octet-stream\n"; //Could be anything, so just upload as raw binary stuff
data += "Content-Transfer-Encoding: binary\n\n";
data += file_get_contents(file) + "\n";
data += "--" + boundary + "--\n";
}
if (this.debug) {
HttpContext.Current.Response.Write("<h2>POST body:</h2><pre>");
if(data.Length > 8192)
HttpContext.Current.Response.Write(htmlspecialchars(data).Substring(0, 8192)); //Limit size of debug output
else
HttpContext.Current.Response.Write(htmlspecialchars(data));
HttpContext.Current.Response.Write("</pre>\n");
}
url = "http://www.smartmessages.net/api/uploadlist";
url += "?accesskey=" + postdata["accesskey"].ToString() + "&outputformat=xml";
HttpWebRequest wrq = (HttpWebRequest)HttpWebRequest.Create(url);
wrq.Method = "POST";
wrq.ContentType = "multipart/form-data; boundary=" + boundary;
byte[] bin_data = Encoding.UTF8.GetBytes(data);
wrq.ContentLength = bin_data.Length;
Stream writeStream = wrq.GetRequestStream();
writeStream.Write(bin_data, 0, bin_data.Length);
writeStream.Close();
HttpWebResponse wrs = (HttpWebResponse)wrq.GetResponse();
StreamReader sr = new StreamReader(wrs.GetResponseStream());
response = sr.ReadToEnd();
return response;
}
private string url_get_contents(string address)
{
HttpWebRequest wrq = (HttpWebRequest)HttpWebRequest.Create(address);
HttpWebResponse wrs = (HttpWebResponse)wrq.GetResponse();
StreamReader sr = new StreamReader(wrs.GetResponseStream());
return sr.ReadToEnd();
}
private string htmlspecialchars(string input)
{
input.Replace("&", "&");
input.Replace("\"", """);
input.Replace("'", "'");
input.Replace("<", "<");
input.Replace(">", ">");
return input;
}
private string http_build_query(Hashtable request_params)
{
string query = "";
int i = 0;
foreach (string key in request_params.Keys)
{
if (i != 0)
query += "&" + key + "=" + request_params[key].ToString();
else
query += key + "=" + request_params[key].ToString();
i++;
}
return query;
}
private string rand(int min, int max)
{
Random random = new Random();
return random.Next(min, max).ToString();
}
private string md5(string input)
{
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
byte[] unicodeText = new byte[input.Length * 2];
enc.GetBytes(input.ToCharArray(), 0, input.Length, unicodeText, 0, true);
MD5 md5Service = new MD5CryptoServiceProvider();
byte[] result = md5Service.ComputeHash(unicodeText);
StringBuilder sb = new StringBuilder();
for (int i=0;i<result.Length;i++)
{
sb.Append(result[i].ToString("X2"));
}
return sb.ToString();
}
private string basename(string input)
{
input = input.Replace("\\", "/"); //Windows style file paths
string[] _input = input.Split('/');
return _input[_input.Length - 1];
}
private string file_get_contents(string filepath)
{
string file_contents = "";
StreamReader stream = new StreamReader(filepath);
file_contents = stream.ReadToEnd();
stream.Dispose();
stream.Close();
return file_contents;
}
private long filesize(string filepath)
{
FileInfo finfo = new FileInfo(filepath);
return finfo.Length;
}
}
class SmartmessagesAPIException : ArgumentException {
public SmartmessagesAPIException() : base() { }
public SmartmessagesAPIException(string message) : base(message) { }
}