@@ -62,40 +62,15 @@ public class Mail : Payload
62
62
private readonly string mailReceiver , subject , message ;
63
63
private readonly MailEncoding encoding ;
64
64
65
- /// <summary>
66
- /// Creates an empty email payload
67
- /// </summary>
68
- /// <param name="mailReceiver">Receiver's email address</param>
69
- /// <param name="encoding">Payload encoding type. Choose dependent on your QR Code scanner app.</param>
70
- public Mail ( string mailReceiver , MailEncoding encoding = MailEncoding . MAILTO )
71
- {
72
- this . mailReceiver = mailReceiver ;
73
- this . subject = this . message = string . Empty ;
74
- this . encoding = encoding ;
75
- }
76
-
77
- /// <summary>
78
- /// Creates an email payload with subject
79
- /// </summary>
80
- /// <param name="mailReceiver">Receiver's email address</param>
81
- /// <param name="subject">Subject line of the email</param>
82
- /// <param name="encoding">Payload encoding type. Choose dependent on your QR Code scanner app.</param>
83
- public Mail ( string mailReceiver , string subject , MailEncoding encoding = MailEncoding . MAILTO )
84
- {
85
- this . mailReceiver = mailReceiver ;
86
- this . subject = subject ;
87
- this . message = string . Empty ;
88
- this . encoding = encoding ;
89
- }
90
-
65
+
91
66
/// <summary>
92
67
/// Creates an email payload with subject and message/text
93
68
/// </summary>
94
69
/// <param name="mailReceiver">Receiver's email address</param>
95
70
/// <param name="subject">Subject line of the email</param>
96
71
/// <param name="message">Message content of the email</param>
97
72
/// <param name="encoding">Payload encoding type. Choose dependent on your QR Code scanner app.</param>
98
- public Mail ( string mailReceiver , string subject , string message , MailEncoding encoding = MailEncoding . MAILTO )
73
+ public Mail ( string mailReceiver = null , string subject = null , string message = null , MailEncoding encoding = MailEncoding . MAILTO )
99
74
{
100
75
this . mailReceiver = mailReceiver ;
101
76
this . subject = subject ;
@@ -105,20 +80,26 @@ public Mail(string mailReceiver, string subject, string message, MailEncoding en
105
80
106
81
public override string ToString ( )
107
82
{
83
+ var returnVal = string . Empty ;
108
84
switch ( this . encoding )
109
85
{
110
86
case MailEncoding . MAILTO :
111
- return
112
- $ "mailto:{ this . mailReceiver } ?subject={ System . Uri . EscapeDataString ( this . subject ) } &body={ System . Uri . EscapeDataString ( this . message ) } ";
87
+ var parts = new List < string > ( ) ;
88
+ if ( ! string . IsNullOrEmpty ( this . subject ) )
89
+ parts . Add ( "subject=" + Uri . EscapeDataString ( this . subject ) ) ;
90
+ if ( ! string . IsNullOrEmpty ( this . message ) )
91
+ parts . Add ( "body=" + Uri . EscapeDataString ( this . message ) ) ;
92
+ var queryString = parts . Any ( ) ? $ "?{ string . Join ( "&" , parts . ToArray ( ) ) } " : "" ;
93
+ returnVal = $ "mailto:{ this . mailReceiver } { queryString } ";
94
+ break ;
113
95
case MailEncoding . MATMSG :
114
- return
115
- $ "MATMSG:TO: { this . mailReceiver } ;SUB: { EscapeInput ( this . subject ) } ;BODY: { EscapeInput ( this . message ) } ;;" ;
96
+ returnVal = $ "MATMSG:TO: { this . mailReceiver } ;SUB: { EscapeInput ( this . subject ) } ;BODY: { EscapeInput ( this . message ) } ;;" ;
97
+ break ;
116
98
case MailEncoding . SMTP :
117
- return
118
- $ "SMTP:{ this . mailReceiver } :{ EscapeInput ( this . subject , true ) } :{ EscapeInput ( this . message , true ) } ";
119
- default :
120
- return this . mailReceiver ;
99
+ returnVal = $ "SMTP:{ this . mailReceiver } :{ EscapeInput ( this . subject , true ) } :{ EscapeInput ( this . message , true ) } ";
100
+ break ;
121
101
}
102
+ return returnVal ;
122
103
}
123
104
124
105
public enum MailEncoding
@@ -161,17 +142,26 @@ public SMS(string number, string subject, SMSEncoding encoding = SMSEncoding.SMS
161
142
162
143
public override string ToString ( )
163
144
{
145
+ var returnVal = string . Empty ;
164
146
switch ( this . encoding )
165
- {
147
+ {
166
148
case SMSEncoding . SMS :
167
- return $ "sms:{ this . number } ?body={ System . Uri . EscapeDataString ( this . subject ) } ";
149
+ var queryString = string . Empty ;
150
+ if ( ! string . IsNullOrEmpty ( this . subject ) )
151
+ queryString = $ "?body={ Uri . EscapeDataString ( this . subject ) } ";
152
+ returnVal = $ "sms:{ this . number } { queryString } ";
153
+ break ;
168
154
case SMSEncoding . SMS_iOS :
169
- return $ "sms:{ this . number } ;body={ System . Uri . EscapeDataString ( this . subject ) } ";
155
+ var queryStringiOS = string . Empty ;
156
+ if ( ! string . IsNullOrEmpty ( this . subject ) )
157
+ queryStringiOS = $ ";body={ Uri . EscapeDataString ( this . subject ) } ";
158
+ returnVal = $ "sms:{ this . number } { queryStringiOS } ";
159
+ break ;
170
160
case SMSEncoding . SMSTO :
171
- return $ "SMSTO:{ this . number } :{ this . subject } ";
172
- default :
173
- return "sms:" ;
161
+ returnVal = $ "SMSTO:{ this . number } :{ this . subject } ";
162
+ break ;
174
163
}
164
+ return returnVal ;
175
165
}
176
166
177
167
public enum SMSEncoding
@@ -214,15 +204,23 @@ public MMS(string number, string subject, MMSEncoding encoding = MMSEncoding.MMS
214
204
215
205
public override string ToString ( )
216
206
{
207
+ var returnVal = string . Empty ;
217
208
switch ( this . encoding )
218
- {
209
+ {
219
210
case MMSEncoding . MMSTO :
220
- return $ "mmsto:{ this . number } ?subject={ System . Uri . EscapeDataString ( this . subject ) } ";
211
+ var queryStringMmsTo = string . Empty ;
212
+ if ( ! string . IsNullOrEmpty ( this . subject ) )
213
+ queryStringMmsTo = $ "?subject={ Uri . EscapeDataString ( this . subject ) } ";
214
+ returnVal = $ "mmsto:{ this . number } { queryStringMmsTo } ";
215
+ break ;
221
216
case MMSEncoding . MMS :
222
- return $ "mms:{ this . number } ?body={ System . Uri . EscapeDataString ( this . subject ) } ";
223
- default :
224
- return "mms:" ;
217
+ var queryStringMms = string . Empty ;
218
+ if ( ! string . IsNullOrEmpty ( this . subject ) )
219
+ queryStringMms = $ "?body={ Uri . EscapeDataString ( this . subject ) } ";
220
+ returnVal = $ "mms:{ this . number } { queryStringMms } ";
221
+ break ;
225
222
}
223
+ return returnVal ;
226
224
}
227
225
228
226
public enum MMSEncoding
0 commit comments