@@ -41,9 +41,9 @@ + (BOOL)requiresMainQueueSetup
41
41
NSString *subject = [RCTConvert NSString: options[@" subject" ]];
42
42
[mail setSubject: subject];
43
43
}
44
-
44
+
45
45
bool *isHTML = NO ;
46
-
46
+
47
47
if (options[@" isHTML" ]){
48
48
isHTML = [options[@" isHTML" ] boolValue ];
49
49
}
@@ -62,70 +62,32 @@ + (BOOL)requiresMainQueueSetup
62
62
NSArray *ccRecipients = [RCTConvert NSArray: options[@" ccRecipients" ]];
63
63
[mail setCcRecipients: ccRecipients];
64
64
}
65
-
65
+
66
66
if (options[@" bccRecipients" ]){
67
67
NSArray *bccRecipients = [RCTConvert NSArray: options[@" bccRecipients" ]];
68
68
[mail setBccRecipients: bccRecipients];
69
69
}
70
70
71
- if (options[@" attachment" ] && options[@" attachment" ][@" path" ] && options[@" attachment" ][@" type" ]){
72
- NSString *attachmentPath = [RCTConvert NSString: options[@" attachment" ][@" path" ]];
73
- NSString *attachmentType = [RCTConvert NSString: options[@" attachment" ][@" type" ]];
74
- NSString *attachmentName = [RCTConvert NSString: options[@" attachment" ][@" name" ]];
71
+ if (options[@" attachment" ]){
72
+ NSArray *attachments = [RCTConvert NSArray: options[@" attachment" ]];
75
73
76
- // Set default filename if not specificed
77
- if (!attachmentName) {
78
- attachmentName = [[attachmentPath lastPathComponent ] stringByDeletingPathExtension ];
79
- }
74
+ for ( NSDictionary *attachment in attachments) {
75
+ NSString *path = [RCTConvert NSString: attachment[ @" path " ]];
76
+ NSString *type = [RCTConvert NSString: attachment[ @" type " ] ];
77
+ NSString *name = [RCTConvert NSString: attachment[ @" name " ]];
80
78
81
- // Get the resource path and read the file using NSData
82
- NSData *fileData = [NSData dataWithContentsOfFile: attachmentPath];
83
-
84
- // Determine the MIME type
85
- NSString *mimeType;
86
-
87
- /*
88
- * Add additional mime types and PR if necessary. Find the list
89
- * of supported formats at http://www.iana.org/assignments/media-types/media-types.xhtml
90
- */
91
- if ([attachmentType isEqualToString: @" jpg" ]) {
92
- mimeType = @" image/jpeg" ;
93
- } else if ([attachmentType isEqualToString: @" png" ]) {
94
- mimeType = @" image/png" ;
95
- } else if ([attachmentType isEqualToString: @" doc" ]) {
96
- mimeType = @" application/msword" ;
97
- } else if ([attachmentType isEqualToString: @" ppt" ]) {
98
- mimeType = @" application/vnd.ms-powerpoint" ;
99
- } else if ([attachmentType isEqualToString: @" html" ]) {
100
- mimeType = @" text/html" ;
101
- } else if ([attachmentType isEqualToString: @" csv" ]) {
102
- mimeType = @" text/csv" ;
103
- } else if ([attachmentType isEqualToString: @" pdf" ]) {
104
- mimeType = @" application/pdf" ;
105
- } else if ([attachmentType isEqualToString: @" vcard" ]) {
106
- mimeType = @" text/vcard" ;
107
- } else if ([attachmentType isEqualToString: @" json" ]) {
108
- mimeType = @" application/json" ;
109
- } else if ([attachmentType isEqualToString: @" zip" ]) {
110
- mimeType = @" application/zip" ;
111
- } else if ([attachmentType isEqualToString: @" text" ]) {
112
- mimeType = @" text/*" ;
113
- } else if ([attachmentType isEqualToString: @" mp3" ]) {
114
- mimeType = @" audio/mpeg" ;
115
- } else if ([attachmentType isEqualToString: @" wav" ]) {
116
- mimeType = @" audio/wav" ;
117
- } else if ([attachmentType isEqualToString: @" aiff" ]) {
118
- mimeType = @" audio/aiff" ;
119
- } else if ([attachmentType isEqualToString: @" flac" ]) {
120
- mimeType = @" audio/flac" ;
121
- } else if ([attachmentType isEqualToString: @" ogg" ]) {
122
- mimeType = @" audio/ogg" ;
123
- } else if ([attachmentType isEqualToString: @" xls" ]) {
124
- mimeType = @" application/vnd.ms-excel" ;
125
- }
79
+ if (name == nil ){
80
+ name = [[path lastPathComponent ] stringByDeletingPathExtension ];
81
+ }
82
+ // Get the resource path and read the file using NSData
83
+ NSData *fileData = [NSData dataWithContentsOfFile: path];
84
+
85
+ // Agnostic to type (ios mailer can handle it as long as there's a file extension)
86
+ NSString *mimeType;
87
+ mimeType = @" application/octet-stream" ;
126
88
127
- // Add attachment
128
- [mail addAttachmentData: fileData mimeType: mimeType fileName: attachmentName];
89
+ [mail addAttachmentData: fileData mimeType: mimeType fileName: name];
90
+ }
129
91
}
130
92
131
93
UIViewController *root = [[[[UIApplication sharedApplication ] delegate ] window ] rootViewController ];
0 commit comments