Exemplo n.º 1
0
 /**
  * Return a list of all identities linked with this user
  *
  * @param string $sql_add   Optional WHERE clauses
  * @param bool   $formatted Format identity email and name
  *
  * @return array List of identities
  */
 function list_identities($sql_add = '', $formatted = false)
 {
     $result = array();
     $sql_result = $this->db->query("SELECT * FROM " . $this->db->table_name('identities') . " WHERE del <> 1 AND user_id = ?" . ($sql_add ? " " . $sql_add : "") . " ORDER BY " . $this->db->quote_identifier('standard') . " DESC, " . $this->db->quote_identifier('name') . " ASC, " . $this->db->quote_identifier('email') . " ASC, " . $this->db->quote_identifier('identity_id') . " ASC", $this->ID);
     while ($sql_arr = $this->db->fetch_assoc($sql_result)) {
         if ($formatted) {
             $ascii_email = format_email($sql_arr['email']);
             $utf8_email = format_email(rcube_utils::idn_to_utf8($ascii_email));
             $sql_arr['email_ascii'] = $ascii_email;
             $sql_arr['email'] = $utf8_email;
             $sql_arr['ident'] = format_email_recipient($ascii_email, $sql_arr['name']);
         }
         $result[] = $sql_arr;
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Render a HTML select box for user identity selection
  */
 function identity_select($attrib = array())
 {
     $attrib['name'] = 'identity';
     $select = new html_select($attrib);
     $identities = $this->rc->user->list_emails();
     foreach ($identities as $ident) {
         $select->add(format_email_recipient($ident['email'], $ident['name']), $ident['identity_id']);
     }
     return $select->show(null);
 }
 protected function _rcmail_get_identity($id)
 {
     $rcmail = rcube::get_instance();
     if ($sql_arr = $rcmail->user->get_identity($id)) {
         $out = $sql_arr;
         $out['mailto'] = $sql_arr['email'];
         $out['string'] = format_email_recipient($sql_arr['email'], rcube_charset::convert($sql_arr['name'], RCUBE_CHARSET, $this->api->output->get_charset()));
         if ($rcmail->config->get('sieverules_from_format', 0) == 1) {
             $out['disp_string'] = $out['string'];
             $out['val_string'] = $out['string'];
         } else {
             $out['disp_string'] = $out['mailto'];
             $out['val_string'] = $out['mailto'];
         }
         return $out;
     }
     return false;
 }
 /**
  * Helper function to build a Mail_mime object to send an iTip message
  *
  * @param array   Event object to send
  * @param string  iTip method (REQUEST|REPLY|CANCEL)
  * @param boolean Request RSVP
  * @return object Mail_mime object with message data
  */
 public function compose_itip_message($event, $method, $rsvp = true)
 {
     $from = rcube_utils::idn_to_ascii($this->sender['email']);
     $from_utf = rcube_utils::idn_to_utf8($from);
     $sender = format_email_recipient($from, $this->sender['name']);
     // truncate list attendees down to the recipient of the iTip Reply.
     // constraints for a METHOD:REPLY according to RFC 5546
     if ($method == 'REPLY') {
         $replying_attendee = null;
         $reply_attendees = array();
         foreach ($event['attendees'] as $attendee) {
             if ($attendee['role'] == 'ORGANIZER') {
                 $reply_attendees[] = $attendee;
             } else {
                 if (strcasecmp($attendee['email'], $from) == 0 || strcasecmp($attendee['email'], $from_utf) == 0) {
                     $replying_attendee = $attendee;
                     if ($attendee['status'] != 'DELEGATED') {
                         unset($replying_attendee['rsvp']);
                         // unset the RSVP attribute
                     }
                 } else {
                     if (!empty($attendee['delegated-to']) && (strcasecmp($attendee['delegated-to'], $from) == 0 || strcasecmp($attendee['delegated-to'], $from_utf) == 0) || !empty($attendee['delegated-from']) && (strcasecmp($attendee['delegated-from'], $from) == 0 || strcasecmp($attendee['delegated-from'], $from_utf) == 0)) {
                         $reply_attendees[] = $attendee;
                     }
                 }
             }
         }
         if ($replying_attendee) {
             array_unshift($reply_attendees, $replying_attendee);
             $event['attendees'] = $reply_attendees;
         }
         if ($event['recurrence']) {
             unset($event['recurrence']['EXCEPTIONS']);
         }
     } else {
         if ($method == 'REQUEST') {
             foreach ($event['attendees'] as $i => $attendee) {
                 if (($rsvp || !isset($attendee['rsvp'])) && ($attendee['status'] != 'DELEGATED' && $attendee['role'] != 'NON-PARTICIPANT')) {
                     $event['attendees'][$i]['rsvp'] = (bool) $rsvp;
                 }
             }
         } else {
             if ($method == 'CANCEL') {
                 if ($event['recurrence']) {
                     unset($event['recurrence']['EXCEPTIONS']);
                 }
             }
         }
     }
     // compose multipart message using PEAR:Mail_Mime
     $message = new Mail_mime("\r\n");
     $message->setParam('text_encoding', 'quoted-printable');
     $message->setParam('head_encoding', 'quoted-printable');
     $message->setParam('head_charset', RCUBE_CHARSET);
     $message->setParam('text_charset', RCUBE_CHARSET . ";\r\n format=flowed");
     $message->setContentType('multipart/alternative');
     // compose common headers array
     $headers = array('From' => $sender, 'Date' => $this->rc->user_date(), 'Message-ID' => $this->rc->gen_message_id(), 'X-Sender' => $from);
     if ($agent = $this->rc->config->get('useragent')) {
         $headers['User-Agent'] = $agent;
     }
     $message->headers($headers);
     // attach ics file for this event
     $ical = libcalendaring::get_ical();
     $ics = $ical->export(array($event), $method, false, $method == 'REQUEST' && $this->plugin->driver ? array($this->plugin->driver, 'get_attachment_body') : false);
     $filename = $event['_type'] == 'task' ? 'todo.ics' : 'event.ics';
     $message->addAttachment($ics, 'text/calendar', $filename, false, '8bit', '', RCUBE_CHARSET . "; method=" . $method);
     return $message;
 }
Exemplo n.º 5
0
 /**
  * Helper function to build a Mail_mime object to send an iTip message
  *
  * @param array   Event object to send
  * @param string  iTip method (REQUEST|REPLY|CANCEL)
  * @return object Mail_mime object with message data
  */
 public function compose_itip_message($event, $method)
 {
     $from = rcube_idn_to_ascii($this->sender['email']);
     $from_utf = rcube_idn_to_utf8($from);
     $sender = format_email_recipient($from, $this->sender['name']);
     // truncate list attendees down to the recipient of the iTip Reply.
     // constraints for a METHOD:REPLY according to RFC 5546
     if ($method == 'REPLY') {
         $replying_attendee = null;
         $reply_attendees = array();
         foreach ($event['attendees'] as $attendee) {
             if ($attendee['role'] == 'ORGANIZER') {
                 $reply_attendees[] = $attendee;
             } else {
                 if (strcasecmp($attedee['email'], $from) == 0 || strcasecmp($attendee['email'], $from_utf) == 0) {
                     $replying_attendee = $attendee;
                 }
             }
         }
         if ($replying_attendee) {
             $reply_attendees[] = $replying_attendee;
             $event['attendees'] = $reply_attendees;
         }
     }
     // compose multipart message using PEAR:Mail_Mime
     $message = new Mail_mime("\r\n");
     $message->setParam('text_encoding', 'quoted-printable');
     $message->setParam('head_encoding', 'quoted-printable');
     $message->setParam('head_charset', RCMAIL_CHARSET);
     $message->setParam('text_charset', RCMAIL_CHARSET . ";\r\n format=flowed");
     $message->setContentType('multipart/alternative');
     // compose common headers array
     $headers = array('From' => $sender, 'Date' => $this->rc->user_date(), 'Message-ID' => $this->rc->gen_message_id(), 'X-Sender' => $from);
     if ($agent = $this->rc->config->get('useragent')) {
         $headers['User-Agent'] = $agent;
     }
     $message->headers($headers);
     // attach ics file for this event
     $ical = $this->cal->get_ical();
     $ics = $ical->export(array($event), $method, false, $method == 'REQUEST' ? array($this->cal->driver, 'get_attachment_body') : false);
     $message->addAttachment($ics, 'text/calendar', 'event.ics', false, '8bit', '', RCMAIL_CHARSET . "; method=" . $method);
     return $message;
 }
 private function _do_emaillearn($uids, $spam)
 {
     $rcmail = rcube::get_instance();
     $identity_arr = $rcmail->user->get_identity();
     $from = $identity_arr['email'];
     if ($spam) {
         $mailto = $rcmail->config->get('markasjunk2_email_spam');
     } else {
         $mailto = $rcmail->config->get('markasjunk2_email_ham');
     }
     $mailto = str_replace('%u', $_SESSION['username'], $mailto);
     $mailto = str_replace('%l', $rcmail->user->get_username('local'), $mailto);
     $mailto = str_replace('%d', $rcmail->user->get_username('domain'), $mailto);
     $mailto = str_replace('%i', $from, $mailto);
     if (!$mailto) {
         return;
     }
     $message_charset = $rcmail->output->get_charset();
     // chose transfer encoding
     $charset_7bit = array('ASCII', 'ISO-2022-JP', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-15');
     $transfer_encoding = in_array(strtoupper($message_charset), $charset_7bit) ? '7bit' : '8bit';
     $temp_dir = realpath($rcmail->config->get('temp_dir'));
     $subject = $rcmail->config->get('markasjunk2_email_subject');
     $subject = str_replace('%u', $_SESSION['username'], $subject);
     $subject = str_replace('%t', $spam ? 'spam' : 'ham', $subject);
     $subject = str_replace('%l', $rcmail->user->get_username('local'), $subject);
     $subject = str_replace('%d', $rcmail->user->get_username('domain'), $subject);
     // compose headers array
     $headers = array();
     $headers['Date'] = date('r');
     $headers['From'] = format_email_recipient($identity_arr['email'], $identity_arr['name']);
     $headers['To'] = $mailto;
     $headers['Subject'] = $subject;
     foreach ($uids as $uid) {
         $MESSAGE = new rcube_message($uid);
         // set message charset as default
         if (!empty($MESSAGE->headers->charset)) {
             $rcmail->storage->set_charset($MESSAGE->headers->charset);
         }
         $MAIL_MIME = new Mail_mime($rcmail->config->header_delimiter());
         if ($rcmail->config->get('markasjunk2_email_attach', false)) {
             $tmpPath = tempnam($temp_dir, 'rcmMarkASJunk2');
             // send mail as attachment
             $MAIL_MIME->setTXTBody(($spam ? 'Spam' : 'Ham') . ' report from ' . $rcmail->config->get('product_name'), false, true);
             $raw_message = $rcmail->storage->get_raw_body($uid);
             $subject = $MESSAGE->get_header('subject');
             if (isset($subject) && $subject != "") {
                 $disp_name = $subject . ".eml";
             } else {
                 $disp_name = "message_rfc822.eml";
             }
             if (file_put_contents($tmpPath, $raw_message)) {
                 $MAIL_MIME->addAttachment($tmpPath, "message/rfc822", $disp_name, true, $transfer_encoding, 'attachment', '', '', '', $rcmail->config->get('mime_param_folding') ? 'quoted-printable' : NULL, $rcmail->config->get('mime_param_folding') == 2 ? 'quoted-printable' : NULL, '', RCUBE_CHARSET);
             }
             // encoding settings for mail composing
             $MAIL_MIME->setParam('text_encoding', $transfer_encoding);
             $MAIL_MIME->setParam('html_encoding', 'quoted-printable');
             $MAIL_MIME->setParam('head_encoding', 'quoted-printable');
             $MAIL_MIME->setParam('head_charset', $message_charset);
             $MAIL_MIME->setParam('html_charset', $message_charset);
             $MAIL_MIME->setParam('text_charset', $message_charset);
             // pass headers to message object
             $MAIL_MIME->headers($headers);
         } else {
             $headers['Resent-From'] = $headers['From'];
             $headers['Resent-Date'] = $headers['Date'];
             $headers['Date'] = $MESSAGE->headers->date;
             $headers['From'] = $MESSAGE->headers->from;
             $headers['Subject'] = $MESSAGE->headers->subject;
             $MAIL_MIME->headers($headers);
             if ($MESSAGE->has_html_part()) {
                 $body = $MESSAGE->first_html_part();
                 $MAIL_MIME->setHTMLBody($body);
             }
             $body = $MESSAGE->first_text_part();
             $MAIL_MIME->setTXTBody($body, false, true);
             foreach ($MESSAGE->attachments as $attachment) {
                 $MAIL_MIME->addAttachment($MESSAGE->get_part_body($attachment->mime_id, true), $attachment->mimetype, $attachment->filename, false, $attachment->encoding, $attachment->disposition, '', $attachment->charset);
             }
             foreach ($MESSAGE->mime_parts as $attachment) {
                 if (!empty($attachment->content_id)) {
                     // covert CID to Mail_MIME format
                     $attachment->content_id = str_replace('<', '', $attachment->content_id);
                     $attachment->content_id = str_replace('>', '', $attachment->content_id);
                     if (empty($attachment->filename)) {
                         $attachment->filename = $attachment->content_id;
                     }
                     $message_body = $MAIL_MIME->getHTMLBody();
                     $dispurl = 'cid:' . $attachment->content_id;
                     $message_body = str_replace($dispurl, $attachment->filename, $message_body);
                     $MAIL_MIME->setHTMLBody($message_body);
                     $MAIL_MIME->addHTMLImage($MESSAGE->get_part_body($attachment->mime_id, true), $attachment->mimetype, $attachment->filename, false);
                 }
             }
             // encoding settings for mail composing
             $MAIL_MIME->setParam('head_encoding', $MESSAGE->headers->encoding);
             $MAIL_MIME->setParam('head_charset', $MESSAGE->headers->charset);
             foreach ($MESSAGE->mime_parts as $mime_id => $part) {
                 $mimetype = strtolower($part->ctype_primary . '/' . $part->ctype_secondary);
                 if ($mimetype == 'text/html') {
                     $MAIL_MIME->setParam('text_encoding', $part->encoding);
                     $MAIL_MIME->setParam('html_charset', $part->charset);
                 } else {
                     if ($mimetype == 'text/plain') {
                         $MAIL_MIME->setParam('html_encoding', $part->encoding);
                         $MAIL_MIME->setParam('text_charset', $part->charset);
                     }
                 }
             }
         }
         $rcmail->deliver_message($MAIL_MIME, $from, $mailto, $smtp_error, $body_file);
         // clean up
         if (file_exists($tmpPath)) {
             unlink($tmpPath);
         }
         if ($rcmail->config->get('markasjunk2_debug')) {
             if ($spam) {
                 rcube::write_log('markasjunk2', $uid . ' SPAM ' . $mailto . ' (' . $subject . ')');
             } else {
                 rcube::write_log('markasjunk2', $uid . ' HAM ' . $mailto . ' (' . $subject . ')');
             }
             if ($smtp_error['vars']) {
                 rcube::write_log('markasjunk2', $smtp_error['vars']);
             }
         }
     }
 }
Exemplo n.º 7
0
 /**
  * rcube_shared.inc: format_email_recipient()
  */
 function test_format_email_recipient()
 {
     $data = array('' => array(''), 'test' => array('test'), '*****@*****.**' => array('*****@*****.**'), 'test@[127.0.0.1]' => array('test@[127.0.0.1]'), '*****@*****.**' => array('*****@*****.**'), 'TEST <*****@*****.**>' => array('*****@*****.**', 'TEST'), '"TEST\\"" <*****@*****.**>' => array('*****@*****.**', 'TEST"'));
     foreach ($data as $expected => $value) {
         $result = format_email_recipient($value[0], $value[1]);
         $this->assertEquals($expected, $result, "Invalid format_email_recipient()");
     }
 }