protected function send($alternateRecipient = null)
 {
     $mime = new Mail_mime(array("head_charset" => "utf-8", "text_charset" => "utf-8", "html_charset" => "utf-8", 'eol' => "\n"));
     $mime->setTXTBody($this->txtBody);
     if ($this->htmlBody !== null) {
         $mime->setHTMLBody($this->htmlBody);
     }
     if (!empty($this->attachments)) {
         foreach ($this->attachments as $attachment) {
             $mime->addAttachment($attachment->File(), $attachment->Type());
         }
     }
     $this->headers['To'] = $this->receipients;
     $this->headers['Sender'] = $this->headers['From'];
     $empfaenger = $this->receipients;
     if ($this->bcc !== null) {
         $this->receipients .= ($this->receipients > '' ? ',' : '') . $this->bcc;
     }
     //do not ever try to call these lines in reverse order
     $body = $mime->get();
     $headers = $mime->headers($this->headers, true);
     if ($this->receipients > '') {
         if (!$GLOBALS['Settings']['OnServer']) {
             $this->receipients = '*****@*****.**';
         } elseif ($alternateRecipient) {
             $this->receipients = $alternateRecipient;
         }
         $mail_queue = new Mail_Queue($GLOBALS['Settings']['MailQueue']['db_options'], $GLOBALS['Settings']['MailQueue']['mail_options']);
         $mail_queue->put($this->headers['From'], $this->receipients, $headers, $body, $this->delay);
     }
     return true;
 }
Example #2
0
File: Error.php Project: roojs/pear
 /**
  * Mail_Queue_Error constructor.
  *
  * @param mixed   $code      Mail_Queue error code, or string with error message.
  * @param integer $mode      what 'error mode' to operate in
  * @param integer $level     what error level to use for
  *                           $mode & PEAR_ERROR_TRIGGER
  * @param string  $debuginfo additional debug info
  */
 function Mail_Queue_Error($code = MAILQUEUE_ERROR, $mode = PEAR_ERROR_RETURN, $level = E_USER_NOTICE, $file = __FILE__, $line = __LINE__, $debuginfo = '')
 {
     $debuginfo .= (empty($debuginfo) ? '' : ' - ') . 'FILE: ' . $file . ', LINE: ' . $line;
     if (is_int($code)) {
         parent::__construct('Mail Queue Error: ' . Mail_Queue::errorMessage($code), $code, $mode, $level, $debuginfo);
     } else {
         parent::__construct('Mail Queue Error: ' . $code, MAILQUEUE_ERROR, $mode, $level, $debuginfo);
     }
 }
Example #3
0
 /**
  * 邮件发送
  * @return boolean
  */
 public function send_mail($recipient, $mailsubject, $mailbody)
 {
     apf_require_file("Swift.php");
     Swift_ClassLoader::load("Swift_Connection_SMTP");
     $message = new Swift_Message($mailsubject);
     $message->setFrom("安居客<*****@*****.**>");
     $message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8"));
     $message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8"));
     foreach ($recipient as $re) {
         Mail_Queue::put('*****@*****.**', $re, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
     }
     return true;
 }
Example #4
0
 /**
  * Initializes the Mail_Queue in {@link self::$queue}.
  *
  * @return void
  * @uses   MDB2_Driver_SQLite
  */
 public function setUp()
 {
     if (!extension_loaded('sqlite')) {
         $this->markTestSkipped("You need ext/sqlite to run this test suite.");
         return;
     }
     $this->dsn = 'sqlite:///' . __DIR__ . "/{$this->db}?mode=0644";
     $this->setUpDatabase($this->dsn);
     $container_opts = array('type' => 'mdb2', 'dsn' => $this->dsn, 'mail_table' => $this->table);
     /**
      * @see Mail_mock
      */
     $mail_opts = array('driver' => 'mock');
     $this->queue = new Mail_Queue($container_opts, $mail_opts);
     if ($this->queue->hasErrors()) {
         $errors = $this->queue->getErrors();
         $fail = "The following errors occurred:\n";
         foreach ($errors as $error) {
             $fail .= $error->getMessage() . "\n";
         }
         $this->fail($fail);
     }
 }
Example #5
0
 /**
  * 邮件发送
  * @param recipient 邮件接收方email
  * @param mailsubject 邮件主题
  * @param mailbody 邮件内容
  * @return boolean
  */
 private function send_mail($recipient, $mailsubject, $mailbody)
 {
     try {
         $message = new Swift_Message($mailsubject);
         $message->setFrom("安居客<" . $this->sender . ">");
         $message->setTo($recipient);
         $message->attach(new Swift_Message_Part(strip_tags($mailbody), "text/plain", "base64", "utf-8"));
         $message->attach(new Swift_Message_Part($mailbody, "text/html", "base64", "utf-8"));
         Mail_Queue::put($this->sender, $recipient, $mailsubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Example #6
0
/**
 * Process mail queue (cron task function).
 *
 * @param vivvo_lite_site	$sm
 */
function mail_queue($sm)
{
    require_once VIVVO_FS_INSTALL_ROOT . 'lib/vivvo/framework/PEAR/Mail/Queue.php';
    $container_options = array('type' => 'mdb2', 'dsn' => VIVVO_DB_TYPE . '://' . VIVVO_DB_USER . ':' . VIVVO_DB_PASSWORD . '@' . VIVVO_DB_HOST . '/' . VIVVO_DB_DATABASE, 'mail_table' => VIVVO_DB_PREFIX . 'mail_queue');
    if (VIVVO_EMAIL_SMTP_PHP == 1) {
        $mail_options = array('driver' => 'mail');
    } else {
        $mail_options = array('driver' => 'smtp', 'host' => VIVVO_EMAIL_SMTP_HOST, 'port' => VIVVO_EMAIL_SMTP_PORT, 'localhost' => 'localhost');
        if (VIVVO_EMAIL_SMTP_PASSWORD != '' and VIVVO_EMAIL_SMTP_USERNAME != '') {
            $mail_options['auth'] = true;
            $mail_options['username'] = VIVVO_EMAIL_SMTP_USERNAME;
            $mail_options['password'] = VIVVO_EMAIL_SMTP_PASSWORD;
        } else {
            $mail_options['auth'] = false;
            $mail_options['username'] = '';
            $mail_options['password'] = '';
        }
    }
    $mail_queue = new Mail_Queue($container_options, $mail_options);
    $mail_queue->sendMailsInQueue(VIVVO_PLUGIN_NEWSLETTER_NUMBER_OF_MAILS);
    if (defined('VIVVO_CRONJOB_MODE')) {
        echo 'mail_queue: Finished.' . PHP_EOL;
    }
}
Example #7
0
 protected function sentMail($mailSubject, $mailBody)
 {
     if ($this->mailSwitch == true && !empty($this->mailAddress)) {
         $mailto = $this->mailAddress;
         apf_require_file("Swift.php");
         Swift_ClassLoader::load("Swift_Connection_SMTP");
         $smtpuser = APF::get_instance()->get_config("SmtpUser");
         $smtpemailto = $mailto;
         $message = new Swift_Message($mailSubject);
         $message->setFrom("安居客<" . $smtpuser . ">");
         $message->setTo($smtpemailto);
         $message->attach(new Swift_Message_Part(strip_tags($mailBody), "text/plain", "base64", "utf-8"));
         $message->attach(new Swift_Message_Part($mailBody, "text/html", "base64", "utf-8"));
         foreach ($smtpemailto as $to) {
             if (!empty($to)) {
                 @Mail_Queue::put($smtpuser, $to, $mailSubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
             }
         }
     }
 }
 /**
  * 发送邮件
  * @param $mailSubject 标题
  * @param $mailBody 内容
  * @param array $mailTo 接受人,数组
  * @return bool
  */
 public function sendMail($mailSubject, $mailBody, $mailTo = array())
 {
     if (empty($mailSubject) || empty($mailBody) || empty($mailTo)) {
         return false;
     }
     apf_require_file("Swift.php");
     Swift_ClassLoader::load("Swift_Connection_SMTP");
     $smtpuser = APF::get_instance()->get_config("SmtpUser");
     $smtpemailto = $mailTo;
     $message = new Swift_Message($mailSubject);
     $message->setFrom("安居客<" . $smtpuser . ">");
     $message->setTo($smtpemailto);
     $message->attach(new Swift_Message_Part(strip_tags($mailBody), "text/plain", "base64", "utf-8"));
     $message->attach(new Swift_Message_Part($mailBody, "text/html", "base64", "utf-8"));
     foreach ($smtpemailto as $to) {
         if (!empty($to)) {
             @Mail_Queue::put($smtpuser, $to, $mailSubject, $message, Const_Mail::TYPE_SWIFT, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
         }
     }
     return true;
 }
        }
    } else {
        foreach (array_keys($config) as $key) {
            if (isset($_GET[$key])) {
                $config[$key] = $_GET[$key];
            }
        }
    }
    return $config;
}
$config = getParams();
// if requested, clear the lock
if ($config['fix-lock']) {
    if (Lock::release('process_mail_queue')) {
        echo "The lock file was removed successfully.\n";
    }
    exit(0);
}
if (!Lock::acquire('process_mail_queue')) {
    $pid = Lock::getProcessID('process_mail_queue');
    fwrite(STDERR, "ERROR: There is already a process (pid={$pid}) of this script running.");
    fwrite(STDERR, "If this is not accurate, you may fix it by running this script with '--fix-lock' as the only parameter.\n");
    exit(1);
}
// handle only pending emails
$limit = 50;
Mail_Queue::send('pending', $limit);
// handle emails that we tried to send before, but an error happened...
$limit = 50;
Mail_Queue::send('error', $limit);
Lock::release('process_mail_queue');
Example #10
0
// | This program is distributed in the hope that it will be useful,      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
// | GNU General Public License for more details.                         |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with this program; if not, write to:                           |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 51 Franklin Street, Suite 330                                        |
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: Bryan Alsdorf <*****@*****.**>                          |
// +----------------------------------------------------------------------+
ini_set('memory_limit', '1024M');
require_once dirname(__FILE__) . '/../init.php';
// if requested, clear the lock
if (in_array('--fix-lock', $argv)) {
    if (Lock::release('truncate_mail_queue')) {
        echo "The lock file was removed successfully.\n";
    }
    exit(0);
}
if (!Lock::acquire('truncate_mail_queue')) {
    $pid = Lock::getProcessID('truncate_mail_queue');
    fwrite(STDERR, "ERROR: There is already a process (pid={$pid}) of this script running.");
    fwrite(STDERR, "If this is not accurate, you may fix it by running this script with '--fix-lock' as the only parameter.\n");
    exit(1);
}
Mail_Queue::truncate();
Lock::release('truncate_mail_queue');
 /**
  * Method used to forward the new email to the list of subscribers.
  *
  * @param   integer $user_id The user ID of the person performing this action
  * @param   integer $issue_id The issue ID
  * @param   array $message An array containing the email
  * @param   boolean $internal_only Whether the email should only be redirected to internal users or not
  * @param   boolean $assignee_only Whether the email should only be sent to the assignee
  * @param   boolean $type The type of email this is
  * @param   integer $sup_id the ID of this email
  * @return  void
  */
 public static function notifyNewEmail($usr_id, $issue_id, $message, $internal_only = false, $assignee_only = false, $type = '', $sup_id = false)
 {
     $prj_id = Issue::getProjectID($issue_id);
     $full_message = $message['full_email'];
     $sender = $message['from'];
     $sender_email = strtolower(Mail_Helper::getEmailAddress($sender));
     // get ID of whoever is sending this.
     $sender_usr_id = User::getUserIDByEmail($sender_email, true);
     if (empty($sender_usr_id)) {
         $sender_usr_id = false;
     }
     // automatically subscribe this sender to email notifications on this issue
     $subscribed_emails = self::getSubscribedEmails($issue_id, 'emails');
     $subscribed_emails = Misc::lowercase($subscribed_emails);
     if (!self::isIssueRoutingSender($issue_id, $sender) && !self::isBounceMessage($sender_email) && !in_array($sender_email, $subscribed_emails) && Workflow::shouldAutoAddToNotificationList($prj_id)) {
         $actions = array('emails');
         self::subscribeEmail($usr_id, $issue_id, $sender_email, $actions);
     }
     // get the subscribers
     $emails = array();
     $users = self::getUsersByIssue($issue_id, 'emails');
     foreach ($users as $user) {
         if (empty($user['sub_usr_id'])) {
             if ($internal_only == false) {
                 $email = $user['sub_email'];
             }
         } else {
             // if we are only supposed to send email to internal users, check if the role is lower than standard user
             if ($internal_only == true && User::getRoleByUser($user['sub_usr_id'], Issue::getProjectID($issue_id)) < User::ROLE_USER) {
                 continue;
             }
             // check if we are only supposed to send email to the assignees
             if ($internal_only == true && $assignee_only == true) {
                 $assignee_usr_ids = Issue::getAssignedUserIDs($issue_id);
                 if (!in_array($user['sub_usr_id'], $assignee_usr_ids)) {
                     continue;
                 }
             }
             $email = User::getFromHeader($user['sub_usr_id']);
         }
         if (empty($email)) {
             continue;
         }
         // don't send the email to the same person who sent it unless they want it
         if ($sender_usr_id != false) {
             $prefs = Prefs::get($sender_usr_id);
             if (!isset($prefs['receive_copy_of_own_action'][$prj_id])) {
                 $prefs['receive_copy_of_own_action'][$prj_id] = 0;
             }
             if ($prefs['receive_copy_of_own_action'][$prj_id] == 0 && (!empty($user['sub_usr_id']) && $sender_usr_id == $user['sub_usr_id'] || strtolower(Mail_Helper::getEmailAddress($email)) == $sender_email)) {
                 continue;
             }
         }
         $emails[] = $email;
     }
     if (!$emails) {
         return;
     }
     // change the sender of the message to {prefix}{issue_id}@{host}
     //  - keep everything else in the message, except 'From:', 'Sender:', 'To:', 'Cc:'
     // make 'Joe Blow <*****@*****.**>' become 'Joe Blow [CSC] <*****@*****.**>'
     $from = self::getFixedFromHeader($issue_id, $sender, 'issue');
     list($_headers, $body) = Mime_Helper::splitBodyHeader($full_message);
     $header_names = Mime_Helper::getHeaderNames($_headers);
     $current_headers = Mail_Helper::stripHeaders($message['headers']);
     $headers = array();
     // build the headers array required by the smtp library
     foreach ($current_headers as $header_name => $value) {
         if ($header_name == 'from') {
             $headers['From'] = $from;
         } else {
             if (is_array($value)) {
                 $value = implode('; ', $value);
             }
             $headers[$header_names[$header_name]] = $value;
         }
     }
     $headers['Subject'] = Mail_Helper::formatSubject($issue_id, $headers['Subject']);
     if (empty($type)) {
         if ($sender_usr_id != false && User::getRoleByUser($sender_usr_id, Issue::getProjectID($issue_id)) == User::ROLE_CUSTOMER) {
             $type = 'customer_email';
         } else {
             $type = 'other_email';
         }
     }
     $options = array('save_email_copy' => 1, 'issue_id' => $issue_id, 'type' => $type, 'sender_usr_id' => $sender_usr_id, 'type_id' => $sup_id);
     foreach ($emails as $to) {
         // add the warning message about replies being blocked or not
         // FIXME: $headers contains $headers['To'] from previous iteration
         $fixed_body = Mail_Helper::addWarningMessage($issue_id, $to, $body, $headers);
         $headers['To'] = Mime_Helper::encodeAddress($to);
         $mail = array('to' => $to, 'headers' => $headers, 'body' => $fixed_body);
         Mail_Queue::addMail($mail, $options);
     }
 }
Example #12
0
 /**
  * Method used to send the SMTP based email message.
  *
  * @access  public
  * @param   string $from The originator of the message
  * @param   string $to The recipient of the message
  * @param   string $subject The subject of the message
  * @param   integer $issue_id The ID of the issue. If false, email will not be associated with issue.
  * @param   string $type The type of message this is
  * @param   integer $sender_usr_id The id of the user sending this email.
  * @param   integer $type_id The ID of the event that triggered this notification (issue_id, sup_id, not_id, etc)
  * @return  string The full body of the message that was sent
  */
 function send($from, $to, $subject, $save_email_copy = 0, $issue_id = false, $type = '', $sender_usr_id = false, $type_id = false)
 {
     static $support_levels;
     // encode the addresses
     $from = MIME_Helper::encodeAddress($from);
     $to = MIME_Helper::encodeAddress($to);
     $subject = MIME_Helper::encode($subject);
     $body = $this->mime->get();
     $headers = array('From' => $from, 'To' => Mail_API::fixAddressQuoting($to), 'Subject' => $subject);
     $this->setHeaders($headers);
     $hdrs = $this->mime->headers($this->headers);
     $res = Mail_Queue::add($to, $hdrs, $body, $save_email_copy, $issue_id, $type, $sender_usr_id, $type_id);
     if (PEAR::isError($res) || $res == false) {
         return $res;
     } else {
         // RFC 822 formatted date
         $header = 'Date: ' . date('D, j M Y H:i:s O') . "\r\n";
         // return the full dump of the email
         foreach ($hdrs as $name => $value) {
             $header .= "{$name}: {$value}\r\n";
         }
         $header .= "\r\n";
         return $header . $body;
     }
 }
Example #13
0
 /**
  * Preload mail to queue.
  * The buffer size can be set in the options.
  *
  * @return mixed True on success, false when the limit is met, else
  *               Mail_Queue_Error object.
  *
  * @access private
  */
 function preload()
 {
     if (!empty($this->queue_data)) {
         return true;
     }
     if (!$this->limit) {
         return false;
         //limit reached
     }
     $bkp_limit = $this->limit;
     //set buffer size
     if ($bkp_limit == MAILQUEUE_ALL) {
         $this->limit = $this->buffer_size;
     } else {
         $this->limit = min($this->buffer_size, $this->limit);
     }
     if (Mail_Queue::isError($err = $this->_preload())) {
         return $err;
     }
     //restore limit
     if ($bkp_limit == MAILQUEUE_ALL) {
         $this->limit = MAILQUEUE_ALL;
     } else {
         $this->limit = $bkp_limit - count($this->queue_data);
     }
     //set buffer pointers
     $this->_current_item = 0;
     $this->_last_item = count($this->queue_data) - 1;
     return true;
 }
Example #14
0
<?php

require_once '_init.php';
$emailQueueId = cleanRequest('id');
if (!$emailQueueId) {
    die("REQUEST = NULL");
} else {
    $mail_queue = new Mail_Queue($container_options, $mail_options);
    $contanier = new Mail_Queue_Container_db($container_options);
    if ($contanier->getMailById($emailQueueId)) {
        $mail_queue->deleteMail($emailQueueId);
    }
    header("Location: ../index.php");
}
<?php

/**
 * @copyright 2005-2008 OpenPNE Project
 * @license   http://www.php.net/license/3_01.txt PHP License 3.01
 */
require_once './config.inc.php';
require_once OPENPNE_WEBAPP_DIR . '/init.inc';
if (OPENPNE_UNDER_MAINTENANCE) {
    exit;
}
require_once 'Mail/Queue.php';
$db_opt = array("type" => "db", "dsn" => $GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn'], "mail_table" => "mail_queue");
$mail_opt = array("driver" => "mail");
$mail_queue = new Mail_Queue($db_opt, $mail_opt);
$mail_queue->sendMailsInQueue(SEND_MAIL_QUEUE_NUM);
Example #16
0
// | This program is free software; you can redistribute it and/or modify |
// | it under the terms of the GNU General Public License as published by |
// | the Free Software Foundation; either version 2 of the License, or    |
// | (at your option) any later version.                                  |
// |                                                                      |
// | This program is distributed in the hope that it will be useful,      |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
// | GNU General Public License for more details.                         |
// |                                                                      |
// | You should have received a copy of the GNU General Public License    |
// | along with this program; if not, write to:                           |
// |                                                                      |
// | Free Software Foundation, Inc.                                       |
// | 51 Franklin Street, Suite 330                                          |
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('mail_queue.tpl.html');
Auth::checkAuthentication(APP_COOKIE);
$issue_id = $_GET['iss_id'];
if (Auth::getCurrentRole() < User::getRoleID('Developer') || Issue::getProjectID($issue_id) != Auth::getCurrentProject()) {
    $tpl->assign('denied', 1);
} else {
    $data = Mail_Queue::getListByIssueID($issue_id);
    $tpl->assign(array('data' => $data, 'issue_id' => $issue_id));
}
$tpl->displayTemplate();
Example #17
0
 /**
  * Method used to send the SMTP based email message.
  *
  * @param   string $from The originator of the message
  * @param   string $to The recipient of the message
  * @param   string $subject The subject of the message
  * @param   integer $issue_id The ID of the issue. If false, email will not be associated with issue.
  * @param   string $type The type of message this is
  * @param   integer $sender_usr_id The id of the user sending this email.
  * @param   integer $type_id The ID of the event that triggered this notification (issue_id, sup_id, not_id, etc)
  * @return  string The full body of the message that was sent
  */
 public function send($from, $to, $subject, $save_email_copy = 0, $issue_id = false, $type = '', $sender_usr_id = false, $type_id = false)
 {
     // encode the addresses
     $from = Mime_Helper::encodeAddress($from);
     $to = Mime_Helper::encodeAddress($to);
     $subject = Mime_Helper::encode($subject);
     $body = $this->mime->get(array('text_charset' => APP_CHARSET, 'head_charset' => APP_CHARSET, 'text_encoding' => APP_EMAIL_ENCODING));
     $headers = array('From' => $from, 'To' => self::fixAddressQuoting($to), 'Subject' => $subject);
     $this->setHeaders($headers);
     $hdrs = $this->mime->headers($this->headers);
     $res = Mail_Queue::add($to, $hdrs, $body, $save_email_copy, $issue_id, $type, $sender_usr_id, $type_id);
     if (Misc::isError($res) || $res == false) {
         return $res;
     }
     // RFC 822 formatted date
     $header = 'Date: ' . Date_Helper::getRFC822Date(time()) . "\r\n";
     // return the full dump of the email
     foreach ($hdrs as $name => $value) {
         $header .= "{$name}: {$value}\r\n";
     }
     $header .= "\r\n";
     return $header . $body;
 }
Example #18
0
require_once '_init.php';
// HOW MANY MAILS ARE IN QUEUE
$mailsInQueue = c("select id from mail_queue where sent_time is null");
// IF NO EMAILS TO SEND IN QUEUE, RETURN
if (!$mailsInQueue) {
    if (CRON) {
        echo "Mails In Queue: " . $mailsInQueue . "\nNothing to Do.\n\n";
    }
    return;
} else {
    if (CRON) {
        echo "Mails In Queue: " . $mailsInQueue . "\nBatch Size: " . $mail_options['max_ammount_mails'] . "\nTrys: " . $mail_options['how_many_trys'] . "\nSending...\n\n";
    }
}
// MAILQUEUE INSTANCE
$mail_queue = new Mail_Queue($container_options, $mail_options);
// MAILQUEUE SEND ALL EMAILS IN QUEUE FROM THE BEGINING, IN CHUNKS OF X NUMBERS OF MAILS, TRYING X TIMES
$result = $mail_queue->sendMailsInQueue($mail_options['max_ammount_mails'], MAILQUEUE_START, $mail_options['how_many_trys'], 'mailqueue_callback');
if (!CRON && $result == true) {
    header("Location: ../index.php");
} else {
    echo "MAILQUEUE_ERROR object:";
    pr($result);
    die;
    //return false;
}
// FUNCTION CALLBACK TO UPDATE LOG FIELD IN DB.
function mailqueue_callback($args)
{
    if (!$args) {
        echo "NOT ARGS IN CALLBACK:";
    // web
    if (@$_GET['fix-lock'] == 1) {
        $fix_lock = true;
    }
} else {
    // command line
    if (in_array('--fix-lock', $_SERVER['argv'])) {
        $fix_lock = true;
    }
}
// if requested, clear the lock
if ($fix_lock) {
    Mail_Queue::removeProcessFile();
    echo "The lock file was removed successfully.\n";
    exit;
}
if (!Mail_Queue::isSafeToRun()) {
    $pid = Lock::getProcessID('process_mail_queue');
    echo "ERROR: There is already a process (pid={$pid}) of this script running. ";
    echo "If this is not accurate, you may fix it by running this script with '--fix-lock' as the only parameter.\n";
    exit;
}
ini_set("memory_limit", "256M");
// handle only pending emails
$limit = 50;
Mail_Queue::send('pending', $limit);
// handle emails that we tried to send before, but an error happened...
$limit = 50;
Mail_Queue::send('error', $limit);
Mail_Queue::removeProcessFile();
 /**
  * Connects to the SMTP server and sends the queued message.
  *
  * @access  private
  * @param   string $recipient The recipient of this message
  * @param   string $text_headers The full headers of this message
  * @param   string $body The full body of this message
  * @return  true, or a PEAR_Error object
  */
 function _sendEmail($recipient, $text_headers, $body)
 {
     $header_names = Mime_Helper::getHeaderNames($text_headers);
     $_headers = Mail_Queue::_getHeaders($text_headers, $body);
     $headers = array();
     foreach ($_headers as $lowercase_name => $value) {
         // need to remove the quotes to avoid a parsing problem
         // on senders that have extended characters in the first
         // or last words in their sender name
         if ($lowercase_name == 'from') {
             $value = Mime_Helper::removeQuotes($value);
         }
         $value = Mime_Helper::encode($value);
         // add the quotes back
         if ($lowercase_name == 'from') {
             $value = Mime_Helper::quoteSender($value);
         }
         $headers[$header_names[$lowercase_name]] = $value;
     }
     // remove any Reply-To:/Return-Path: values from outgoing messages
     unset($headers['Reply-To']);
     unset($headers['Return-Path']);
     // mutt sucks, so let's remove the broken Mime-Version header and add the proper one
     if (in_array('Mime-Version', array_keys($headers))) {
         unset($headers['Mime-Version']);
         $headers['MIME-Version'] = '1.0';
     }
     $mail =& Mail::factory('smtp', Mail_API::getSMTPSettings());
     $res = $mail->send($recipient, $headers, $body);
     if (PEAR::isError($res)) {
         // special handling of errors when the mail server is down
         if (strstr($res->getMessage(), 'unable to connect to smtp server')) {
             Error_Handler::logToFile(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         } else {
             Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
         }
         return $res;
     } else {
         return true;
     }
 }
 private function sendMail()
 {
     switch ($this->_dealType) {
         case Model_House_JpHouseIdx::ENUM_HOUSE_TYPE_OFFICE_RENT:
             $subject = '金铺【铺租】房源过期、违规,套餐关系修复';
             break;
         case Model_House_JpHouseIdx::ENUM_HOUSE_TYPE_OFFICE_SALE:
             $subject = '金铺【铺售】房源过期、违规,套餐关系修复';
             break;
         case Model_House_JpHouseIdx::ENUM_HOUSE_TYPE_SHOP_RENT:
             $subject = '金铺【楼售】房源过期、违规,套餐关系修复';
             break;
         case Model_House_JpHouseIdx::ENUM_HOUSE_TYPE_SHOP_SALE:
             $subject = '金铺【楼租】房源过期、违规,套餐关系修复';
             break;
         default:
             $subject = '金铺房源删除,套餐关系修复';
     }
     $content = file_get_contents($this->_email);
     foreach ($this->_recipient as $recipient) {
         Mail_Queue::put('*****@*****.**', $recipient, $subject, $content, Const_Mail::TYPE_PLAIN, Const_Mail::TYPE_ID_COMMUNITY_SUBSCRIBE);
     }
 }
Example #22
0
// | Boston, MA 02110-1301, USA.                                          |
// +----------------------------------------------------------------------+
// | Authors: João Prado Maia <*****@*****.**>                             |
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../init.php';
$usr_id = Auth::getUserID();
$prj_id = Auth::getCurrentProject();
$tpl = new Template_Helper();
$tpl->setTemplate('view_email.tpl.html');
Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true);
$issue_id = Support::getIssueFromEmail($_GET['id']);
if ($issue_id != 0 && !Issue::canAccess($issue_id, $usr_id) || $issue_id == 0 && User::getRoleByUser($usr_id, $prj_id) < User::ROLE_USER) {
    $tpl->setTemplate('permission_denied.tpl.html');
    $tpl->displayTemplate();
    exit;
}
$email = Support::getEmailDetails($_GET['ema_id'], $_GET['id']);
$email['seb_body'] = str_replace('&amp;nbsp;', '&nbsp;', $email['seb_body']);
$tpl->assign(array('email' => $email, 'issue_id' => $issue_id, 'extra_title' => ev_gettext('Issue #%1$s Email #%3$s: %2$s', $issue_id, $email['sup_subject'], Support::getSequenceByID($_GET['id'])), 'email_accounts' => Email_Account::getAssocList(array_keys(Project::getAssocList(Auth::getUserID())), true), 'recipients' => Mail_Queue::getMessageRecipients(array('customer_email', 'other_email'), $_GET['id'])));
if (@$_GET['cat'] == 'list_emails') {
    $sides = Support::getListingSides($_GET['id']);
    $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next']));
} elseif (@$_GET['cat'] == 'move_email' && Auth::getCurrentRole() >= User::getRoleID('Standard User')) {
    $res = Support::moveEmail(@$_GET['id'], @$_GET['ema_id'], @$_GET['new_ema_id']);
    $tpl->assign('move_email_result', $res);
    $tpl->assign('current_user_prefs', Prefs::get(Auth::getUserID()));
} else {
    $sides = Support::getIssueSides($issue_id, $_GET['id']);
    $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next']));
}
$tpl->displayTemplate();
Example #23
0
/**
 * Selects a mail queue entry from the table and returns the contents.
 *
 * @param   string $id The mail queue entry ID.
 * @return  A string containing the body.
 */
function getMailQueue($id)
{
    if (Auth::getCurrentRole() < User::getRoleID('Developer')) {
        return;
    }
    $res = Mail_Queue::getEntry($id);
    if (!Issue::canAccess($res['maq_iss_id'], $GLOBALS['usr_id'])) {
        return '';
    }
    if (empty($_GET['ec_id'])) {
        return $res['maq_body'];
    }
    return Link_Filter::processText(Auth::getCurrentProject(), nl2br(htmlspecialchars($res['maq_headers'] . "\n" . $res['maq_body'])));
}
Example #24
0
/**
 * Положить письмо в очередь
 *
 * @param string $recipient
 * @param string $from
 * @param string $subject
 * @param string $message
 * @param string HTML-сообщение
 *
 * Чтобы отправить сообщение в формате HTML, нужно указать параметр html_message.
 * При этом параметр message должен содержать сообщение в plain text или может быть пустым
 *
 * Чтобы отправить plain text, параметр html_message нужно оставить пустым.
 */
function nc_mail2queue($recipient, $from, $subject, $message, $html_message = "", $attachment_type = "")
{
    require_once "Mail/Queue.php";
    $db_options = array('type' => 'ezsql', 'mail_table' => 'Mail_Queue');
    $mail_options = array('driver' => 'mail');
    $mail_queue = new Mail_Queue($db_options, $mail_options);
    $hdrs = array('From' => $from, 'Subject' => nc_base64_encode_header($subject));
    $mime = new Mail_mime("\n");
    if ($attachment_type) {
        $nc_core = nc_Core::get_object();
        $db = $nc_core->db;
        $type_escaped = $db->escape($attachment_type);
        $sql = "SELECT `Filename`, `Path`, `Content_Type`, `Extension` FROM `Mail_Attachment` WHERE `Type` = '{$type_escaped}'";
        $attachments = (array) $db->get_results($sql, ARRAY_A);
        while (preg_match('/\\%FILE_([-_a-z0-9]+)/i', $html_message, $match)) {
            $filename = $match[1];
            $file = false;
            foreach ($attachments as $index => $attachment) {
                if (strtolower($attachment['Filename']) == strtolower($filename)) {
                    $file = $attachment;
                    unset($attachments[$index]);
                    break;
                }
            }
            $replace = '';
            if ($file) {
                $absolute_path = $nc_core->DOCUMENT_ROOT . $file['Path'];
                $replace = 'file_' . $filename . '.' . $file['Extension'];
                $mime->addHTMLImage(@file_get_contents($absolute_path), $file['Content_Type'], $replace, false);
            }
            $html_message = preg_replace('/\\%FILE_' . preg_quote($filename) . '/', $replace, $html_message);
        }
        foreach ($attachments as $attachment) {
            $absolute_path = $nc_core->DOCUMENT_ROOT . $attachment['Path'];
            $mime->addAttachment($absolute_path, $attachment['Content_Type'], $attachment['Filename'] . '.' . $attachment['Extension']);
        }
    }
    if ($message) {
        $mime->setTXTBody($message);
    }
    if ($html_message) {
        $mime->setHTMLBody($html_message);
    }
    $body = $mime->get(array('text_encoding' => '8bit', 'html_charset' => MAIN_EMAIL_ENCODING, 'text_charset' => MAIN_EMAIL_ENCODING, 'head_charset' => MAIN_EMAIL_ENCODING));
    $hdrs = $mime->headers($hdrs);
    $mail_queue->put($from, $recipient, $hdrs, $body);
}
Example #25
0
File: mdb.php Project: Blu2z/implsk
 /**
  * Preload mail to queue.
  *
  * @return mixed   True on success else Mail_Queue_Error object.
  * @access private
  */
 function _preload()
 {
     $query = 'SELECT id FROM ' . $this->mail_table . ' WHERE sent_time IS NULL AND try_sent < ' . $this->try . ' AND time_to_send < ' . $this->db->getTimestampValue(date("Y-m-d H:i:s")) . ' ORDER BY time_to_send';
     $res = $this->db->limitQuery($query, null, $this->offset, $this->limit);
     if (MDB::isError($res)) {
         return new Mail_Queue_Error(MAILQUEUE_ERROR_QUERY_FAILED, $this->pearErrorMode, E_USER_ERROR, __FILE__, __LINE__, 'MDB: query failed - "' . $query . '" - ' . $res->getMessage());
     }
     $this->_last_item = 0;
     $this->queue_data = array();
     //reset buffer
     while ($row = $this->db->fetchInto($res, MDB_FETCHMODE_ASSOC)) {
         $this->queue_data[$this->_last_item] = $this->getMailById($row['id']);
         if (Mail_Queue::isError($this->queue_data[$this->_last_item])) {
             return $this->queue_data[$this->_last_item];
         }
         $this->_last_item++;
     }
     @$this->db->freeResult($res);
     return true;
 }
Example #26
0
<?php

// Parameters (GET): number (default: 20)
$NETCAT_FOLDER = join(strstr(__FILE__, "/") ? "/" : "\\", array_slice(preg_split("/[\\/\\\\]+/", __FILE__), 0, -3)) . (strstr(__FILE__, "/") ? "/" : "\\");
include_once $NETCAT_FOLDER . "vars.inc.php";
require_once $ROOT_FOLDER . "connect_io.php";
require_once $INCLUDE_FOLDER . "lib/Mail/Queue.php";
$number = $_GET['number'] ? $_GET['number'] : 20;
$db_options = array('type' => 'ezsql', 'mail_table' => 'Mail_Queue');
$mail_options = array('driver' => 'mail');
$mail_queue = new Mail_Queue($db_options, $mail_options);
$mail_queue->sendMailsInQueue($number);
Example #27
0
// +----------------------------------------------------------------------+
require_once dirname(__FILE__) . '/../init.php';
$tpl = new Template_Helper();
$tpl->setTemplate('view_note.tpl.html');
Auth::checkAuthentication(APP_COOKIE, 'index.php?err=5', true);
$usr_id = Auth::getUserID();
$note_id = $_GET['id'];
$note = Note::getDetails($note_id);
if ($note == '') {
    $tpl->assign('note', '');
    $tpl->displayTemplate();
    exit;
} else {
    $note['message'] = $note['not_note'];
    $issue_id = Note::getIssueID($note_id);
    $usr_id = Auth::getUserID();
}
if (User::getRoleByUser($usr_id, Issue::getProjectID($issue_id)) < User::getRoleID('Standard User') || !Access::canViewInternalNotes($issue_id, Auth::getUserID())) {
    $tpl->setTemplate('permission_denied.tpl.html');
    $tpl->displayTemplate();
    exit;
}
$note = Note::getDetails($_GET['id']);
$note['message'] = $note['not_note'];
$issue_id = Note::getIssueID($_GET['id']);
$tpl->assign(array('note' => $note, 'issue_id' => $issue_id, 'extra_title' => 'Note #' . Note::getNoteSequenceNumber($issue_id, $note_id) . ': ' . $note['not_title'], 'recipients' => Mail_Queue::getMessageRecipients('notes', $note_id)));
if (!empty($issue_id)) {
    $sides = Note::getSideLinks($issue_id, $_GET['id']);
    $tpl->assign(array('previous' => $sides['previous'], 'next' => $sides['next']));
}
$tpl->displayTemplate();
Example #28
0
File: Queue.php Project: roojs/pear
 /**
  * Return a textual error message for a MDB error code
  *
  * @param   int     $value error code
  * @return  string  error message, or false if the error code was
  *                  not recognized
  * @access public
  */
 function errorMessage($value)
 {
     static $errorMessages;
     if (!isset($errorMessages)) {
         $errorMessages = array(MAILQUEUE_ERROR => 'unknown error', MAILQUEUE_ERROR_NO_DRIVER => 'No mail driver specified', MAILQUEUE_ERROR_NO_CONTAINER => 'No container specified', MAILQUEUE_ERROR_CANNOT_INITIALIZE => 'Cannot initialize container', MAILQUEUE_ERROR_NO_OPTIONS => 'No container options specified', MAILQUEUE_ERROR_CANNOT_CONNECT => 'Cannot connect to database', MAILQUEUE_ERROR_QUERY_FAILED => 'db query failed', MAILQUEUE_ERROR_UNEXPECTED => 'Unexpected class', MAILQUEUE_ERROR_CANNOT_SEND_MAIL => 'Cannot send email');
     }
     if (Mail_Queue::isError($value)) {
         $value = $value->getCode();
     }
     return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[MAILQUEUE_ERROR];
 }
Example #29
0
function put_mail_queue($address, $subject, $body, $is_receive_mail = true, $from = ADMIN_EMAIL)
{
    if (!$is_receive_mail || !db_common_is_mailaddress($address)) {
        return false;
    }
    // 改行コード
    $cr = "\r";
    $lf = "\n";
    $crlf = "\r\n";
    // header
    $headers['MIME-Version'] = "1.0";
    $headers['Content-Type'] = "text/plain; charset=iso-2022-jp";
    $headers['From'] = $from;
    $headers['To'] = $address;
    // 半角カナを全角カナに変換
    if (MAIL_HAN2ZEN) {
        $subject = mb_convert_kana($subject, "KV");
        $body = mb_convert_kana($body, "KV");
    }
    // subject (改行コードを含んではならない)
    $subject = str_replace(array($cr, $lf), "", $subject);
    $subject = mb_convert_encoding($subject, "JIS");
    $headers['Subject'] = '=?ISO-2022-JP?B?' . base64_encode($subject) . '?=';
    // body (LF)
    if (MAIL_WRAP_WIDTH) {
        $body = t_wordwrap($body, MAIL_WRAP_WIDTH);
    }
    $body = mb_convert_encoding($body, "JIS");
    $body = str_replace($cr, $lf, str_replace($crlf, $lf, $body));
    include_once 'Mail/Queue.php';
    $db_opt = array("type" => "db", "dsn" => $GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn'], "mail_table" => "mail_queue");
    $mail_opt = array("driver" => "mail");
    if ($GLOBALS['_OPENPNE_DSN_LIST']['main']['dsn']['phptype'] === 'pgsql') {
        $db_opt['sequence'] = 'mail_queue_seq_id';
    }
    $mail_mime = new Mail_mime();
    $mail_mime->setTXTBody($body);
    $body = $mail_mime->get(array("text_charset" => "ISO-2022-JP"));
    $body = addslashes($body);
    $headers = $mail_mime->headers($headers);
    if (MAIL_SET_ENVFROM) {
        if (MAIL_ENVFROM) {
            $f = MAIL_ENVFROM;
        } else {
            $f = ADMIN_EMAIL;
        }
        $params = '-f' . escapeshellcmd($f);
        $mail_opt['param'] = $params;
        $mail_queue = new Mail_Queue($db_opt, $mail_opt);
        return $mail_queue->put($from, $address, $headers, $body);
    } else {
        $mail_queue = new Mail_Queue($db_opt, $mail_opt);
        return $mail_queue->put($from, $address, $headers, $body);
    }
}
/**
 * Selects a mail queue entry from the table and returns the contents.
 * 
 * @param   string $id The mail queue entry ID.
 * @return  A string containing the body.
 */
function getMailQueue($id)
{
    if (Auth::getCurrentRole() < User::getRoleID('Developer')) {
        return;
    }
    $res = Mail_Queue::getEntry($id);
    if (!empty($_GET["ec_id"])) {
        return Link_Filter::processText(Auth::getCurrentProject(), nl2br(htmlspecialchars($_GET["ec_id"] . ":" . $id . ":" . $res["maq_headers"] . "\n" . $res["maq_body"])));
    } else {
        return $res["maq_body"];
    }
}