From e6e3879a9b936d37126da61c61b59826b6e17dd1 Mon Sep 17 00:00:00 2001 From: Mathieu Virbel Date: Fri, 25 May 2012 18:39:48 +0200 Subject: [PATCH] ios: if no mail is configured, prevent crashing and return a status code "cannotsend". --- src/ios/ios.pyx | 10 +++++++--- src/ios/ios_mail.m | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ios/ios.pyx b/src/ios/ios.pyx index 7ed3423..0e00cf5 100644 --- a/src/ios/ios.pyx +++ b/src/ios/ios.pyx @@ -77,7 +77,7 @@ def send_email(subject, text, mimetype=None, filename=None, filename_alias=None, `callback`: func(status) Callback that can be called when the email interface have been removed. A status will be passed as the first argument: "cancelled", - "saved", "sent", "failed", "unknown". + "saved", "sent", "failed", "unknown", "cannotsend". .. note:: @@ -149,9 +149,13 @@ def send_email(subject, text, mimetype=None, filename=None, filename_alias=None, Py_INCREF(callback) - if ios_send_email(j_subject, j_text, j_mimetype, j_filename, - j_filename_alias, _send_email_done, callback) == 0: + ret = ios_send_email(j_subject, j_text, j_mimetype, j_filename, + j_filename_alias, _send_email_done, callback) + if ret == 0: callback('failed') return 0 + elif ret == -1: + callback('cannotsend') + return 0 return 1 diff --git a/src/ios/ios_mail.m b/src/ios/ios_mail.m index 86d3e44..395b8f6 100644 --- a/src/ios/ios_mail.m +++ b/src/ios/ios_mail.m @@ -67,13 +67,17 @@ UIViewController *get_viewcontroller(void) { int ios_send_email(char *subject, char *text, char *mimetype, char *filename, char *filename_alias, ios_send_email_cb callback, void *userdata) { - UIViewController* viewController = get_viewcontroller(); if ( viewController == NULL ) { - printf("ios_send_email: unable to get view controller"); + printf("ios_send_email: unable to get view controller.\n"); return 0; } + if (! [MFMailComposeViewController canSendMail]) { + printf("ios_send_email: no available mail provider configured.\n"); + return -1; + } + MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init]; InAppEmailViewController *inAppVc = [[InAppEmailViewController alloc] init]; inAppVc.callback = callback;