Skip to content

Commit

Permalink
Allow the activesync_mail_presend hook to return new MIME data.
Browse files Browse the repository at this point in the history
Since clients are so fussy about error messages, this provides the
option for just removing the offending attachments, replacing them with
a text part explaining what happened, and sending the message.
  • Loading branch information
mrubinsk committed Sep 4, 2014
1 parent 1a3456e commit 9dc07f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions framework/Core/lib/Horde/Core/ActiveSync/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ protected function _callPreSendHook()
if (!$result = $hooks->callHook('activesync_email_presend', 'horde', array($params))) {
throw new Horde_ActiveSync_Exception('There was an issue running the activesync_email_presend hook.');
}
if ($result instanceof Horde_ActiveSync_Mime) {
$this->_raw->replaceMime($result->base);
}
} catch (Horde_Exception_HookNotSet $e) {
}
}
Expand Down
35 changes: 24 additions & 11 deletions horde/config/hooks.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,8 @@
* failed and the message will NOT be sent.
*
* [boolean] - True if the validation passes, false for any other failure.
*
* [Horde_ActiveSync_Mime] - Replaces the outgoing message with the contents
* of this MIME object.
*
* TODO: groupldap, share_add, share_modify, share_remove
*
Expand Down Expand Up @@ -1114,7 +1115,7 @@ class Horde_Hooks
* - reply: (boolean) If true, this is a SMART_REPLY.
* - forward: (boolean) If true, this is a SMART_FORWARD
*
* @return boolean
* @return mixed boolean|Horde_ActiveSync_Mime
*/
// public function activesync_email_presend(array $params)
// {
Expand All @@ -1131,16 +1132,28 @@ class Horde_Hooks
// file_put_contents($tmp, $stream);
// $clamscan = '/path/to/clamdscan';
// exec($clamscan . ' --silent ' . escapeshellarg($tmp), $output, $return_var);
// switch ($return_var) {
// case 1:
// // Virus found.
// throw new Horde_ActiveSync_Exception_EmailFatalFailure('Virus found. Attachment will not be added to the compose message.');
// switch ($return_var) {
// case 1:
// // Virus found.
// // We can throw an exception to prevent the email from being
// // sent altogether, or we can return a Horde_ActiveSync_Mime
// // object with the offending attachment(s) removed.
// //throw new Horde_ActiveSync_Exception_EmailFatalFailure('Virus found. Attachment will not be added to the compose message.');
//
// case 2:
// return false;
// }
// }
// }
// $updated = true;
// $part = new Horde_Mime_Part();
// $part->setType('text/plain');
// $part->setContents(sprintf(
// _("An attachment named %s was removed by Horde_ActiveSync due to a virus being detected."),
// $mime->getPart($id)->getName(true))
// );
// $mime->removePart($id);
// $mime->addPart($part);
// break;
// case 2:
// return false;
// }
// }
//
// return true;
// }
Expand Down

0 comments on commit 9dc07f0

Please sign in to comment.