5
// Created by Nathan Weiner on 6/17/10.
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to deal
10
// in the Software without restriction, including without limitation the rights
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
15
// The above copyright notice and this permission notice shall be included in
16
// all copies or substantial portions of the Software.
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
#import "SHKConfiguration.h"
32
@implementation MFMailComposeViewController (SHK)
34
- (void)SHKviewDidDisappear:(BOOL)animated
36
[super viewDidDisappear:animated];
38
// Remove the SHK view wrapper from the window (but only if the view doesn't have another modal over it)
39
if (self.modalViewController == nil)
40
[[SHK currentHelper] viewWasDismissed];
47
@implementation SHKMail
50
#pragma mark Configuration : Service Defination
52
+ (NSString *)sharerTitle
54
return SHKLocalizedString(@"Email");
77
+ (BOOL)shareRequiresInternetConnection
82
+ (BOOL)requiresAuthentication
89
#pragma mark Configuration : Dynamic Enable
93
return [MFMailComposeViewController canSendMail];
96
- (BOOL)shouldAutoShare
104
#pragma mark Share API Methods
110
if (![self validateItem])
113
return [self sendMail]; // Put the actual sending action in another method to make subclassing SHKMail easier
118
MFMailComposeViewController *mailController = [[[MFMailComposeViewController alloc] init] autorelease];
119
if (!mailController) {
120
// e.g. no mail account registered (will show alert)
121
[[SHK currentHelper] hideCurrentViewControllerAnimated:YES];
125
[self retain]; //must retain, because mailController does not retain its delegates. Released in callback.
126
mailController.mailComposeDelegate = self;
127
mailController.navigationBar.tintColor = SHKCONFIG_WITH_ARGUMENT(barTintForView:,mailController);
129
NSString *body = item.text;
130
BOOL isHTML = self.item.isMailHTML;
131
NSString *separator = (isHTML ? @"<br/><br/>" : @"\n\n");
139
NSString *urlStr = [item.URL.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
142
body = [body stringByAppendingFormat:@"%@%@", separator, urlStr];
149
NSString *attachedStr = SHKLocalizedString(@"Attached: %@", item.title ? item.title : item.filename);
152
body = [body stringByAppendingFormat:@"%@%@", separator, attachedStr];
162
if (self.item.mailShareWithAppSignature)
164
body = [body stringByAppendingString:separator];
165
body = [body stringByAppendingString:SHKLocalizedString(@"Sent from %@", SHKCONFIG(appName))];
170
[mailController addAttachmentData:item.data mimeType:item.mimeType fileName:item.filename];
172
NSArray *toRecipients = self.item.mailToRecipients;
174
[mailController setToRecipients:toRecipients];
178
CGFloat jpgQuality = self.item.mailJPGQuality;
179
[mailController addAttachmentData:UIImageJPEGRepresentation(item.image, jpgQuality) mimeType:@"image/jpeg" fileName:@"Image.jpg"];
182
[mailController setSubject:item.title];
183
[mailController setMessageBody:body isHTML:isHTML];
185
[[SHK currentHelper] showViewController:mailController];
190
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
192
[[SHK currentHelper] hideCurrentViewControllerAnimated:YES];
196
case MFMailComposeResultSent:
197
[self sendDidFinish];
199
case MFMailComposeResultSaved:
200
[self sendDidFinish];
202
case MFMailComposeResultCancelled:
203
[self sendDidCancel];
205
case MFMailComposeResultFailed:
206
[self sendDidFailWithError:nil];