/** * Send an email using Swift (send commands) * * @param string to_address * @param string from_address * @param string subject * @param string body, optional * @param string content-type,optional * @param string content-transfer-encoding,optional * @return bool successful */ static function sendEmail($to, $from, $subject, $body = false, $type = 'text/plain', $encoding = '8bit', $attachments = array()) { $ret = false; if (config_option('notification_from_address')) { $from = config_option('notification_from_address'); } Hook::fire('notifier_email_body', $body, $body); Hook::fire('notifier_email_subject', $subject, $subject); Hook::fire('notifier_send_email', array('to' => $to, 'from' => $from, 'subject' => $subject, 'body' => $body, 'type' => $type, 'encoding' => $encoding), $ret); if ($ret) { return true; } Env::useLibrary('swift'); $mailer = self::getMailer(); if (!$mailer instanceof Swift_Mailer) { throw new NotifierConnectionError(); } // if $smtp_address = config_option("smtp_address"); if (config_option("mail_transport") == self::MAIL_TRANSPORT_SMTP && $smtp_address) { $pos = strrpos($from, "<"); if ($pos !== false) { //$sender_address = trim(substr($from, $pos + 1), "> "); $sender_name = trim(substr($from, 0, $pos)); } else { $sender_name = ""; } $from = array($smtp_address => $sender_name); } else { $pos = strrpos($from, "<"); if ($pos !== false) { $sender_name = trim(substr($from, 0, $pos)); $sender_address = str_replace(array("<", ">"), array("", ""), trim(substr($from, $pos, strlen($from) - 1))); } else { $sender_name = ""; $sender_address = $from; } $from = array($sender_address => $sender_name); } //Create the message $message = Swift_Message::newInstance($subject)->setFrom($from)->setBody($body)->setContentType($type); foreach ($attachments as $a) { $attach = Swift_Attachment::fromPath(array_var($a, 'path'), array_var($a, 'type')); $attach->setDisposition(array_Var($a, 'disposition', 'attachment')); if (array_var($a, 'cid')) { $attach->setId(array_var($a, 'cid')); } if (array_var($a, 'name')) { $attach->setFilename(array_var($a, 'name')); } $message->attach($attach); } $message->setContentType($type); $to = prepare_email_addresses(implode(",", $to)); foreach ($to as $address) { $message->addTo(array_var($address, 0), array_var($address, 1)); } $result = $mailer->send($message); return $result; }
/** * add_file_from_multi * * @access public * @param $file_data * @param $uploaded_file * @param $member_ids * @return file id */ function add_file_from_multi($file_data, $uploaded_file, $member_ids, $upload_option) { try { if ($upload_option != -1) { $file = ProjectFiles::findById($upload_option); } else { $file = new ProjectFile(); } $type = array_var($file_data, 'type'); $file->setType($type); $file->setFilename(array_var($file_data, 'name')); $file->setFromAttributes($file_data); $file->setIsVisible(true); $file->setAttachToNotification(array_var($file_data, 'attach_to_notification')); if (array_var($file_data, 'default_subject_sel') == 'subject') { $file->setDefaultSubject(array_var($file_data, 'default_subject_text')); } else { $file->setDefaultSubject(''); } DB::beginWork(); $file->save(); if ($file->getType() == ProjectFiles::TYPE_DOCUMENT) { // handle uploaded file $revision_comment = array_var($file_data, 'revision_comment'); $revision = $file->handleUploadedFile($uploaded_file, true, $revision_comment); // handle uploaded file @unlink($uploaded_file['tmp_name']); } $object_controller = new ObjectController(); //$member_ids = json_decode(array_var($_POST, 'members')); if (count($member_ids) > 0 || !array_var($file_data, 'composing_mail')) { $object_controller->add_to_members($file, $member_ids); } $object_controller->add_subscribers($file, array('user_' . logged_user()->getId() => '1')); //If New file if ($upload_option == -1) { //Add links $object_controller->link_to_new_object($file); $object_controller->add_subscribers($file); if (!array_Var($file_data, 'composing_mail')) { $object_controller->add_custom_properties($file); } } DB::commit(); set_user_config_option('notify_myself_too', array_var($file_data, 'notify_myself_too')); if (array_var($file_data, 'notify_myself_too')) { logged_user()->notify_myself = true; } ApplicationLogs::createLog($file, ApplicationLogs::ACTION_ADD); if (array_var($file_data, 'notify_myself_too')) { logged_user()->notify_myself = false; } return $file->getId(); } catch (Exception $e) { DB::rollback(); Logger::log("Error when uploading file: " . $e->getMessage() . "\n" . $e->getTraceAsString()); // If we uploaded the file remove it from repository if (isset($revision) && $revision instanceof ProjectFileRevision && FileRepository::isInRepository($revision->getRepositoryId())) { FileRepository::deleteFile($revision->getRepositoryId()); } // if flash_error($e->getMessage()); } // try }