]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add additional error handling for emailing private links
authorMichael Gapczynski <mtgap@owncloud.com>
Sun, 29 Jul 2012 22:01:43 +0000 (18:01 -0400)
committerMichael Gapczynski <mtgap@owncloud.com>
Mon, 30 Jul 2012 14:07:20 +0000 (10:07 -0400)
apps/files_sharing/ajax/email.php
apps/files_sharing/js/share.js
lib/mail.php

index e931e5f77e6669e108c364242c4cfefa5f0ca0bd..2a81e6f98272b5cd7367f6040fd6400131f0df2e 100644 (file)
@@ -9,4 +9,9 @@ $subject = $user.' shared a '.$type.' with you';
 $link = $_POST['link'];
 $text = $user.' shared the '.$type.' '.$_POST['file'].' with you. It is available for download here: '.$link;
 $fromaddress = OCP\Config::getUserValue($user, 'settings', 'email', 'sharing-noreply@'.OCP\Util::getServerHost());
-OCP\Util::sendMail($_POST['toaddress'], $_POST['toaddress'], $subject, $text, $fromaddress, $user);
+try {
+       OCP\Util::sendMail($_POST['toaddress'], $_POST['toaddress'], $subject, $text, $fromaddress, $user);
+       OCP\JSON::success();
+} catch (Exception $exception) {
+       OCP\JSON::error(array('data' => array('message' => $exception->getMessage())));
+}
index afe31a75d0b5d14f7f1ca394e388af6f4eef9ec0..1ad51873540eb56f1bf0fac9b16c37246d58868d 100644 (file)
@@ -202,11 +202,19 @@ OC.Share={
        emailPrivateLink:function() {
                var link = $('#privateLinkText').val();
                var file = link.substr(link.lastIndexOf('/') + 1).replace(/%20/g, ' ');
-               $.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: $('#email').val(), link: link, file: file } );
-               $('#email').css('font-weight', 'bold');
-               $('#email').animate({ fontWeight: 'normal' }, 2000, function() {
-                       $(this).val('');
-               }).val('Email sent');
+               var email = $('#email').val();
+               if (email != '') {
+                       $.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: email, link: link, file: file }, function(result) {
+                               if (result && result.status == 'success') {
+                                       $('#email').css('font-weight', 'bold');
+                                       $('#email').animate({ fontWeight: 'normal' }, 2000, function() {
+                                               $(this).val('');
+                                       }).val('Email sent');
+                               } else {
+                                       OC.dialogs.alert(result.data.message, 'Error while sharing');
+                               }
+                       });
+               }
        },
        dirname:function(path) {
                return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, '');
index a4e3a39feeb261fb27b221fcc59d990f46ca8144..0ecee0f01c84ff8f87006d7c5e8740c1b6ee5e49 100644 (file)
@@ -83,7 +83,8 @@ class OC_Mail {
                        unset($mailo);
                        OC_Log::write('mail', 'Mail from '.$fromname.' ('.$fromaddress.')'.' to: '.$toname.'('.$toaddress.')'.' subject: '.$subject, OC_Log::DEBUG);
                } catch (Exception $exception) {
-                       OC_Log::write('mail', $exception->getMessage(), OC_Log::DEBUG);
+                       OC_Log::write('mail', $exception->getMessage(), OC_Log::ERROR);
+                       throw($exception);
                }
        }