/** * __construct * * Provide a uid, and parse message structure. * * @param string $uid The message UID. * * @uses rcmail::get_instance() * @uses rcube_imap::decode_mime_string() * @uses self::set_safe() * * @see self::$app, self::$imap, self::$opt, self::$structure */ function __construct($uid) { $this->app = rcmail::get_instance(); $this->imap = $this->app->imap; $this->imap->get_all_headers = true; $this->uid = $uid; $this->headers = $this->imap->get_headers($uid, NULL, true, true); if (!$this->headers) { return; } $this->subject = rcube_imap::decode_mime_string($this->headers->subject, $this->headers->charset); list(, $this->sender) = each($this->imap->decode_address_list($this->headers->from)); $this->set_safe(intval($_GET['_safe']) || $_SESSION['safe_messages'][$uid]); $this->opt = array('safe' => $this->is_safe, 'prefer_html' => $this->app->config->get('prefer_html'), 'get_url' => rcmail_url('get', array('_mbox' => $this->imap->get_mailbox_name(), '_uid' => $uid))); if ($this->structure = $this->imap->get_structure($uid, $this->headers->body_structure)) { $this->get_mime_numbers($this->structure); $this->parse_structure($this->structure); } else { $this->body = $this->imap->get_body($uid); } // notify plugins and let them analyze this structured message object $this->app->plugins->exec_hook('message_load', array('object' => $this)); }
/** * Checks wether recipients exist in any of the addressbooks. * * @param array $args Default hook parameters. * * @return void */ public function check_recipients($args) { $rcmail = rcmail::get_instance(); // don't process the sent message, if it's a 'Read Receipt' response if (isset($args['headers']['Content-Type']) && strpos($args['headers']['Content-Type'], 'report-type=disposition-notification') !== false) { return $args; } $rcube_imap = new rcube_imap(null); // build recipients array $recipients = $rcube_imap->decode_address_list($args['headers']['To']); if (isset($args['headers']['Cc'])) { $recipients = array_merge($recipients, $rcube_imap->decode_address_list($args['headers']['Cc'])); } if (isset($args['headers']['Bcc'])) { $recipients = array_merge($recipients, $rcube_imap->decode_address_list($args['headers']['Bcc'])); } // stores contacts that don't exist in current address books $new_contacts = array(); // iterate over recipients and search for them in address books foreach ($recipients as $recipient) { // flag to denote if the current recipient doesn't exist in any of the address books $is_new_contact = true; // if we dont want to list users in same domain as us for some reason // example: globaladdressbook plugin with all domain users inside if (!$this->rcmail->config->get('recipient_to_contact_addressbooks')) { // get current recipient domain $recipient_domain = preg_replace('/^[^@]*@(.*)$/', '$1', $recipient['mailto']); // get identity used to send email $identity = $rcmail->user->get_identity(); // get current identity domain $identity_domain = preg_replace('/^[^@]*@(.*)$/', '$1', $identity['email']); // check if recipient domain match with this identify domain // if match, continue loop and ignore recipient if ($recipient_domain == $identity_domain) { unset($recipient_domain); unset($identity); unset($identity_domain); $is_new_contact = false; continue; } } // interate over over address books and search for a contact with the same email address foreach ($this->addressbooks as $abook_id => $address_source) { $address_book = $this->rcmail->get_address_book($abook_id); $search_result = $address_book->search('email', $recipient['mailto']); // the contact already exist. skip the rest address books and move to next recipient if ($search_result->count > 0) { $is_new_contact = false; break; } } // store the non-existing recipient if ($is_new_contact) { $new_contacts[] = $recipient; } } if (!empty($new_contacts)) { $_SESSION['recipient_to_contact'] = $new_contacts; } }
/** * Collect the email address of a just-sent email recipients into * the automatic addressbook (if it's not already in another * addressbook). */ public function register_recipients($p) { $rcmail = rcmail::get_instance(); if (!$rcmail->config->get('use_auto_abook', true)) { return; } $headers = $p['headers']; if (!class_exists('rcube_mime')) { // RC < 0.8 compatibility code $IMAP = new rcube_imap(null); $all_recipients = array_merge($IMAP->decode_address_list($headers['To'], null, true, $headers['charset']), $IMAP->decode_address_list($headers['Cc'], null, true, $headers['charset']), $IMAP->decode_address_list($headers['Bcc'], null, true, $headers['charset'])); } else { $all_recipients = array_merge(rcube_mime::decode_address_list($headers['To'], null, true, $headers['charset']), rcube_mime::decode_address_list($headers['Cc'], null, true, $headers['charset']), rcube_mime::decode_address_list($headers['Bcc'], null, true, $headers['charset'])); } require_once dirname(__FILE__) . '/automatic_addressbook_backend.php'; $CONTACTS = new automatic_addressbook_backend($rcmail->db, $rcmail->user->ID); foreach ($all_recipients as $recipient) { // Bcc and Cc can be empty if ($recipient['mailto'] != '') { $contact = array('email' => $recipient['mailto'], 'name' => $recipient['name']); // use email address part for name if (empty($contact['name']) || $contact['name'] == $contact['email']) { $contact['name'] = ucfirst(preg_replace('/[\\.\\-]/', ' ', substr($contact['email'], 0, strpos($contact['email'], '@')))); } /* We only want to add the contact to the collected contacts * address book if it is not already in an addressbook, so we * first lookup in every address source. */ $book_types = (array) $rcmail->config->get('autocomplete_addressbooks', 'sql'); foreach ($book_types as $id) { $abook = $rcmail->get_address_book($id); $previous_entries = $abook->search('email', $contact['email'], false, false); if ($previous_entries->count) { break; } } if (!$previous_entries->count) { $plugin = $rcmail->plugins->exec_hook('contact_create', array('record' => $contact, 'source' => $this->abook_id)); if (!$plugin['abort']) { $CONTACTS->insert($contact, false); } } } } }
/** * Checks wether recipients exist in any of the addressbooks. * * @param array $args Default hook parameters. * * @return void */ public function check_recipients($args) { // don't process the sent message, if it's a 'Read Receipt' response if (isset($args['headers']['Content-Type']) && strpos($args['headers']['Content-Type'], 'report-type=disposition-notification') !== false) { return $args; } $rcube_imap = new rcube_imap(null); // build recipients array $recipients = $rcube_imap->decode_address_list($args['headers']['To']); if (isset($args['headers']['Cc'])) { $recipients = array_merge($recipients, $rcube_imap->decode_address_list($args['headers']['Cc'])); } if (isset($args['headers']['Bcc'])) { $recipients = array_merge($recipients, $rcube_imap->decode_address_list($args['headers']['Bcc'])); } // stores contacts that don't exist in current address books $new_contacts = array(); // iterate over recipients and search for them in address books foreach ($recipients as $recipient) { // flag to denote if the current recipient doesn't exist in any of the address books $is_new_contact = true; // interate over over address books and search for a contact with the same email address foreach ($this->addressbooks as $abook_id => $address_source) { $address_book = $this->rcmail->get_address_book($abook_id); $search_result = $address_book->search('email', $recipient['mailto']); // the contact already exist. skip the rest address books and move to next recipient if ($search_result->count > 0) { $is_new_contact = false; break; } } // store the non-existing recipient if ($is_new_contact) { $new_contacts[] = $recipient; } } if (!empty($new_contacts)) { $_SESSION['recipient_to_contact'] = $new_contacts; } }