1+ using System ;
2+ using System . Collections . Generic ;
3+ using System . Linq ;
4+
5+ namespace ExploitablePath
6+ {
7+ public class EmailMessage
8+ {
9+ public string From { get ; }
10+
11+ public string [ ] To { get ; }
12+
13+ public string [ ] Cc { get ; }
14+
15+ public string [ ] Bcc { get ; }
16+
17+ public string [ ] ReplyTo { get ; }
18+
19+ public string Subject { get ; }
20+
21+ public string Body { get ; }
22+
23+ public bool IsBodyHtml { get ; }
24+
25+ public IList < EmailMessageAttachment > Attachments { get ; }
26+
27+ public bool HasAttachments => Attachments != null && Attachments . Count > 0 ;
28+
29+ public EmailMessage ( string from , string to , string subject , string body , bool isBodyHtml )
30+ : this ( from , new [ ] { to } , null , null , null , subject , body , isBodyHtml , null )
31+ {
32+ }
33+
34+ public EmailMessage ( string from , string [ ] to , string [ ] cc , string [ ] bcc , string [ ] replyTo , string subject , string body , bool isBodyHtml , IEnumerable < EmailMessageAttachment > attachments )
35+ {
36+ ArgumentIsNotNullOrEmpty ( to , nameof ( to ) ) ;
37+ ArgumentIsNotNullOrEmpty ( subject , nameof ( subject ) ) ;
38+ ArgumentIsNotNullOrEmpty ( body , nameof ( body ) ) ;
39+
40+ From = from ;
41+ To = to ;
42+ Cc = cc ;
43+ Bcc = bcc ;
44+ ReplyTo = replyTo ;
45+ Subject = subject ;
46+ Body = body ;
47+ IsBodyHtml = isBodyHtml ;
48+ Attachments = attachments ? . ToList ( ) ;
49+ }
50+
51+ private static void ArgumentIsNotNullOrEmpty ( string arg , string argName )
52+ {
53+ if ( arg == null )
54+ {
55+ throw new ArgumentNullException ( argName ) ;
56+ }
57+
58+ if ( arg . Length == 0 )
59+ {
60+ throw new ArgumentException ( "Value cannot be empty." , argName ) ;
61+ }
62+ }
63+
64+ private static void ArgumentIsNotNullOrEmpty ( string [ ] arg , string argName )
65+ {
66+ if ( arg == null )
67+ {
68+ throw new ArgumentNullException ( argName ) ;
69+ }
70+
71+ if ( arg . Length == 0 )
72+ {
73+ throw new ArgumentException ( "Value cannot be an empty array." , argName ) ;
74+ }
75+
76+ if ( arg . Any ( x => x is not null && x . Length > 0 ) == false )
77+ {
78+ throw new ArgumentException ( "Value cannot be an array containing only null or empty elements." , argName ) ;
79+ }
80+ }
81+ }
82+ }
0 commit comments