/** * Actually carry out the action. */ public function doAction($form_params, $form_data, $fields) { global $conf; $mail = new Horde_Mime_Mail(); $mail->addHeader('From', $form_params['from']); $mail->addHeader('Subject', $form_params['subject']); $mail->addHeader('To', $form_params['to']); if (!empty($form_params['cc'])) { $mail->addHeader('Cc', $form_params['cc']); } if (!empty($form_params['bcc'])) { $mail->addHeader('Bcc', $form_params['bcc']); } $body = ''; foreach ($fields as $field) { $value = array_shift($form_data); switch ($field['field_type']) { case 'file': case 'image': if (!empty($value['file'])) { $mail->addAttachment($value['file'], $value['name'], $value['type']); } break; default: $body .= $field['field_label'] . ': ' . $this->_formatFormData($value) . "\n"; break; } } $mail->setBody($body); return $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); }
/** * Push content to the recipient. * * @param Horde_Push $content The content element. * @param array $options Additional options. * * @return NULL */ public function push(Horde_Push $content, $options = array()) { $contents = $content->getContent(); $types = $content->getMimeTypes(); $mail = new Horde_Mime_Mail(); // @todo Append references if (isset($types['text/plain'])) { $mail->setBody($content->getStringContent($types['text/plain'][0])); unset($contents[$types['text/plain'][0]]); } if (isset($types['text/html'])) { $mail->setHtmlBody($content->getStringContent($types['text/html'][0]), 'UTF-8', !isset($types['text/plain'])); unset($contents[$types['text/html'][0]]); } foreach ($contents as $part) { $mail->addPart($part['mime_type'], $part['content'], 'UTF-8'); } $mail->addRecipients(explode(',', $this->getAcl())); $mail->addHeader('subject', $content->getSummary()); if (!empty($this->_params['from'])) { $mail->addHeader('from', $this->_params['from']); } $mail->addHeader('to', $this->getAcl()); if (!empty($options['pretend'])) { $mock = new Horde_Mail_Transport_Mock(); $mail->send($mock); return sprintf("Would push mail \n\n%s\n\n%s\n to %s.", $mock->sentMessages[0]['header_text'], $mock->sentMessages[0]['body'], $this->getAcl()); } $mail->send($this->_mail); return sprintf('Pushed mail to %s.', $this->getAcl()); }
/** * Notify user * * @param mixed $user User or array of users to send notification to * @param string $subject Subject of message * @param string $body Body of message * @param array $attachments Attached files * * @return true on succes, PEAR_Error on failure */ public function notify($user, $subject, $body, $attachments = array()) { if (empty($user)) { return true; } $mail = new Horde_Mime_Mail(array('body' => $body, 'Subject' => $subject, 'From' => $this->_params['from_addr'], 'User-Agent' => 'Folks ' . $GLOBALS['registry']->getVersion(), 'X-Originating-IP' => $_SERVER['REMOTE_ADDR'], 'X-Remote-Browser' => $_SERVER['HTTP_USER_AGENT'])); foreach ($attachments as $file) { if (file_exists($file)) { $mail->addAttachment($file, null, null, 'UTF-8'); } } if (is_string($user)) { $user = array($user); } foreach ($user as $recipent) { $to = $this->_getUserFromAddr($recipent); if (empty($to)) { continue; } $mail->addHeader('To', $to, true); $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } return true; }
/** * Sends email notifications that a task has been added, edited, or * deleted to users that want such notifications. * * @param string $action The event action. One of "add", "edit", or * "delete". * @param Nag_Task $task The changed task. * @param Nag_Task $old_task The original task if $action is "edit". * * @throws Nag_Exception */ public static function sendNotification($action, $task, $old_task = null) { if (!in_array($action, array('add', 'edit', 'delete'))) { throw new Nag_Exception('Unknown event action: ' . $action); } try { $share = $GLOBALS['nag_shares']->getShare($task->tasklist); } catch (Horde_Share_Exception $e) { Horde::log($e->getMessage(), 'ERR'); throw new Nag_Exception($e); } $groups = $GLOBALS['injector']->getInstance('Horde_Group'); $recipients = array(); $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); $from = $identity->getDefaultFromAddress(true); $owner = $share->get('owner'); if (strlen($owner)) { $recipients[$owner] = self::_notificationPref($owner, 'owner'); } foreach ($share->listUsers(Horde_Perms::READ) as $user) { if (empty($recipients[$user])) { $recipients[$user] = self::_notificationPref($user, 'read', $task->tasklist); } } foreach ($share->listGroups(Horde_Perms::READ) as $group) { try { $group_users = $groups->listUsers($group); } catch (Horde_Group_Exception $e) { Horde::log($e, 'ERR'); continue; } foreach ($group_users as $user) { if (empty($recipients[$user])) { $recipients[$user] = self::_notificationPref($user, 'read', $task->tasklist); } } } $addresses = array(); foreach ($recipients as $user => $vals) { if (!$vals) { continue; } $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user); $email = $identity->getValue('from_addr'); if (strpos($email, '@') === false) { continue; } if (!isset($addresses[$vals['lang']][$vals['tf']][$vals['df']])) { $addresses[$vals['lang']][$vals['tf']][$vals['df']] = array(); } $tmp = new Horde_Mail_Rfc822_Address($email); $tmp->personal = $identity->getValue('fullname'); $addresses[$vals['lang']][$vals['tf']][$vals['df']][] = strval($tmp); } if (!$addresses) { return; } $mail = new Horde_Mime_Mail(array('User-Agent' => 'Nag ' . $GLOBALS['registry']->getVersion(), 'Precedence' => 'bulk', 'Auto-Submitted' => 'auto-generated', 'From' => $from)); foreach ($addresses as $lang => $twentyFour) { $GLOBALS['registry']->setLanguageEnvironment($lang); $view_link = Horde::url('view.php', true)->add(array('tasklist' => $task->tasklist, 'task' => $task->id))->setRaw(true); switch ($action) { case 'add': $subject = _("Task added:"); $notification_message = _("You requested to be notified when tasks are added to your task lists.") . "\n\n" . ($task->due ? _("The task \"%s\" has been added to task list \"%s\", with a due date of: %s.") : _("The task \"%s\" has been added to task list \"%s\".")) . "\n" . str_replace('%', '%%', $view_link); break; case 'edit': $subject = _("Task modified:"); $notification_message = _("You requested to be notified when tasks are edited on your task lists.") . "\n\n" . _("The task \"%s\" has been edited on task list \"%s\".") . "\n" . str_replace('%', '%%', $view_link) . "\n\n" . _("Changes made for this task:"); if ($old_task->name != $task->name) { $notification_message .= "\n - " . sprintf(_("Changed name from \"%s\" to \"%s\""), $old_task->name, $task->name); } if ($old_task->tasklist != $task->tasklist) { $old_share = $GLOBALS['nag_shares']->getShare($old_task->tasklist); $notification_message .= "\n - " . sprintf(_("Changed task list from \"%s\" to \"%s\""), Nag::getLabel($old_share), Nag::getLabel($share)); } if ($old_task->parent_id != $task->parent_id) { $old_parent = $old_task->getParent(); try { $parent = $task->getParent(); $notification_message .= "\n - " . sprintf(_("Changed parent task from \"%s\" to \"%s\""), $old_parent ? $old_parent->name : _("no parent"), $parent ? $parent->name : _("no parent")); } catch (Nag_Exception $e) { } } if ($old_task->assignee != $task->assignee) { $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($old_task->assignee); $old_name = $identity->getValue('fullname'); if (!strlen($old_name)) { $old_name = $old_task->assignee; } $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($task->assignee); $new_name = $identity->getValue('fullname'); if (!strlen($new_name)) { $new_name = $new_task->assignee; } $notification_message .= "\n - " . sprintf(_("Changed assignee from \"%s\" to \"%s\""), $old_name, $new_name); } if ($old_task->private != $task->private) { $notification_message .= "\n - " . ($task->private ? _("Turned privacy on") : _("Turned privacy off")); } if ($old_task->due != $task->due) { $notification_message .= "\n - " . sprintf(_("Changed due date from %s to %s"), $old_task->due ? self::formatDate($old_task->due) : _("no due date"), $task->due ? self::formatDate($task->due) : _("no due date")); } if ($old_task->start != $task->start) { $notification_message .= "\n - " . sprintf(_("Changed start date from %s to %s"), $old_task->start ? self::formatDate($old_task->start) : _("no start date"), $task->start ? self::formatDate($task->start) : _("no start date")); } if ($old_task->alarm != $task->alarm) { $notification_message .= "\n - " . sprintf(_("Changed alarm from %s to %s"), self::formatAlarm($old_task->alarm), self::formatAlarm($task->alarm)); } if ($old_task->priority != $task->priority) { $notification_message .= "\n - " . sprintf(_("Changed priority from %s to %s"), $old_task->priority, $task->priority); } if ($old_task->estimate != $task->estimate) { $notification_message .= "\n - " . sprintf(_("Changed estimate from %s to %s"), $old_task->estimate, $task->estimate); } if ($old_task->completed != $task->completed) { $notification_message .= "\n - " . sprintf(_("Changed completion from %s to %s"), $old_task->completed ? _("completed") : _("not completed"), $task->completed ? _("completed") : _("not completed")); } if ($old_task->desc != $task->desc) { $notification_message .= "\n - " . _("Changed description"); } break; case 'delete': $subject = _("Task deleted:"); $notification_message = _("You requested to be notified when tasks are deleted from your task lists.") . "\n\n" . _("The task \"%s\" has been deleted from task list \"%s\"."); break; } $mail->addHeader('Subject', $subject . ' ' . $task->name); foreach ($twentyFour as $tf => $dateFormat) { foreach ($dateFormat as $df => $df_recipients) { $message = sprintf($notification_message, $task->name, Nag::getLabel($share), $task->due ? strftime($df, $task->due) . ' ' . date($tf ? 'H:i' : 'h:ia', $task->due) : ''); if (strlen(trim($task->desc))) { $message .= "\n\n" . _("Task description:") . "\n\n" . $task->desc; } $mail->setBody($message); $mail->clearRecipients(); $mail->addRecipients($df_recipients); Horde::log(sprintf('Sending event notifications for %s to %s', $task->name, implode(', ', $df_recipients)), 'INFO'); $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } } } }
/** * Sends email notifications to a list of recipients. * * We do some ugly work in here to make sure that no one gets comments * mailed to them that they shouldn't see (because of group permissions). * * @param array $opts Option hash with notification information. * Possible values: * - ticket: (Whups_Ticket) A ticket. If not set, * this is assumed to be a reminder * message. * - recipients: (array|string) The list of recipients, * with user names as keys and user roles * as values. * - subject: (string) The email subject. * - view: (Horde_View) The view object for the * message text. * - template: (string) The template file for the * message text. * - from: (string) The email sender. * - new: (boolean, optional) Whether the passed * ticket was just created. */ public function mail(array $opts) { global $conf, $registry, $prefs; $opts = array_merge(array('ticket' => false, 'new' => false), $opts); /* Set up recipients and message headers. */ $mail = new Horde_Mime_Mail(array('X-Whups-Generated' => 1, 'User-Agent' => 'Whups ' . $registry->getVersion(), 'Precedence' => 'bulk', 'Auto-Submitted' => $opts['ticket'] ? 'auto-replied' : 'auto-generated')); $mail_always = null; if ($opts['ticket'] && !empty($conf['mail']['always_copy'])) { $mail_always = $conf['mail']['always_copy']; if (strpos($mail_always, '<@>') !== false) { try { $mail_always = str_replace('<@>', $opts['ticket']->get('queue_name'), $mail_always); } catch (Whups_Exception $e) { $mail_always = null; } } if ($mail_always && !isset($opts['recipients'][$mail_always])) { $opts['recipients'][$mail_always] = 'always'; } } if ($opts['ticket'] && ($queue = $this->getQueue($opts['ticket']->get('queue'))) && !empty($queue['email'])) { $mail->addHeader('From', $queue['email']); } elseif (!empty($conf['mail']['from_addr'])) { $mail->addHeader('From', $conf['mail']['from_addr']); } else { $mail->addHeader('From', Whups::formatUser($opts['from'])); } if (!empty($conf['mail']['return_path'])) { $mail->addHeader('Return-Path', $conf['mail']['return_path']); } if ($opts['ticket']) { $opts['subject'] = '[' . $registry->get('name') . ' #' . $opts['ticket']->getId() . '] ' . $opts['subject']; } $mail->addHeader('Subject', $opts['subject']); /* Get our array of comments, sorted in the appropriate order. */ if ($opts['ticket']) { $comments = $this->getHistory($opts['ticket']->getId()); if ($conf['mail']['commenthistory'] == 'new' && count($comments)) { $comments = array_pop($comments); $comments = array($comments); } elseif ($conf['mail']['commenthistory'] != 'chronological') { $comments = array_reverse($comments); } } else { $comments = array(); } /* Don't notify any email address more than once. */ $seen_email_addresses = array(); /* Get VFS handle for attachments. */ if ($opts['ticket']) { $vfs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create(); try { $attachments = Whups::getAttachments($opts['ticket']->getId()); } catch (Whups_Exception $e) { $attachments = array(); Horde::log($e); } } $from = Whups::getUserAttributes($opts['from']); foreach ($opts['recipients'] as $user => $role) { /* Make sure to check permissions as a guest for the 'always_copy' * address, and as the recipient for all others. */ $to = $full_name = ''; if (!empty($mail_always) && $user == $mail_always) { $details = null; $mycomments = Whups::permissionsFilter($comments, 'comment', Horde_Perms::READ, ''); $to = $mail_always; } else { $details = Whups::getUserAttributes($user); if (!empty($details['email'])) { $to = Whups::formatUser($details); $mycomments = Whups::permissionsFilter($comments, 'comment', Horde_Perms::READ, $details['user']); } $full_name = $details['name']; } /* We may have no recipients due to users excluding themselves * from self notifies. */ if (!$to) { continue; } if ($details && $details['type'] == 'user') { $user_prefs = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Prefs')->create('whups', array('user' => $details['user'])); if (($details['user'] == $registry->getAuth() || !$registry->getAuth()) && $from['type'] == 'user' && $details['user'] == $from['user'] && $user_prefs->getValue('email_others_only')) { continue; } } if ($opts['ticket']) { /* Add attachments. */ $attachmentAdded = false; if (empty($GLOBALS['conf']['mail']['link_attach'])) { /* We need to remove all attachments because the attachment * list is potentially limited by permissions. */ $mail->clearParts(); foreach ($mycomments as $comment) { foreach ($comment['changes'] as $change) { if ($change['type'] != 'attachment') { continue; } foreach ($attachments as $attachment) { if ($attachment['name'] != $change['value']) { continue; } if (!isset($attachment['part'])) { $attachment['part'] = new Horde_Mime_Part(); $attachment['part']->setType(Horde_Mime_Magic::filenameToMime($change['value'], false)); $attachment['part']->setDisposition('attachment'); $attachment['part']->setContents($vfs->read(Whups::VFS_ATTACH_PATH . '/' . $opts['ticket']->getId(), $change['value'])); $attachment['part']->setName($change['value']); } $mail->addMimePart($attachment['part']); $attachmentAdded = true; break; } } } } $formattedComment = $this->formatComments($mycomments, $opts['ticket']->getId()); if (!$attachmentAdded && !strlen(trim($formattedComment)) && $details && $details['type'] == 'user' && $user_prefs->getValue('email_comments_only')) { continue; } $opts['view']->comment = $formattedComment; } $addr_ob = new Horde_Mail_Rfc822_Address($to); if ($addr_ob->valid) { $bare_address = $addr_ob->bare_address; if (!empty($seen_email_addresses[$bare_address])) { continue; } $seen_email_addresses[$bare_address] = true; if (empty($full_name) && !is_null($addr_ob->personal)) { $full_name = $addr_ob->personal; } } // Use email address as fallback. if (empty($full_name)) { $full_name = $to; } $opts['view']->full_name = $full_name; $opts['view']->role = $role; $body = $opts['view']->render($opts['template']); if (!strlen(trim($body))) { continue; } $mail->setBody($body); $mail->addHeaderOb(Horde_Mime_Headers_MessageId::create()); if ($opts['ticket']) { $message_id = '<whups-' . $opts['ticket']->getId() . '-' . md5($user) . '@' . $conf['server']['name'] . '>'; if ($opts['new']) { $mail->addHeader('Message-ID', $message_id); } else { $mail->addHeader('In-Reply-To', $message_id); $mail->addHeader('References', $message_id); } } $mail->clearRecipients(); $mail->addHeader('To', $to); try { $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'), true); $entry = sprintf('%s Message sent to %s from "%s"', $_SERVER['REMOTE_ADDR'], $to, $GLOBALS['registry']->getAuth()); Horde::log($entry, 'INFO'); } catch (Horde_Mime_Exception $e) { Horde::log($e, 'ERR'); } } }
/** * Mails a notification message after encoding the headers and adding the * standard username/time line. * * @param string $message The message text to send out. * @param array $headers Additional headers to add to the email. */ public static function mail($message, $headers = array()) { global $conf, $registry; /* Make sure there's a place configured to send the email. */ if (empty($conf['wicked']['notify_address'])) { return; } if ($GLOBALS['registry']->getAuth()) { $prefix = $GLOBALS['registry']->getAuth(); } else { $prefix = 'guest [' . $_SERVER['REMOTE_ADDR'] . ']'; } $message = $prefix . ' ' . date('r') . "\n\n" . $message; /* In case we don't get a user's email address to send the * notification from, what should we fall back to for the From: * header? */ $default_from_addr = !empty($conf['wicked']['guest_address']) ? $conf['wicked']['guest_address'] : $conf['wicked']['notify_address']; if ($GLOBALS['registry']->getAuth()) { $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); $from = $identity->getValue('fullname'); if (empty($from)) { $from = $registry->get('name'); } $from_addr = $identity->getValue('from_addr'); if (empty($from_addr)) { $from_addr = $default_from_addr; } } else { $from = $registry->get('name') . ' Guest'; $from_addr = $default_from_addr; } $mail = new Horde_Mime_Mail(array('body' => $message, 'To' => $conf['wicked']['notify_address'], 'From' => $from . '<' . $from_addr . '>', 'User-Agent' => 'Wicked ' . $GLOBALS['registry']->getVersion(), 'Precedence' => 'bulk', 'Auto-Submitted' => 'auto-replied')); foreach (array_keys($headers) as $hkey) { $mail->addHeader($hkey, $headers[$hkey]); } try { $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } catch (Horde_Mime_Exception $e) { $GLOBALS['notification']->push($e); } }
/** * Send new posts to a distribution email address for a wider audience * * @param int $message_id Identifier of message to be distributed * * @throws Horde_Mime_Exception */ function distribute($message_id) { global $conf; $storage = $GLOBALS['injector']->getInstance('Agora_Factory_Driver')->create(); $message = $storage->getMessage($message_id); $forum = $storage->getForum($message['forum_id']); if (empty($forum['forum_distribution_address'])) { return; } $mail = new Horde_Mime_Mail(); $mail->addHeader('X-Horde-Agora-Post', $message_id); $mail->addHeader('From', strpos($message['message_author'], '@') ? $message['message_author'] : $forum['forum_distribution_address']); $mail->addHeader('Subject', '[' . $forum['forum_name'] . '] ' . $message['message_subject']); $mail->addHeader('To', $forum['forum_distribution_address']); $mail->setBody($message['body']); $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); }
/** * Reads a submitted permissions form and updates the share permissions. * * @param Horde_Share_Object|Kronolith_Resource_Base $share The share to update. * * @return array A list of error messages. * @throws Kronolith_Exception */ public static function readPermsForm($share) { $auth = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Auth')->create(); $perm = $share->getPermission(); $errors = array(); if ($GLOBALS['conf']['share']['notify']) { $identity = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create(); $mail = new Horde_Mime_Mail(array('From' => $identity->getDefaultFromAddress(true), 'User-Agent' => 'Kronolith ' . $GLOBALS['registry']->getVersion())); $image = self::getImagePart('big_share.png'); $view = new Horde_View(array('templatePath' => KRONOLITH_TEMPLATES . '/share')); new Horde_View_Helper_Text($view); $view->identity = $identity; $view->calendar = $share->get('name'); $view->imageId = $image->getContentId(); } // Process owner and owner permissions. if (!$share instanceof Kronolith_Resource_Base) { $old_owner = $share->get('owner'); $new_owner_backend = Horde_Util::getFormData('owner_select', Horde_Util::getFormData('owner_input', $old_owner)); $new_owner = $GLOBALS['registry']->convertUsername($new_owner_backend, true); // Only set new owner if this isn't a system calendar, and the // owner actually changed and the new owner is set at all. if (!is_null($old_owner) && $old_owner !== $new_owner && !empty($new_owner)) { if ($old_owner != $GLOBALS['registry']->getAuth() && !$GLOBALS['registry']->isAdmin()) { $errors[] = _("Only the owner or system administrator may change ownership or owner permissions for a share"); } elseif ($auth->hasCapability('list') && !$auth->exists($new_owner_backend)) { $errors[] = sprintf(_("The user \"%s\" does not exist."), $new_owner_backend); } else { $share->set('owner', $new_owner); $share->save(); if ($GLOBALS['conf']['share']['notify']) { $view->ownerChange = true; $multipart = self::buildMimeMessage($view, 'notification', $image); $to = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($new_owner)->getDefaultFromAddress(true); $mail->addHeader('Subject', _("Ownership assignment")); $mail->addHeader('To', $to); $mail->setBasePart($multipart); $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); $view->ownerChange = false; } } } } if ($GLOBALS['conf']['share']['notify']) { if ($GLOBALS['conf']['share']['hidden']) { $view->subscribe = Horde::url('calendars/subscribe.php', true)->add('calendar', $share->getName()); } $multipart = self::buildMimeMessage($view, 'notification', $image); } if ($GLOBALS['registry']->isAdmin() || !empty($GLOBALS['conf']['share']['world'])) { // Process default permissions. if (Horde_Util::getFormData('default_show')) { $perm->addDefaultPermission(Horde_Perms::SHOW, false); } else { $perm->removeDefaultPermission(Horde_Perms::SHOW, false); } if (Horde_Util::getFormData('default_read')) { $perm->addDefaultPermission(Horde_Perms::READ, false); } else { $perm->removeDefaultPermission(Horde_Perms::READ, false); } if (Horde_Util::getFormData('default_edit')) { $perm->addDefaultPermission(Horde_Perms::EDIT, false); } else { $perm->removeDefaultPermission(Horde_Perms::EDIT, false); } if (Horde_Util::getFormData('default_delete')) { $perm->addDefaultPermission(Horde_Perms::DELETE, false); } else { $perm->removeDefaultPermission(Horde_Perms::DELETE, false); } if (Horde_Util::getFormData('default_delegate')) { $perm->addDefaultPermission(self::PERMS_DELEGATE, false); } else { $perm->removeDefaultPermission(self::PERMS_DELEGATE, false); } // Process guest permissions. if (Horde_Util::getFormData('guest_show')) { $perm->addGuestPermission(Horde_Perms::SHOW, false); } else { $perm->removeGuestPermission(Horde_Perms::SHOW, false); } if (Horde_Util::getFormData('guest_read')) { $perm->addGuestPermission(Horde_Perms::READ, false); } else { $perm->removeGuestPermission(Horde_Perms::READ, false); } if (Horde_Util::getFormData('guest_edit')) { $perm->addGuestPermission(Horde_Perms::EDIT, false); } else { $perm->removeGuestPermission(Horde_Perms::EDIT, false); } if (Horde_Util::getFormData('guest_delete')) { $perm->addGuestPermission(Horde_Perms::DELETE, false); } else { $perm->removeGuestPermission(Horde_Perms::DELETE, false); } if (Horde_Util::getFormData('guest_delegate')) { $perm->addGuestPermission(self::PERMS_DELEGATE, false); } else { $perm->removeGuestPermission(self::PERMS_DELEGATE, false); } } // Process creator permissions. if (Horde_Util::getFormData('creator_show')) { $perm->addCreatorPermission(Horde_Perms::SHOW, false); } else { $perm->removeCreatorPermission(Horde_Perms::SHOW, false); } if (Horde_Util::getFormData('creator_read')) { $perm->addCreatorPermission(Horde_Perms::READ, false); } else { $perm->removeCreatorPermission(Horde_Perms::READ, false); } if (Horde_Util::getFormData('creator_edit')) { $perm->addCreatorPermission(Horde_Perms::EDIT, false); } else { $perm->removeCreatorPermission(Horde_Perms::EDIT, false); } if (Horde_Util::getFormData('creator_delete')) { $perm->addCreatorPermission(Horde_Perms::DELETE, false); } else { $perm->removeCreatorPermission(Horde_Perms::DELETE, false); } if (Horde_Util::getFormData('creator_delegate')) { $perm->addCreatorPermission(self::PERMS_DELEGATE, false); } else { $perm->removeCreatorPermission(self::PERMS_DELEGATE, false); } // Process user permissions. $u_names = Horde_Util::getFormData('u_names'); $u_show = Horde_Util::getFormData('u_show'); $u_read = Horde_Util::getFormData('u_read'); $u_edit = Horde_Util::getFormData('u_edit'); $u_delete = Horde_Util::getFormData('u_delete'); $u_delegate = Horde_Util::getFormData('u_delegate'); $current = $perm->getUserPermissions(); if ($GLOBALS['conf']['share']['notify']) { $mail->addHeader('Subject', _("Access permissions")); } $perm->removeUserPermission(null, null, false); foreach ($u_names as $key => $user_backend) { // Apply backend hooks $user = $GLOBALS['registry']->convertUsername($user_backend, true); // If the user is empty, or we've already set permissions // via the owner_ options, don't do anything here. if (empty($user) || $user == $new_owner) { continue; } if ($auth->hasCapability('list') && !$auth->exists($user_backend)) { $errors[] = sprintf(_("The user \"%s\" does not exist."), $user_backend); continue; } $has_perms = false; if (!empty($u_show[$key])) { $perm->addUserPermission($user, Horde_Perms::SHOW, false); $has_perms = true; } if (!empty($u_read[$key])) { $perm->addUserPermission($user, Horde_Perms::READ, false); $has_perms = true; } if (!empty($u_edit[$key])) { $perm->addUserPermission($user, Horde_Perms::EDIT, false); $has_perms = true; } if (!empty($u_delete[$key])) { $perm->addUserPermission($user, Horde_Perms::DELETE, false); $has_perms = true; } if (!empty($u_delegate[$key])) { $perm->addUserPermission($user, self::PERMS_DELEGATE, false); $has_perms = true; } // Notify users that have been added. if ($GLOBALS['conf']['share']['notify'] && !isset($current[$user]) && $has_perms) { $to = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($user)->getDefaultFromAddress(true); $mail->addHeader('To', $to); $mail->setBasePart($multipart); $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } } // Process group permissions. $g_names = Horde_Util::getFormData('g_names'); $g_show = Horde_Util::getFormData('g_show'); $g_read = Horde_Util::getFormData('g_read'); $g_edit = Horde_Util::getFormData('g_edit'); $g_delete = Horde_Util::getFormData('g_delete'); $g_delegate = Horde_Util::getFormData('g_delegate'); $current = $perm->getGroupPermissions(); $perm->removeGroupPermission(null, null, false); foreach ($g_names as $key => $group) { if (empty($group)) { continue; } $has_perms = false; if (!empty($g_show[$key])) { $perm->addGroupPermission($group, Horde_Perms::SHOW, false); $has_perms = true; } if (!empty($g_read[$key])) { $perm->addGroupPermission($group, Horde_Perms::READ, false); $has_perms = true; } if (!empty($g_edit[$key])) { $perm->addGroupPermission($group, Horde_Perms::EDIT, false); $has_perms = true; } if (!empty($g_delete[$key])) { $perm->addGroupPermission($group, Horde_Perms::DELETE, false); $has_perms = true; } if (!empty($g_delegate[$key])) { $perm->addGroupPermission($group, self::PERMS_DELEGATE, false); $has_perms = true; } // Notify users that have been added. if ($GLOBALS['conf']['share']['notify'] && !isset($current[$group]) && $has_perms) { $groupOb = $GLOBALS['injector']->getInstance('Horde_Group')->getData($group); if (!empty($groupOb['email'])) { $mail->addHeader('To', $groupOb['name'] . ' <' . $groupOb['email'] . '>'); $mail->setBasePart($multipart); $mail->send($GLOBALS['injector']->getInstance('Horde_Mail')); } } } try { $share->setPermission($perm); } catch (Horde_Share_Exception $e) { throw new Kronolith_Exception($e); } return $errors; }
public function testReusing() { $mail = new Horde_Mime_Mail(array('Subject' => 'My Subject', 'body' => "This is\nthe body", 'To' => '*****@*****.**', 'From' => '*****@*****.**', 'charset' => 'iso-8859-15')); $dummy = new Horde_Mail_Transport_Mock(); $mail->send($dummy); $sent1 = str_replace("\r\n", "\n", $dummy->sentMessages[0]); $mail->addHeader('To', '*****@*****.**'); $mail->send($dummy); $sent2 = str_replace("\r\n", "\n", $dummy->sentMessages[1]); $mail->setBody("This is\nanother body"); $mail->send($dummy); $sent3 = str_replace("\r\n", "\n", $dummy->sentMessages[2]); $hdrs1 = Horde_Mime_Headers::parseHeaders($sent1['header_text']); $hdrs2 = Horde_Mime_Headers::parseHeaders($sent2['header_text']); $this->assertNotEquals($hdrs1->getValue('message-id'), $hdrs2->getValue('message-id')); $this->assertEquals(array('*****@*****.**'), $sent1['recipients']); $this->assertEquals(array('*****@*****.**'), $sent2['recipients']); $this->assertEquals("This is\nanother body\n", $sent3['body']); }
$notification->push($e); } } $redirect_url->redirect(); } /* Add user's name to the email address if provided. */ if ($name) { $addr_ob = new Horde_Mail_Rfc822_Address($email); if (is_null($addr_ob->host)) { $addr_ob->host = $conf['problems']['maildomain']; } $addr_ob->personal = $name; $email = $addr_ob->writeAddress(true); } $mail = new Horde_Mime_Mail(array('body' => $body, 'Subject' => _("[Problem Report]") . ' ' . $subject, 'To' => $conf['problems']['email'], 'From' => $email)); $mail->addHeader('Sender', 'horde-problem@' . $conf['problems']['maildomain']); /* Add attachment. */ if ($attachment) { $mail->addAttachment($attachment['tmp_name'], $attachment['name'], $attachment['type']); } try { $mail->send($injector->getInstance('Horde_Mail')); /* Success. */ Horde::log(sprintf("%s Message sent to %s from %s", $_SERVER['REMOTE_ADDR'], preg_replace('/^.*<([^>]+)>.*$/', '$1', $conf['problems']['email']), preg_replace('/^.*<([^>]+)>.*$/', '$1', $email)), 'INFO'); /* Return to previous page and exit this script. */ $redirect_url->redirect(); } catch (Horde_Exception $e) { $notification->push($e); } } break;