/**
  * Function which clones current occurrence and sets appropriate properties.
  * The original recurring item is moved to next occurrence.
  *@param boolean $markComplete true if existing occurrence has to be mark complete else false.
  */
 function regenerateTask($markComplete)
 {
     // Get all properties
     $taskItemProps = mapi_getprops($this->message);
     if (isset($this->action["subject"])) {
         $taskItemProps[$this->proptags["subject"]] = $this->action["subject"];
     }
     if (isset($this->action["importance"])) {
         $taskItemProps[$this->proptags["importance"]] = $this->action["importance"];
     }
     if (isset($this->action["startdate"])) {
         $taskItemProps[$this->proptags["startdate"]] = $this->action["startdate"];
         $taskItemProps[$this->proptags["commonstart"]] = $this->action["startdate"];
     }
     if (isset($this->action["duedate"])) {
         $taskItemProps[$this->proptags["duedate"]] = $this->action["duedate"];
         $taskItemProps[$this->proptags["commonend"]] = $this->action["duedate"];
     }
     $folder = mapi_msgstore_openentry($this->store, $taskItemProps[PR_PARENT_ENTRYID]);
     $newMessage = mapi_folder_createmessage($folder);
     $taskItemProps[$this->proptags["status"]] = $markComplete ? olTaskComplete : olTaskNotStarted;
     $taskItemProps[$this->proptags["complete"]] = $markComplete;
     $taskItemProps[$this->proptags["percent_complete"]] = $markComplete ? 1 : 0;
     // This occurrence has been marked as 'Complete' so disable reminder
     if ($markComplete) {
         $taskItemProps[$this->proptags["reset_reminder"]] = false;
         $taskItemProps[$this->proptags["reminder"]] = false;
         $taskItemProps[$this->proptags["datecompleted"]] = $this->action["datecompleted"];
         unset($this->action[$this->proptags['datecompleted']]);
     }
     // Recurrence ends for this item
     $taskItemProps[$this->proptags["dead_occurrence"]] = true;
     $taskItemProps[$this->proptags["task_f_creator"]] = true;
     //OL props
     $taskItemProps[$this->proptags["side_effects"]] = 1296;
     $taskItemProps[$this->proptags["icon_index"]] = 1280;
     // Copy recipients
     $recipienttable = mapi_message_getrecipienttable($this->message);
     $recipients = mapi_table_queryallrows($recipienttable, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_EMAIL_ADDRESS, PR_RECIPIENT_ENTRYID, PR_RECIPIENT_TYPE, PR_SEND_INTERNET_ENCODING, PR_SEND_RICH_INFO, PR_RECIPIENT_DISPLAY_NAME, PR_ADDRTYPE, PR_DISPLAY_TYPE, PR_RECIPIENT_TRACKSTATUS, PR_RECIPIENT_TRACKSTATUS_TIME, PR_RECIPIENT_FLAGS, PR_ROWID));
     $copy_to_recipientTable = mapi_message_getrecipienttable($newMessage);
     $copy_to_recipientRows = mapi_table_queryallrows($copy_to_recipientTable, array(PR_ROWID));
     foreach ($copy_to_recipientRows as $recipient) {
         mapi_message_modifyrecipients($newMessage, MODRECIP_REMOVE, array($recipient));
     }
     mapi_message_modifyrecipients($newMessage, MODRECIP_ADD, $recipients);
     // Copy attachments
     $attachmentTable = mapi_message_getattachmenttable($this->message);
     if ($attachmentTable) {
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD));
         foreach ($attachments as $attach_props) {
             $attach_old = mapi_message_openattach($this->message, (int) $attach_props[PR_ATTACH_NUM]);
             $attach_newResourceMsg = mapi_message_createattach($newMessage);
             mapi_copyto($attach_old, array(), array(), $attach_newResourceMsg, 0);
             mapi_savechanges($attach_newResourceMsg);
         }
     }
     mapi_setprops($newMessage, $taskItemProps);
     mapi_savechanges($newMessage);
     // Update body of original message
     $msgbody = mapi_message_openproperty($this->message, PR_BODY);
     $msgbody = trim($this->windows1252_to_utf8($msgbody), "");
     $separator = "------------\r\n";
     if (!empty($msgbody) && strrpos($msgbody, $separator) === false) {
         $msgbody = $separator . $msgbody;
         $stream = mapi_openpropertytostream($this->message, PR_BODY, MAPI_CREATE | MAPI_MODIFY);
         mapi_stream_setsize($stream, strlen($msgbody));
         mapi_stream_write($stream, $msgbody);
         mapi_stream_commit($stream);
     }
     // We need these properties to notify client
     return mapi_getprops($newMessage, array(PR_ENTRYID, PR_PARENT_ENTRYID, PR_STORE_ENTRYID));
 }
 /**
  * Function which replaces attachments with copy_from in copy_to.
  *@param resource $copy_from MAPI_message from which attachments are to be copied.
  *@param resource $copy_to MAPI_message to which attachment are to be copied.
  *@param boolean $copyExceptions if true then all exceptions should also be sent as attachments
  */
 function replaceAttachments($copy_from, $copy_to, $copyExceptions = true)
 {
     /* remove all old attachments */
     $attachmentTable = mapi_message_getattachmenttable($copy_to);
     if ($attachmentTable) {
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_METHOD, PR_EXCEPTION_STARTTIME));
         foreach ($attachments as $attach_props) {
             /* remove exceptions too? */
             if (!$copyExceptions && $attach_props[PR_ATTACH_METHOD] == 5 && isset($attach_props[PR_EXCEPTION_STARTTIME])) {
                 continue;
             }
             mapi_message_deleteattach($copy_to, $attach_props[PR_ATTACH_NUM]);
         }
     }
     $attachmentTable = false;
     /* copy new attachments */
     $attachmentTable = mapi_message_getattachmenttable($copy_from);
     if ($attachmentTable) {
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_METHOD, PR_EXCEPTION_STARTTIME));
         foreach ($attachments as $attach_props) {
             if (!$copyExceptions && $attach_props[PR_ATTACH_METHOD] == 5 && isset($attach_props[PR_EXCEPTION_STARTTIME])) {
                 continue;
             }
             $attach_old = mapi_message_openattach($copy_from, (int) $attach_props[PR_ATTACH_NUM]);
             $attach_newResourceMsg = mapi_message_createattach($copy_to);
             mapi_copyto($attach_old, array(), array(), $attach_newResourceMsg, 0);
             mapi_savechanges($attach_newResourceMsg);
         }
     }
 }
示例#3
0
 /**
  * Get an exception attachment based on its basedate
  */
 function getExceptionAttachment($base_date)
 {
     // Retrieve only embedded messages
     $attach_res = array(RES_AND, array(array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_ATTACH_METHOD, VALUE => array(PR_ATTACH_METHOD => 5)))));
     $attachments = mapi_message_getattachmenttable($this->message);
     $attachRows = mapi_table_queryallrows($attachments, array(PR_ATTACH_NUM), $attach_res);
     if (is_array($attachRows)) {
         foreach ($attachRows as $attachRow) {
             $tempattach = mapi_message_openattach($this->message, $attachRow[PR_ATTACH_NUM]);
             $exception = mapi_attach_openobj($tempattach);
             $data = mapi_message_getprops($exception, array($this->proptags["basedate"]));
             if (isset($data[$this->proptags["basedate"]]) && $this->isSameDay($this->fromGMT($this->tz, $data[$this->proptags["basedate"]]), $base_date)) {
                 return $tempattach;
             }
         }
     }
     return false;
 }
示例#4
0
 /**
  * Copies attachments from one message to another.
  *
  * @param MAPIMessage $toMessage
  * @param MAPIMessage $fromMessage
  *
  * @return void
  */
 private function copyAttachments(&$toMessage, $fromMessage)
 {
     $attachtable = mapi_message_getattachmenttable($fromMessage);
     $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
     foreach ($rows as $row) {
         if (isset($row[PR_ATTACH_NUM])) {
             $attach = mapi_message_openattach($fromMessage, $row[PR_ATTACH_NUM]);
             $newattach = mapi_message_createattach($toMessage);
             // Copy all attachments from old to new attachment
             $attachprops = mapi_getprops($attach);
             mapi_setprops($newattach, $attachprops);
             if (isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
                 // Data is in a stream
                 $srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
                 $dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
                 while (1) {
                     $data = mapi_stream_read($srcstream, 4096);
                     if (strlen($data) == 0) {
                         break;
                     }
                     mapi_stream_write($dststream, $data);
                 }
                 mapi_stream_commit($dststream);
             }
             mapi_savechanges($newattach);
         }
     }
 }
示例#5
0
function buildEMLAttachment($attach)
{
    $msgembedded = mapi_attach_openobj($attach);
    $msgprops = mapi_getprops($msgembedded, array(PR_MESSAGE_CLASS, PR_CLIENT_SUBMIT_TIME, PR_DISPLAY_TO, PR_SUBJECT, PR_SENT_REPRESENTING_NAME, PR_SENT_REPRESENTING_EMAIL_ADDRESS));
    $msgembeddedrcpttable = mapi_message_getrecipienttable($msgembedded);
    $msgto = $msgprops[PR_DISPLAY_TO];
    if ($msgembeddedrcpttable) {
        $msgembeddedrecipients = mapi_table_queryrows($msgembeddedrcpttable, array(PR_ADDRTYPE, PR_ENTRYID, PR_DISPLAY_NAME, PR_EMAIL_ADDRESS, PR_SMTP_ADDRESS, PR_RECIPIENT_TYPE, PR_RECIPIENT_FLAGS, PR_PROPOSEDNEWTIME, PR_PROPOSENEWTIME_START, PR_PROPOSENEWTIME_END, PR_RECIPIENT_TRACKSTATUS), 0, 99999999);
        foreach ($msgembeddedrecipients as $rcpt) {
            if ($rcpt[PR_DISPLAY_NAME] == $msgprops[PR_DISPLAY_TO]) {
                $msgto = $rcpt[PR_DISPLAY_NAME];
                if (isset($rcpt[PR_EMAIL_ADDRESS]) && $rcpt[PR_EMAIL_ADDRESS] != $msgprops[PR_DISPLAY_TO]) {
                    $msgto .= " <" . $rcpt[PR_EMAIL_ADDRESS] . ">";
                }
                break;
            }
        }
    }
    $msgsubject = $msgprops[PR_SUBJECT];
    $msgfrom = $msgprops[PR_SENT_REPRESENTING_NAME];
    if (isset($msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS]) && $msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS] != $msgprops[PR_SENT_REPRESENTING_NAME]) {
        $msgfrom .= " <" . $msgprops[PR_SENT_REPRESENTING_EMAIL_ADDRESS] . ">";
    }
    $msgtime = $msgprops[PR_CLIENT_SUBMIT_TIME];
    $msgembeddedbody = eml_ReadMessage($msgembedded);
    $msgembeddedattachtable = mapi_message_getattachmenttable($msgembedded);
    $msgembeddedattachtablerows = mapi_table_queryallrows($msgembeddedattachtable, array(PR_ATTACH_NUM, PR_ATTACH_METHOD));
    if ($msgembeddedattachtablerows) {
        $boundary = '=_zpush_static';
        $headercontenttype = "multipart/mixed";
        $msgembeddedbody['body'] = "Unfortunately your mobile is not able to handle MIME Messages\n" . "--" . $boundary . "\n" . "Content-Type: " . $msgembeddedbody['content'] . "; charset=utf-8\n" . "Content-Transfer-Encoding: quoted-printable\n\n" . $msgembeddedbody['body'] . "\n";
        foreach ($msgembeddedattachtablerows as $msgembeddedattachtablerow) {
            $msgembeddedattach = mapi_message_openattach($msgembedded, $msgembeddedattachtablerow[PR_ATTACH_NUM]);
            if (!$msgembeddedattach) {
                debugLog("Unable to open attachment number {$attachnum}");
            } else {
                $msgembeddedattachprops = mapi_getprops($msgembeddedattach, array(PR_ATTACH_MIME_TAG, PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_DISPLAY_NAME));
                if (isset($msgembeddedattachprops[PR_ATTACH_LONG_FILENAME])) {
                    $attachfilename = w2u($msgembeddedattachprops[PR_ATTACH_LONG_FILENAME]);
                } else {
                    if (isset($msgembeddedattachprops[PR_ATTACH_FILENAME])) {
                        $attachfilename = w2u($msgembeddedattachprops[PR_ATTACH_FILENAME]);
                    } else {
                        if (isset($msgembeddedattachprops[PR_DISPLAY_NAME])) {
                            $attachfilename = w2u($msgembeddedattachprops[PR_DISPLAY_NAME]);
                        } else {
                            $attachfilename = w2u("untitled");
                        }
                    }
                }
                if ($msgembeddedattachtablerow[PR_ATTACH_METHOD] == ATTACH_EMBEDDED_MSG) {
                    $attachfilename .= w2u(".eml");
                }
                $msgembeddedbody['body'] .= "--" . $boundary . "\n" . "Content-Type: " . $msgembeddedattachprops[PR_ATTACH_MIME_TAG] . ";\n" . " name=\"" . $attachfilename . "\"\n" . "Content-Transfer-Encoding: base64\n" . "Content-Disposition: attachment;\n" . " filename=\"" . $attachfilename . "\"\n\n";
                $msgembeddedattachstream = mapi_openpropertytostream($msgembeddedattach, PR_ATTACH_DATA_BIN);
                $msgembeddedattachment = "";
                while (1) {
                    $msgembeddedattachdata = mapi_stream_read($msgembeddedattachstream, 4096);
                    if (byte_strlen($msgembeddedattachdata) == 0) {
                        break;
                    }
                    $msgembeddedattachment .= $msgembeddedattachdata;
                }
                $msgembeddedbody['body'] .= chunk_split(base64_encode($msgembeddedattachment)) . "\n";
                unset($msgembeddedattachment);
            }
        }
        $msgembeddedbody['body'] .= "--" . $boundary . "--\n";
    } else {
        $headercontenttype = $msgembeddedbody['content'] . "; charset=utf-8";
        $boundary = '';
    }
    $msgembeddedheader = "Subject: " . $msgsubject . "\n" . "From: " . $msgfrom . "\n" . "To: " . $msgto . "\n" . "Date: " . gmstrftime("%a, %d %b %Y %T +0000", $msgprops[PR_CLIENT_SUBMIT_TIME]) . "\n" . "MIME-Version: 1.0\n" . "Content-Type: " . $headercontenttype . ";\n" . ($boundary ? " boundary=\"" . $boundary . "\"\n" : "") . "\n";
    $stream = mapi_stream_create();
    mapi_stream_setsize($stream, byte_strlen($msgembeddedheader . $msgembeddedbody['body']));
    mapi_stream_write($stream, $msgembeddedheader . $msgembeddedbody['body']);
    mapi_stream_seek($stream, 0, STREAM_SEEK_SET);
    return $stream;
}
示例#6
0
文件: ics.php 项目: nnaannoo/paskot
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     if (WBXML_DEBUG == true) {
         debugLog("SendMail: forward: {$forward}   reply: {$reply}   parent: {$parent}\n" . $rfc822);
     }
     $mimeParams = array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8');
     $mimeObject = new Mail_mimeDecode($rfc822);
     $message = $mimeObject->decode($mimeParams);
     // Open the outbox and create the message there
     $storeprops = mapi_getprops($this->_defaultstore, array(PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID));
     if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID])) {
         debugLog("Outbox not found to create message");
         return false;
     }
     $outbox = mapi_msgstore_openentry($this->_defaultstore, $storeprops[PR_IPM_OUTBOX_ENTRYID]);
     if (!$outbox) {
         debugLog("Unable to open outbox");
         return false;
     }
     $mapimessage = mapi_folder_createmessage($outbox);
     mapi_setprops($mapimessage, array(PR_SUBJECT => u2wi(isset($message->headers["subject"]) ? $message->headers["subject"] : ""), PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID], PR_MESSAGE_CLASS => "IPM.Note", PR_MESSAGE_DELIVERY_TIME => time()));
     if (isset($message->headers["x-priority"])) {
         switch ($message->headers["x-priority"]) {
             case 1:
             case 2:
                 $priority = PRIO_URGENT;
                 $importance = IMPORTANCE_HIGH;
                 break;
             case 4:
             case 5:
                 $priority = PRIO_NONURGENT;
                 $importance = IMPORTANCE_LOW;
                 break;
             case 3:
             default:
                 $priority = PRIO_NORMAL;
                 $importance = IMPORTANCE_NORMAL;
                 break;
         }
         mapi_setprops($mapimessage, array(PR_IMPORTANCE => $importance, PR_PRIORITY => $priority));
     }
     $addresses = array();
     $toaddr = $ccaddr = $bccaddr = array();
     $Mail_RFC822 = new Mail_RFC822();
     if (isset($message->headers["to"])) {
         $toaddr = $Mail_RFC822->parseAddressList($message->headers["to"]);
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = $Mail_RFC822->parseAddressList($message->headers["cc"]);
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = $Mail_RFC822->parseAddressList($message->headers["bcc"]);
     }
     // Add recipients
     $recips = array();
     if (isset($toaddr)) {
         foreach (array(MAPI_TO => $toaddr, MAPI_CC => $ccaddr, MAPI_BCC => $bccaddr) as $type => $addrlist) {
             foreach ($addrlist as $addr) {
                 $mapirecip[PR_ADDRTYPE] = "SMTP";
                 $mapirecip[PR_EMAIL_ADDRESS] = $addr->mailbox . "@" . $addr->host;
                 if (isset($addr->personal) && strlen($addr->personal) > 0) {
                     $mapirecip[PR_DISPLAY_NAME] = u2wi($addr->personal);
                 } else {
                     $mapirecip[PR_DISPLAY_NAME] = $mapirecip[PR_EMAIL_ADDRESS];
                 }
                 $mapirecip[PR_RECIPIENT_TYPE] = $type;
                 $mapirecip[PR_ENTRYID] = mapi_createoneoff($mapirecip[PR_DISPLAY_NAME], $mapirecip[PR_ADDRTYPE], $mapirecip[PR_EMAIL_ADDRESS]);
                 array_push($recips, $mapirecip);
             }
         }
     }
     mapi_message_modifyrecipients($mapimessage, 0, $recips);
     // Loop through message subparts.
     $body = "";
     $body_html = "";
     if ($message->ctype_primary == "multipart" && ($message->ctype_secondary == "mixed" || $message->ctype_secondary == "alternative")) {
         $mparts = $message->parts;
         for ($i = 0; $i < count($mparts); $i++) {
             $part = $mparts[$i];
             // palm pre & iPhone send forwarded messages in another subpart which are also parsed
             if ($part->ctype_primary == "multipart" && ($part->ctype_secondary == "mixed" || $part->ctype_secondary == "alternative" || $part->ctype_secondary == "related")) {
                 foreach ($part->parts as $spart) {
                     $mparts[] = $spart;
                 }
                 continue;
             }
             // standard body
             if ($part->ctype_primary == "text" && $part->ctype_secondary == "plain" && isset($part->body) && (!isset($part->disposition) || $part->disposition != "attachment")) {
                 $body .= u2wi($part->body);
                 // assume only one text body
             } elseif ($part->ctype_primary == "text" && $part->ctype_secondary == "html") {
                 $body_html .= u2wi($part->body);
             } elseif ($part->ctype_primary == "ms-tnef" || $part->ctype_secondary == "ms-tnef") {
                 $zptnef = new ZPush_tnef($this->_defaultstore);
                 $mapiprops = array();
                 $zptnef->extractProps($part->body, $mapiprops);
                 if (is_array($mapiprops) && !empty($mapiprops)) {
                     //check if it is a recurring item
                     $tnefrecurr = GetPropIDFromString($this->_defaultstore, "PT_BOOLEAN:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x5");
                     if (isset($mapiprops[$tnefrecurr])) {
                         $this->_handleRecurringItem($mapimessage, $mapiprops);
                     }
                     mapi_setprops($mapimessage, $mapiprops);
                 } else {
                     debugLog("TNEF: Mapi props array was empty");
                 }
             } elseif ($part->ctype_primary == "text" && $part->ctype_secondary == "calendar") {
                 $zpical = new ZPush_ical($this->_defaultstore);
                 $mapiprops = array();
                 $zpical->extractProps($part->body, $mapiprops);
                 // iPhone sends a second ICS which we ignore if we can
                 if (!isset($mapiprops[PR_MESSAGE_CLASS]) && strlen(trim($body)) == 0) {
                     debugLog("Secondary iPhone response is being ignored!! Mail dropped!");
                     return true;
                 }
                 if (!checkMapiExtVersion("6.30") && is_array($mapiprops) && !empty($mapiprops)) {
                     mapi_setprops($mapimessage, $mapiprops);
                 } else {
                     // store ics as attachment
                     //see icalTimezoneFix function in compat.php for more information
                     $part->body = icalTimezoneFix($part->body);
                     $this->_storeAttachment($mapimessage, $part);
                     debugLog("Sending ICS file as attachment");
                 }
             } else {
                 $this->_storeAttachment($mapimessage, $part);
             }
         }
     } else {
         if ($message->ctype_primary == "text" && $message->ctype_secondary == "html") {
             $body_html .= u2wi($message->body);
         } else {
             $body = u2wi($message->body);
         }
     }
     // some devices only transmit a html body
     if (strlen($body) == 0 && strlen($body_html) > 0) {
         debugLog("only html body sent, transformed into plain text");
         $body = strip_tags($body_html);
     }
     if ($forward) {
         $orig = $forward;
     }
     if ($reply) {
         $orig = $reply;
     }
     if (isset($orig) && $orig) {
         // Append the original text body for reply/forward
         $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig));
         $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid);
         if ($fwmessage) {
             //update icon when forwarding or replying message
             if ($forward) {
                 mapi_setprops($fwmessage, array(PR_ICON_INDEX => 262));
             } elseif ($reply) {
                 mapi_setprops($fwmessage, array(PR_ICON_INDEX => 261));
             }
             mapi_savechanges($fwmessage);
             $stream = mapi_openproperty($fwmessage, PR_BODY, IID_IStream, 0, 0);
             $fwbody = "";
             while (1) {
                 $data = mapi_stream_read($stream, 1024);
                 if (strlen($data) == 0) {
                     break;
                 }
                 $fwbody .= $data;
             }
             $stream = mapi_openproperty($fwmessage, PR_HTML, IID_IStream, 0, 0);
             $fwbody_html = "";
             while (1) {
                 $data = mapi_stream_read($stream, 1024);
                 if (strlen($data) == 0) {
                     break;
                 }
                 $fwbody_html .= $data;
             }
             if ($forward) {
                 // During a forward, we have to add the forward header ourselves. This is because
                 // normally the forwarded message is added as an attachment. However, we don't want this
                 // because it would be rather complicated to copy over the entire original message due
                 // to the lack of IMessage::CopyTo ..
                 $fwmessageprops = mapi_getprops($fwmessage, array(PR_SENT_REPRESENTING_NAME, PR_DISPLAY_TO, PR_DISPLAY_CC, PR_SUBJECT, PR_CLIENT_SUBMIT_TIME));
                 $fwheader = "\r\n\r\n";
                 $fwheader .= "-----Original Message-----\r\n";
                 if (isset($fwmessageprops[PR_SENT_REPRESENTING_NAME])) {
                     $fwheader .= "From: " . $fwmessageprops[PR_SENT_REPRESENTING_NAME] . "\r\n";
                 }
                 if (isset($fwmessageprops[PR_DISPLAY_TO]) && strlen($fwmessageprops[PR_DISPLAY_TO]) > 0) {
                     $fwheader .= "To: " . $fwmessageprops[PR_DISPLAY_TO] . "\r\n";
                 }
                 if (isset($fwmessageprops[PR_DISPLAY_CC]) && strlen($fwmessageprops[PR_DISPLAY_CC]) > 0) {
                     $fwheader .= "Cc: " . $fwmessageprops[PR_DISPLAY_CC] . "\r\n";
                 }
                 if (isset($fwmessageprops[PR_CLIENT_SUBMIT_TIME])) {
                     $fwheader .= "Sent: " . strftime("%x %X", $fwmessageprops[PR_CLIENT_SUBMIT_TIME]) . "\r\n";
                 }
                 if (isset($fwmessageprops[PR_SUBJECT])) {
                     $fwheader .= "Subject: " . $fwmessageprops[PR_SUBJECT] . "\r\n";
                 }
                 $fwheader .= "\r\n";
                 // add fwheader to body and body_html
                 $body .= $fwheader;
                 if (strlen($body_html) > 0) {
                     $body_html .= str_ireplace("\r\n", "<br>", $fwheader);
                 }
             }
             if (strlen($body) > 0) {
                 $body .= $fwbody;
             }
             if (strlen($body_html) > 0) {
                 $body_html .= $fwbody_html;
             }
         } else {
             debugLog("Unable to open item with id {$orig} for forward/reply");
         }
     }
     if ($forward) {
         // Add attachments from the original message in a forward
         $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig));
         $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid);
         $attachtable = mapi_message_getattachmenttable($fwmessage);
         $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
         foreach ($rows as $row) {
             if (isset($row[PR_ATTACH_NUM])) {
                 $attach = mapi_message_openattach($fwmessage, $row[PR_ATTACH_NUM]);
                 $newattach = mapi_message_createattach($mapimessage);
                 // Copy all attachments from old to new attachment
                 $attachprops = mapi_getprops($attach);
                 mapi_setprops($newattach, $attachprops);
                 if (isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
                     // Data is in a stream
                     $srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
                     $dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
                     while (1) {
                         $data = mapi_stream_read($srcstream, 4096);
                         if (strlen($data) == 0) {
                             break;
                         }
                         mapi_stream_write($dststream, $data);
                     }
                     mapi_stream_commit($dststream);
                 }
                 mapi_savechanges($newattach);
             }
         }
     }
     //set PR_INTERNET_CPID to 65001 (utf-8) if store supports it and to 1252 otherwise
     $internetcpid = 1252;
     if (defined('STORE_SUPPORTS_UNICODE') && STORE_SUPPORTS_UNICODE == true) {
         $internetcpid = 65001;
     }
     mapi_setprops($mapimessage, array(PR_BODY => $body, PR_INTERNET_CPID => $internetcpid));
     if (strlen($body_html) > 0) {
         mapi_setprops($mapimessage, array(PR_HTML => $body_html));
     }
     mapi_savechanges($mapimessage);
     mapi_message_submitmessage($mapimessage);
     return true;
 }
示例#7
0
文件: ics.php 项目: jkreska/test1
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     $mimeParams = array('decode_headers' => false, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\r\n", 'charset' => 'utf-8');
     $mimeObject = new Mail_mimeDecode($mimeParams['input'], $mimeParams['crlf']);
     $message = $mimeObject->decode($mimeParams);
     // Open the outbox and create the message there
     $storeprops = mapi_getprops($this->_defaultstore, array(PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID));
     if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID])) {
         debugLog("Outbox not found to create message");
         return false;
     }
     $outbox = mapi_msgstore_openentry($this->_defaultstore, $storeprops[PR_IPM_OUTBOX_ENTRYID]);
     if (!$outbox) {
         debugLog("Unable to open outbox");
         return false;
     }
     $mapimessage = mapi_folder_createmessage($outbox);
     mapi_setprops($mapimessage, array(PR_SUBJECT => u2w($mimeObject->_decodeHeader($message->headers["subject"])), PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID], PR_MESSAGE_CLASS => "IPM.Note", PR_MESSAGE_DELIVERY_TIME => time()));
     if (isset($message->headers["x-priority"])) {
         switch ($message->headers["x-priority"]) {
             case 1:
             case 2:
                 $priority = PRIO_URGENT;
                 $importance = IMPORTANCE_HIGH;
                 break;
             case 4:
             case 5:
                 $priority = PRIO_NONURGENT;
                 $importance = IMPORTANCE_LOW;
                 break;
             case 3:
             default:
                 $priority = PRIO_NORMAL;
                 $importance = IMPORTANCE_NORMAL;
                 break;
         }
         mapi_setprops($mapimessage, array(PR_IMPORTANCE => $importance, PR_PRIORITY => $priority));
     }
     $addresses = array();
     $toaddr = $ccaddr = $bccaddr = array();
     if (isset($message->headers["to"])) {
         $toaddr = Mail_RFC822::parseAddressList($message->headers["to"]);
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = Mail_RFC822::parseAddressList($message->headers["cc"]);
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = Mail_RFC822::parseAddressList($message->headers["bcc"]);
     }
     // Add recipients
     $recips = array();
     if (isset($toaddr)) {
         foreach (array(MAPI_TO => $toaddr, MAPI_CC => $ccaddr, MAPI_BCC => $bccaddr) as $type => $addrlist) {
             foreach ($addrlist as $addr) {
                 $mapirecip[PR_ADDRTYPE] = "SMTP";
                 $mapirecip[PR_EMAIL_ADDRESS] = $addr->mailbox . "@" . $addr->host;
                 if (isset($addr->personal) && strlen($addr->personal) > 0) {
                     $mapirecip[PR_DISPLAY_NAME] = u2w($mimeObject->_decodeHeader($addr->personal));
                 } else {
                     $mapirecip[PR_DISPLAY_NAME] = $mapirecip[PR_EMAIL_ADDRESS];
                 }
                 $mapirecip[PR_RECIPIENT_TYPE] = $type;
                 $mapirecip[PR_ENTRYID] = mapi_createoneoff($mapirecip[PR_DISPLAY_NAME], $mapirecip[PR_ADDRTYPE], $mapirecip[PR_EMAIL_ADDRESS]);
                 array_push($recips, $mapirecip);
             }
         }
     }
     mapi_message_modifyrecipients($mapimessage, 0, $recips);
     // Loop through subparts. We currently only support real single-level
     // multiparts and partly multipart/related/mixed for attachments.
     // The PDA currently only does this because you are adding
     // an attachment and the type will be multipart/mixed or multipart/alternative.
     $body = "";
     if ($message->ctype_primary == "multipart" && ($message->ctype_secondary == "mixed" || $message->ctype_secondary == "alternative")) {
         foreach ($message->parts as $part) {
             if ($part->ctype_primary == "text" && $part->ctype_secondary == "plain" && isset($part->body)) {
                 // discard any other kind of text, like html
                 $body .= u2w($part->body);
                 // assume only one text body
             } elseif ($part->ctype_primary == "ms-tnef" || $part->ctype_secondary == "ms-tnef") {
                 $zptnef = new ZPush_tnef($this->_defaultstore);
                 $mapiprops = array();
                 $zptnef->extractProps($part->body, $mapiprops);
                 if (is_array($mapiprops) && !empty($mapiprops)) {
                     //check if it is a recurring item
                     $tnefrecurr = GetPropIDFromString($this->_defaultstore, "PT_BOOLEAN:{6ED8DA90-450B-101B-98DA-00AA003F1305}:0x5");
                     if (isset($mapiprops[$tnefrecurr])) {
                         $this->_handleRecurringItem($mapimessage, $mapiprops);
                     }
                     mapi_setprops($mapimessage, $mapiprops);
                 } else {
                     debugLog("TNEF: Mapi props array was empty");
                 }
             } elseif ($part->ctype_primary == "multipart" && ($part->ctype_secondary == "mixed" || $part->ctype_secondary == "related")) {
                 if (is_array($part->parts)) {
                     foreach ($part->parts as $part2) {
                         if (isset($part2->disposition) && ($part2->disposition == "inline" || $part2->disposition == "attachment")) {
                             $this->_storeAttachment($mapimessage, $part2);
                         }
                     }
                 }
             } elseif ($part->ctype_primary == "text" && $part->ctype_secondary == "calendar") {
                 $zpical = new ZPush_ical($this->_defaultstore);
                 $mapiprops = array();
                 $zpical->extractProps($part->body, $mapiprops);
                 if (is_array($mapiprops) && !empty($mapiprops)) {
                     mapi_setprops($mapimessage, $mapiprops);
                 } else {
                     debugLog("ICAL: Mapi props array was empty");
                 }
             } else {
                 $this->_storeAttachment($mapimessage, $part);
             }
         }
     } else {
         $body = u2w($message->body);
     }
     if ($forward) {
         $orig = $forward;
     }
     if ($reply) {
         $orig = $reply;
     }
     if (isset($orig) && $orig) {
         // Append the original text body for reply/forward
         $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig));
         $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid);
         if ($fwmessage) {
             //update icon when forwarding or replying message
             if ($forward) {
                 mapi_setprops($fwmessage, array(PR_ICON_INDEX => 262));
             } elseif ($reply) {
                 mapi_setprops($fwmessage, array(PR_ICON_INDEX => 261));
             }
             mapi_savechanges($fwmessage);
             $stream = mapi_openproperty($fwmessage, PR_BODY, IID_IStream, 0, 0);
             $fwbody = "";
             while (1) {
                 $data = mapi_stream_read($stream, 1024);
                 if (strlen($data) == 0) {
                     break;
                 }
                 $fwbody .= $data;
             }
             if (strlen($body) > 0) {
                 if ($forward) {
                     // During a forward, we have to add the forward header ourselves. This is because
                     // normally the forwarded message is added as an attachment. However, we don't want this
                     // because it would be rather complicated to copy over the entire original message due
                     // to the lack of IMessage::CopyTo ..
                     $fwmessageprops = mapi_getprops($fwmessage, array(PR_SENT_REPRESENTING_NAME, PR_DISPLAY_TO, PR_DISPLAY_CC, PR_SUBJECT, PR_CLIENT_SUBMIT_TIME));
                     $body .= "\r\n\r\n";
                     $body .= "-----Original Message-----\r\n";
                     if (isset($fwmessageprops[PR_SENT_REPRESENTING_NAME])) {
                         $body .= "From: " . $fwmessageprops[PR_SENT_REPRESENTING_NAME] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_DISPLAY_TO]) && strlen($fwmessageprops[PR_DISPLAY_TO]) > 0) {
                         $body .= "To: " . $fwmessageprops[PR_DISPLAY_TO] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_DISPLAY_CC]) && strlen($fwmessageprops[PR_DISPLAY_CC]) > 0) {
                         $body .= "Cc: " . $fwmessageprops[PR_DISPLAY_CC] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_CLIENT_SUBMIT_TIME])) {
                         $body .= "Sent: " . strftime("%x %X", $fwmessageprops[PR_CLIENT_SUBMIT_TIME]) . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_SUBJECT])) {
                         $body .= "Subject: " . $fwmessageprops[PR_SUBJECT] . "\r\n";
                     }
                     $body .= "\r\n";
                 }
                 $body .= $fwbody;
             }
         } else {
             debugLog("Unable to open item with id {$orig} for forward/reply");
         }
     }
     if ($forward) {
         // Add attachments from the original message in a forward
         $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig));
         $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid);
         $attachtable = mapi_message_getattachmenttable($fwmessage);
         $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
         foreach ($rows as $row) {
             if (isset($row[PR_ATTACH_NUM])) {
                 $attach = mapi_message_openattach($fwmessage, $row[PR_ATTACH_NUM]);
                 $newattach = mapi_message_createattach($mapimessage);
                 // Copy all attachments from old to new attachment
                 $attachprops = mapi_getprops($attach);
                 mapi_setprops($newattach, $attachprops);
                 if (isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
                     // Data is in a stream
                     $srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
                     $dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
                     while (1) {
                         $data = mapi_stream_read($srcstream, 4096);
                         if (strlen($data) == 0) {
                             break;
                         }
                         mapi_stream_write($dststream, $data);
                     }
                     mapi_stream_commit($dststream);
                 }
                 mapi_savechanges($newattach);
             }
         }
     }
     mapi_setprops($mapimessage, array(PR_BODY => $body));
     mapi_savechanges($mapimessage);
     mapi_message_submitmessage($mapimessage);
     return true;
 }
 /**
  * Get an exception attachment based on its basedate
  */
 function getExceptionAttachment($base_date)
 {
     // Retrieve only exceptions which are stored as embedded messages
     $attach_res = array(RES_AND, array(array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_ATTACH_METHOD, VALUE => array(PR_ATTACH_METHOD => ATTACH_EMBEDDED_MSG)))));
     $attachments = mapi_message_getattachmenttable($this->message);
     $attachRows = mapi_table_queryallrows($attachments, array(PR_ATTACH_NUM), $attach_res);
     if (is_array($attachRows)) {
         foreach ($attachRows as $attachRow) {
             $tempattach = mapi_message_openattach($this->message, $attachRow[PR_ATTACH_NUM]);
             $exception = mapi_attach_openobj($tempattach);
             $data = mapi_message_getprops($exception, array($this->proptags["basedate"]));
             if (!isset($data[$this->proptags["basedate"]])) {
                 // if no basedate found then it could be embedded message so ignore it
                 // we need proper restriction to exclude embedded messages aswell
                 continue;
             }
             if ($this->isSameDay($this->fromGMT($this->tz, $data[$this->proptags["basedate"]]), $base_date)) {
                 return $tempattach;
             }
         }
     }
     return false;
 }
示例#9
0
 /**
  * Convert vObject to an array of properties
  * @param array $properties 
  * @param object $vCard
  */
 public function propertiesToVObject($contact, &$vCard)
 {
     $this->logger->debug("Generating contact vCard from properties");
     $p = $this->bridge->getExtendedProperties();
     $contactProperties = mapi_getprops($contact);
     // $this->bridge->getProperties($contactId);
     $dump = print_r($contactProperties, true);
     $this->logger->trace("Contact properties:\n{$contactProperties}");
     // Version check
     switch ($this->version) {
         case 2:
             $vCard->add('VERSION', '2.1');
             break;
         case 3:
             $vCard->add('VERSION', '3.0');
             break;
         case 4:
             $vCard->add('VERSION', '4.0');
             break;
         default:
             $this->logger->fatal("Unrecognised VCard version: " . $this->version);
             return;
     }
     // Private contact ?
     if (isset($contactProperties[$p['private']]) && $contactProperties[$p['private']]) {
         $vCard->add('CLASS', 'PRIVATE');
         // Not in VCARD 4.0 but keep it for compatibility
     }
     // Mandatory FN
     $this->setVCard($vCard, 'FN', $contactProperties, $p['display_name']);
     // Contact name and pro information
     // N property
     /*
        Special note:  The structured property value corresponds, in
     	  sequence, to the Family Names (also known as surnames), Given
     	  Names, Additional Names, Honorific Prefixes, and Honorific
     	  Suffixes.  The text components are separated by the SEMICOLON
     	  character (U+003B).  Individual text components can include
     	  multiple text values separated by the COMMA character (U+002C).
     	  This property is based on the semantics of the X.520 individual
     	  name attributes [CCITT.X520.1988].  The property SHOULD be present
     	  in the vCard object when the name of the object the vCard
     	  represents follows the X.520 model.
     
     	  The SORT-AS parameter MAY be applied to this property.
     */
     $contactInfos = array();
     $contactInfos[] = isset($contactProperties[$p['surname']]) ? $contactProperties[$p['surname']] : '';
     $contactInfos[] = isset($contactProperties[$p['given_name']]) ? $contactProperties[$p['given_name']] : '';
     $contactInfos[] = isset($contactProperties[$p['middle_name']]) ? $contactProperties[$p['middle_name']] : '';
     $contactInfos[] = isset($contactProperties[$p['display_name_prefix']]) ? $contactProperties[$p['display_name_prefix']] : '';
     $contactInfos[] = isset($contactProperties[$p['generation']]) ? $contactProperties[$p['generation']] : '';
     $element = new Sabre_VObject_Property("N");
     $element->setValue(implode(';', $contactInfos));
     // $element->offsetSet("SORT-AS", '"' . $contactProperties[$p['fileas']] . '"');
     $vCard->add($element);
     $this->setVCard($vCard, 'SORT-AS', $contactProperties, $p['fileas']);
     $this->setVCard($vCard, 'NICKNAME', $contactProperties, $p['nickname']);
     $this->setVCard($vCard, 'TITLE', $contactProperties, $p['title']);
     $this->setVCard($vCard, 'ROLE', $contactProperties, $p['profession']);
     $this->setVCard($vCard, 'ORG', $contactProperties, $p['company_name']);
     $this->setVCard($vCard, 'OFFICE', $contactProperties, $p['office_location']);
     if ($this->version >= 4) {
         if (isset($contactProperties[$p['assistant']])) {
             if (!empty($contactProperties[$p['assistant']])) {
                 $element = new Sabre_VObject_Property('RELATED');
                 $element->setValue($contactProperties[$p['assistant']]);
                 $element->offsetSet('TYPE', 'assistant');
                 // Not RFC compliant
                 $vCard->add($element);
             }
         }
         if (isset($contactProperties[$p['manager_name']])) {
             if (!empty($contactProperties[$p['manager_name']])) {
                 $element = new Sabre_VObject_Property('RELATED');
                 $element->setValue($contactProperties[$p['manager_name']]);
                 $element->offsetSet('TYPE', 'manager');
                 // Not RFC compliant
                 $vCard->add($element);
             }
         }
         if (isset($contactProperties[$p['spouse_name']])) {
             if (!empty($contactProperties[$p['spouse_name']])) {
                 $element = new Sabre_VObject_Property('RELATED');
                 $element->setValue($contactProperties[$p['spouse_name']]);
                 $element->offsetSet('TYPE', 'spouse');
                 $vCard->add($element);
             }
         }
     }
     // older syntax - may be needed by some clients so keep it!
     $this->setVCard($vCard, 'X-MS-ASSISTANT', $contactProperties, $p['assistant']);
     $this->setVCard($vCard, 'X-MS-MANAGER', $contactProperties, $p['manager_name']);
     $this->setVCard($vCard, 'X-MS-SPOUSE', $contactProperties, $p['spouse_name']);
     // Dates
     if (isset($contactProperties[$p['birthday']]) && $contactProperties[$p['birthday']] > 0) {
         $vCard->add('BDAY', date(DATE_PATTERN, $contactProperties[$p['birthday']]));
     }
     if (isset($contactProperties[$p['wedding_anniversary']]) && $contactProperties[$p['wedding_anniversary']] > 0) {
         if ($this->version >= 4) {
             $vCard->add('ANNIVERSARY', date(DATE_PATTERN, $contactProperties[$p['wedding_anniversary']]));
         } else {
             $vCard->add('X-ANNIVERSARY', date(DATE_PATTERN, $contactProperties[$p['wedding_anniversary']]));
         }
     }
     // Telephone numbers
     // webaccess can handle 19 telephone numbers...
     $this->setVCard($vCard, 'TEL;TYPE=HOME,VOICE', $contactProperties, $p['home_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=HOME,VOICE', $contactProperties, $p['home2_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=CELL', $contactProperties, $p['cellular_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=WORK,VOICE', $contactProperties, $p['office_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=WORK,VOICE', $contactProperties, $p['business2_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=WORK,FAX', $contactProperties, $p['business_fax_number']);
     $this->setVCard($vCard, 'TEL;TYPE=HOME,FAX', $contactProperties, $p['home_fax_number']);
     $this->setVCard($vCard, 'TEL;TYPE=PAGER', $contactProperties, $p['pager_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=ISDN', $contactProperties, $p['isdn_number']);
     $this->setVCard($vCard, 'TEL;TYPE=WORK', $contactProperties, $p['company_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=CAR', $contactProperties, $p['car_telephone_number']);
     $this->setVCard($vCard, 'TEL;TYPE=SECR', $contactProperties, $p['assistant_telephone_number']);
     // There are unmatched telephone numbers in zarafa, use them!
     $unmatchedProperties = array("callback_telephone_number", "other_telephone_number", "primary_fax_number", "primary_telephone_number", "radio_telephone_number", "telex_telephone_number", "ttytdd_telephone_number");
     if (in_array(DEFAULT_TELEPHONE_NUMBER_PROPERTY, $unmatchedProperties)) {
         // unmatched found a match!
         $this->setVCard($vCard, 'TEL', $contactProperties, $p[DEFAULT_TELEPHONE_NUMBER_PROPERTY]);
     }
     $this->setVCardAddress($vCard, 'HOME', $contactProperties, 'home');
     $this->setVCardAddress($vCard, 'WORK', $contactProperties, 'business');
     $this->setVCardAddress($vCard, 'OTHER', $contactProperties, 'other');
     // emails
     for ($i = 1; $i <= 3; $i++) {
         if (isset($contactProperties[$p["email_address_{$i}"]])) {
             // Zarafa needs an email display name
             $emailProperty = new Sabre_VObject_Property('EMAIL', $contactProperties[$p["email_address_{$i}"]]);
             // Get display name
             $dn = isset($contactProperties[$p["email_address_display_name_{$i}"]]) ? $contactProperties[$p["email_address_display_name_{$i}"]] : $contactProperties[$p['display_name']];
             $emailProperty->offsetSet("X-CN", '"' . $dn . '"');
             $vCard->add($emailProperty);
         }
     }
     // URL and Instant Messenging (vCard 3.0 extension)
     $this->setVCard($vCard, 'URL', $contactProperties, $p["webpage"]);
     $this->setVCard($vCard, 'IMPP', $contactProperties, $p["im"]);
     // Categories
     $contactCategories = '';
     if (isset($contactProperties[$p['categories']])) {
         if (is_array($contactProperties[$p['categories']])) {
             $contactCategories = implode(',', $contactProperties[$p['categories']]);
         } else {
             $contactCategories = $contactProperties[$p['categories']];
         }
     }
     if ($contactCategories != '') {
         $vCard->add('CATEGORIES', $contactCategories);
     }
     // Contact picture?
     $hasattachProp = mapi_getprops($contact, array(PR_HASATTACH));
     $photo = NULL;
     $photoMime = '';
     if (isset($hasattachProp[PR_HASATTACH]) && $hasattachProp[PR_HASATTACH]) {
         $attachmentTable = mapi_message_getattachmenttable($contact);
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD, PR_ATTACH_CONTENT_ID, PR_ATTACH_MIME_TAG, PR_ATTACHMENT_CONTACTPHOTO, PR_EC_WA_ATTACHMENT_HIDDEN_OVERRIDE));
         $dump = print_r($attachments, true);
         $this->logger->trace("Contact attachments:\n{$dump}");
         foreach ($attachments as $attachmentRow) {
             if (isset($attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) && $attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) {
                 $attach = mapi_message_openattach($contact, $attachmentRow[PR_ATTACH_NUM]);
                 $photo = mapi_attach_openbin($attach, PR_ATTACH_DATA_BIN);
                 if (isset($attachmentRow[PR_ATTACH_MIME_TAG])) {
                     $photoMime = $attachmentRow[PR_ATTACH_MIME_TAG];
                 } else {
                     $photoMime = 'image/jpeg';
                 }
                 break;
             }
         }
     }
     if ($photo != NULL) {
         // SogoConnector does not like image/jpeg
         if ($photoMime == 'image/jpeg') {
             $photoMime = 'JPEG';
         }
         $this->logger->trace("Adding contact picture to VCard");
         $photoEncoded = base64_encode($photo);
         $photoProperty = new Sabre_VObject_Property('PHOTO', $photoEncoded);
         $photoProperty->offsetSet('TYPE', $photoMime);
         $photoProperty->offsetSet('ENCODING', 'b');
         $vCard->add($photoProperty);
     }
     // Misc
     $vCard->add('UID', "urn:uuid:" . substr($contactProperties[PR_CARDDAV_URI], 0, -4));
     // $this->entryIdToStr($contactProperties[PR_ENTRYID]));
     $this->setVCard($vCard, 'NOTE', $contactProperties, $p['notes']);
     $vCard->add('PRODID', VCARD_PRODUCT_ID);
     $vCard->add('REV', date('c', $contactProperties[$p['last_modification_time']]));
 }
示例#10
0
 function GetAttachmentData($attname)
 {
     list($folderid, $id, $attachnum) = explode(":", $attname);
     if (!isset($id) || !isset($attachnum)) {
         return false;
     }
     $sourcekey = hex2bin($id);
     $foldersourcekey = hex2bin($folderid);
     $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, $foldersourcekey, $sourcekey);
     if (!$entryid) {
         debugLog("Attachment requested for non-existing item {$attname}");
         return false;
     }
     $message = mapi_msgstore_openentry($this->_defaultstore, $entryid);
     if (!$message) {
         debugLog("Unable to open item for attachment data for " . bin2hex($entryid));
         return false;
     }
     $attach = mapi_message_openattach($message, $attachnum);
     if (!$attach) {
         debugLog("Unable to open attachment number {$attachnum}");
         return false;
     }
     $attachtable = mapi_message_getattachmenttable($message);
     // START CHANGED dw2412 EML Attachment
     $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM, PR_ATTACH_METHOD));
     foreach ($rows as $row) {
         if (isset($row[PR_ATTACH_NUM]) && $row[PR_ATTACH_NUM] == $attachnum) {
             if ($row[PR_ATTACH_METHOD] == ATTACH_EMBEDDED_MSG) {
                 $stream = buildEMLAttachment($attach);
             } else {
                 $stream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
             }
         }
     }
     // END CHANGED dw2412 EML Attachment
     if (!$stream) {
         debugLog("Unable to open attachment data stream");
         return false;
     }
     while (1) {
         $data = mapi_stream_read($stream, 4096);
         if (strlen($data) == 0) {
             break;
         }
         print $data;
     }
     return true;
 }
示例#11
0
 function SendMail($rfc822, $forward = false, $reply = false, $parent = false)
 {
     $message = Mail_mimeDecode::decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\r\n", 'charset' => 'utf-8'));
     // Open the outbox and create the message there
     $storeprops = mapi_getprops($this->_defaultstore, array(PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID));
     if (!isset($storeprops[PR_IPM_OUTBOX_ENTRYID])) {
         debugLog("Outbox not found to create message");
         return false;
     }
     $outbox = mapi_msgstore_openentry($this->_defaultstore, $storeprops[PR_IPM_OUTBOX_ENTRYID]);
     if (!$outbox) {
         debugLog("Unable to open outbox");
         return false;
     }
     $mapimessage = mapi_folder_createmessage($outbox);
     mapi_setprops($mapimessage, array(PR_SUBJECT => u2w($message->headers["subject"]), PR_SENTMAIL_ENTRYID => $storeprops[PR_IPM_SENTMAIL_ENTRYID], PR_MESSAGE_CLASS => "IPM.Note", PR_MESSAGE_DELIVERY_TIME => time()));
     if (isset($message->headers["x-priority"])) {
         switch ($message->headers["x-priority"]) {
             case 1:
             case 2:
                 $priority = PRIO_URGENT;
                 $importance = IMPORTANCE_HIGH;
                 break;
             case 4:
             case 5:
                 $priority = PRIO_NONURGENT;
                 $importance = IMPORTANCE_LOW;
                 break;
             case 3:
             default:
                 $priority = PRIO_NORMAL;
                 $importance = IMPORTANCE_NORMAL;
                 break;
         }
         mapi_setprops($mapimessage, array(PR_IMPORTANCE => $importance, PR_PRIORITY => $priority));
     }
     $addresses = array();
     $toaddr = $ccaddr = $bccaddr = array();
     if (isset($message->headers["to"])) {
         $toaddr = Mail_RFC822::parseAddressList($message->headers["to"]);
     }
     if (isset($message->headers["cc"])) {
         $ccaddr = Mail_RFC822::parseAddressList($message->headers["cc"]);
     }
     if (isset($message->headers["bcc"])) {
         $bccaddr = Mail_RFC822::parseAddressList($message->headers["bcc"]);
     }
     // Add recipients
     $recips = array();
     if (isset($toaddr)) {
         foreach (array(MAPI_TO => $toaddr, MAPI_CC => $ccaddr, MAPI_BCC => $bccaddr) as $type => $addrlist) {
             foreach ($addrlist as $addr) {
                 $mapirecip[PR_ADDRTYPE] = "SMTP";
                 $mapirecip[PR_EMAIL_ADDRESS] = $addr->mailbox . "@" . $addr->host;
                 if (isset($addr->personal) && strlen($addr->personal) > 0) {
                     $mapirecip[PR_DISPLAY_NAME] = u2w($addr->personal);
                 } else {
                     $mapirecip[PR_DISPLAY_NAME] = $mapirecip[PR_EMAIL_ADDRESS];
                 }
                 $mapirecip[PR_RECIPIENT_TYPE] = $type;
                 $mapirecip[PR_ENTRYID] = mapi_createoneoff($mapirecip[PR_DISPLAY_NAME], $mapirecip[PR_ADDRTYPE], $mapirecip[PR_EMAIL_ADDRESS]);
                 array_push($recips, $mapirecip);
             }
         }
     }
     mapi_message_modifyrecipients($mapimessage, 0, $recips);
     // Loop through subparts. We currently only support single-level
     // multiparts. The PDA currently only does this because you are adding
     // an attachment and the type will be multipart/mixed.
     if ($message->ctype_primary == "multipart" && $message->ctype_secondary == "mixed") {
         foreach ($message->parts as $part) {
             if ($part->ctype_primary == "text") {
                 $body = u2w($part->body);
             } else {
                 // attachment
                 $attach = mapi_message_createattach($mapimessage);
                 // Filename is present in both Content-Type: name=.. and in Content-Disposition: filename=
                 if (isset($part->ctype_parameters["name"])) {
                     $filename = $part->ctype_parameters["name"];
                 } else {
                     if (isset($part->d_parameters["name"])) {
                         $filename = $part->d_parameters["filename"];
                     } else {
                         $filename = "untitled";
                     }
                 }
                 // Set filename and attachment type
                 mapi_setprops($attach, array(PR_ATTACH_LONG_FILENAME => u2w($filename), PR_ATTACH_METHOD => ATTACH_BY_VALUE));
                 // Set attachment data
                 mapi_setprops($attach, array(PR_ATTACH_DATA_BIN => $part->body));
                 // Set MIME type
                 mapi_setprops($attach, array(PR_ATTACH_MIME_TAG => $part->ctype_primary . "/" . $part->ctype_secondary));
                 mapi_savechanges($attach);
             }
         }
     } else {
         $body = u2w($message->body);
     }
     if ($forward) {
         $orig = $forward;
     }
     if ($reply) {
         $orig = $reply;
     }
     if (isset($orig) && $orig) {
         // Append the original text body for reply/forward
         $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig));
         $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid);
         if ($fwmessage) {
             $messageprops = mapi_getprops($fwmessage, array(PR_BODY));
             if (isset($messageprops[PR_BODY])) {
                 if ($forward) {
                     // During a forward, we have to add the forward header ourselves. This is because
                     // normally the forwarded message is added as an attachment. However, we don't want this
                     // because it would be rather complicated to copy over the entire original message due
                     // to the lack of IMessage::CopyTo ..
                     $fwmessageprops = mapi_getprops($fwmessage, array(PR_SENT_REPRESENTING_NAME, PR_DISPLAY_TO, PR_DISPLAY_CC, PR_SUBJECT, PR_CLIENT_SUBMIT_TIME));
                     $body .= "\r\n\r\n";
                     $body .= "-----Original Message-----\r\n";
                     if (isset($fwmessageprops[PR_SENT_REPRESENTING_NAME])) {
                         $body .= "From: " . $fwmessageprops[PR_SENT_REPRESENTING_NAME] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_DISPLAY_TO]) && strlen($fwmessageprops[PR_DISPLAY_TO]) > 0) {
                         $body .= "To: " . $fwmessageprops[PR_DISPLAY_TO] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_DISPLAY_CC]) && strlen($fwmessageprops[PR_DISPLAY_CC]) > 0) {
                         $body .= "Cc: " . $fwmessageprops[PR_DISPLAY_CC] . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_CLIENT_SUBMIT_TIME])) {
                         $body .= "Sent: " . strftime("%x %X", $fwmessageprops[PR_CLIENT_SUBMIT_TIME]) . "\r\n";
                     }
                     if (isset($fwmessageprops[PR_SUBJECT])) {
                         $body .= "Subject: " . $fwmessageprops[PR_SUBJECT] . "\r\n";
                     }
                     $body .= "\r\n";
                 }
                 $body .= $messageprops[PR_BODY];
             }
         } else {
             debugLog("Unable to open item with id {$orig} for forward/reply");
         }
     }
     if ($forward) {
         // Add attachments from the original message in a forward
         $entryid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, hex2bin($parent), hex2bin($orig));
         $fwmessage = mapi_msgstore_openentry($this->_defaultstore, $entryid);
         $attachtable = mapi_message_getattachmenttable($fwmessage);
         $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
         foreach ($rows as $row) {
             if (isset($row[PR_ATTACH_NUM])) {
                 $attach = mapi_message_openattach($fwmessage, $row[PR_ATTACH_NUM]);
                 $newattach = mapi_message_createattach($mapimessage);
                 // Copy all attachments from old to new attachment
                 $attachprops = mapi_getprops($attach);
                 mapi_setprops($newattach, $attachprops);
                 if (isset($attachprops[mapi_prop_tag(PT_ERROR, mapi_prop_id(PR_ATTACH_DATA_BIN))])) {
                     // Data is in a stream
                     $srcstream = mapi_openpropertytostream($attach, PR_ATTACH_DATA_BIN);
                     $dststream = mapi_openpropertytostream($newattach, PR_ATTACH_DATA_BIN, MAPI_MODIFY | MAPI_CREATE);
                     while (1) {
                         $data = mapi_stream_read($srcstream, 4096);
                         if (strlen($data) == 0) {
                             break;
                         }
                         mapi_stream_write($dststream, $data);
                     }
                     mapi_stream_commit($dststream);
                 }
                 mapi_savechanges($newattach);
             }
         }
     }
     mapi_setprops($mapimessage, array(PR_BODY => $body));
     mapi_savechanges($mapimessage);
     mapi_message_submitmessage($mapimessage);
     return true;
 }
示例#12
0
 /**
  * Copies attachments from one message to another.
  *
  * @param MAPIMessage $toMessage
  * @param MAPIMessage $fromMessage
  *
  * @return void
  */
 private function copyAttachments(&$toMessage, $fromMessage)
 {
     $attachtable = mapi_message_getattachmenttable($fromMessage);
     $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
     foreach ($rows as $row) {
         if (isset($row[PR_ATTACH_NUM])) {
             $attach = mapi_message_openattach($fromMessage, $row[PR_ATTACH_NUM]);
             $newattach = mapi_message_createattach($toMessage);
             mapi_copyto($attach, array(), array(), $newattach, 0);
             mapi_savechanges($newattach);
         }
     }
 }
示例#13
0
 /**
  * Assign a contact picture to a contact
  * @param entryId contact entry id
  * @param contactPicture must be a valid jpeg file. If contactPicture is NULL will remove contact picture from contact if exists
  */
 public function setContactPicture(&$contact, $contactPicture)
 {
     $this->logger->trace("setContactPicture");
     // Find if contact picture is already set
     $contactAttachment = -1;
     $hasattachProp = mapi_getprops($contact, array(PR_HASATTACH));
     if ($hasattachProp) {
         $attachmentTable = mapi_message_getattachmenttable($contact);
         $attachments = mapi_table_queryallrows($attachmentTable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME, PR_ATTACH_FILENAME, PR_ATTACHMENT_HIDDEN, PR_DISPLAY_NAME, PR_ATTACH_METHOD, PR_ATTACH_CONTENT_ID, PR_ATTACH_MIME_TAG, PR_ATTACHMENT_CONTACTPHOTO, PR_EC_WA_ATTACHMENT_HIDDEN_OVERRIDE));
         foreach ($attachments as $attachmentRow) {
             if (isset($attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) && $attachmentRow[PR_ATTACHMENT_CONTACTPHOTO]) {
                 $contactAttachment = $attachmentRow[PR_ATTACH_NUM];
                 break;
             }
         }
     }
     // Remove existing attachment if necessary
     if ($contactAttachment != -1) {
         $this->logger->trace("removing existing contact picture");
         $attach = mapi_message_deleteattach($contact, $contactAttachment);
     }
     if ($contactPicture !== NULL) {
         $this->logger->debug("Saving contact picture as attachment");
         // Create attachment
         $attach = mapi_message_createattach($contact);
         // Update contact attachment properties
         $properties = array(PR_ATTACH_SIZE => strlen($contactPicture), PR_ATTACH_LONG_FILENAME => 'ContactPicture.jpg', PR_ATTACHMENT_HIDDEN => false, PR_DISPLAY_NAME => 'ContactPicture.jpg', PR_ATTACH_METHOD => ATTACH_BY_VALUE, PR_ATTACH_MIME_TAG => 'image/jpeg', PR_ATTACHMENT_CONTACTPHOTO => true, PR_ATTACH_DATA_BIN => $contactPicture, PR_ATTACHMENT_FLAGS => 1, PR_ATTACH_EXTENSION_A => '.jpg', PR_ATTACH_NUM => 1);
         mapi_setprops($attach, $properties);
         mapi_savechanges($attach);
     }
     // Test
     if (mapi_last_hresult() > 0) {
         $this->logger->warn("Error saving contact picture: " . get_mapi_error_name());
     } else {
         $this->logger->trace("contact picture done");
     }
 }
 /**
  * A wrapper for mapi_inetmapi_imtoinet function
  *
  * @param MAPIMessage       $mapimessage
  * @param SyncObject        $message
  *
  * @access private
  * @return boolean
  */
 private function imtoinet($mapimessage, &$message)
 {
     // if it is a signed message get a full attachment generated by ZCP
     $props = mapi_getprops($mapimessage, array(PR_MESSAGE_CLASS));
     if (isset($props[PR_MESSAGE_CLASS]) && $props[PR_MESSAGE_CLASS] && strpos(strtolower($props[PR_MESSAGE_CLASS]), 'multipartsigned')) {
         // find the required attachment
         $attachtable = mapi_message_getattachmenttable($mapimessage);
         mapi_table_restrict($attachtable, MAPIUtils::GetSignedAttachmentRestriction());
         if (mapi_table_getrowcount($attachtable) == 1) {
             $rows = mapi_table_queryrows($attachtable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE), 0, 1);
             if (isset($rows[0][PR_ATTACH_NUM])) {
                 $mapiattach = mapi_message_openattach($mapimessage, $rows[0][PR_ATTACH_NUM]);
                 $stream = mapi_openpropertytostream($mapiattach, PR_ATTACH_DATA_BIN);
                 $streamsize = $rows[0][PR_ATTACH_SIZE];
             }
         }
     } elseif (function_exists("mapi_inetmapi_imtoinet")) {
         $addrbook = $this->getAddressbook();
         $stream = mapi_inetmapi_imtoinet($this->session, $addrbook, $mapimessage, array('use_tnef' => -1));
         $mstreamstat = mapi_stream_stat($stream);
         $streamsize = $mstreamstat["cb"];
     }
     if (isset($stream) && isset($streamsize)) {
         if (Request::GetProtocolVersion() >= 12.0) {
             if (!isset($message->asbody)) {
                 $message->asbody = new SyncBaseBody();
             }
             //TODO data should be wrapped in a MapiStreamWrapper
             $message->asbody->data = mapi_stream_read($stream, $streamsize);
             $message->asbody->estimatedDataSize = $streamsize;
             $message->asbody->truncated = 0;
         } else {
             $message->mimetruncated = 0;
             //TODO mimedata should be a wrapped in a MapiStreamWrapper
             $message->mimedata = mapi_stream_read($stream, $streamsize);
             $message->mimesize = $streamsize;
         }
         unset($message->body, $message->bodytruncated);
         return true;
     } else {
         ZLog::Write(LOGLEVEL_ERROR, sprintf("Error opening attachment for imtoinet"));
     }
     return false;
 }
 function getEmbeddedTask($message)
 {
     $table = mapi_message_getattachmenttable($message);
     $rows = mapi_table_queryallrows($table, array(PR_ATTACH_NUM));
     // Assume only one attachment
     if (empty($rows)) {
         return false;
     }
     $attach = mapi_message_openattach($message, $rows[0][PR_ATTACH_NUM]);
     $message = mapi_openproperty($attach, PR_ATTACH_DATA_OBJ, IID_IMessage, 0, 0);
     return $message;
 }
 /**
  * Writes a SyncContact to MAPI
  *
  * @param mixed             $mapimessage
  * @param SyncContact       $contact
  *
  * @access private
  * @return boolean
  */
 private function setContact($mapimessage, $contact)
 {
     mapi_setprops($mapimessage, array(PR_MESSAGE_CLASS => "IPM.Contact"));
     // normalize email addresses
     if (isset($contact->email1address) && ($contact->email1address = $this->extractEmailAddress($contact->email1address)) === false) {
         unset($contact->email1address);
     }
     if (isset($contact->email2address) && ($contact->email2address = $this->extractEmailAddress($contact->email2address)) === false) {
         unset($contact->email2address);
     }
     if (isset($contact->email3address) && ($contact->email3address = $this->extractEmailAddress($contact->email3address)) === false) {
         unset($contact->email3address);
     }
     $contactmapping = MAPIMapping::GetContactMapping();
     $contactprops = MAPIMapping::GetContactProperties();
     $this->setPropsInMAPI($mapimessage, $contact, $contactmapping);
     ///set display name from contact's properties
     $cname = $this->composeDisplayName($contact);
     //get contact specific mapi properties and merge them with the AS properties
     $contactprops = array_merge($this->getPropIdsFromStrings($contactmapping), $this->getPropIdsFromStrings($contactprops));
     //contact specific properties to be set
     $props = array();
     //need to be set in order to show contacts properly in outlook and wa
     $nremails = array();
     $abprovidertype = 0;
     if (isset($contact->email1address)) {
         $this->setEmailAddress($contact->email1address, $cname, 1, $props, $contactprops, $nremails, $abprovidertype);
     }
     if (isset($contact->email2address)) {
         $this->setEmailAddress($contact->email2address, $cname, 2, $props, $contactprops, $nremails, $abprovidertype);
     }
     if (isset($contact->email3address)) {
         $this->setEmailAddress($contact->email3address, $cname, 3, $props, $contactprops, $nremails, $abprovidertype);
     }
     $props[$contactprops["addressbooklong"]] = $abprovidertype;
     $props[$contactprops["displayname"]] = $props[$contactprops["subject"]] = $cname;
     //pda multiple e-mail addresses bug fix for the contact
     if (!empty($nremails)) {
         $props[$contactprops["addressbookmv"]] = $nremails;
     }
     //set addresses
     $this->setAddress("home", $contact->homecity, $contact->homecountry, $contact->homepostalcode, $contact->homestate, $contact->homestreet, $props, $contactprops);
     $this->setAddress("business", $contact->businesscity, $contact->businesscountry, $contact->businesspostalcode, $contact->businessstate, $contact->businessstreet, $props, $contactprops);
     $this->setAddress("other", $contact->othercity, $contact->othercountry, $contact->otherpostalcode, $contact->otherstate, $contact->otherstreet, $props, $contactprops);
     //set the mailing address and its type
     if (isset($props[$contactprops["businessaddress"]])) {
         $props[$contactprops["mailingaddress"]] = 2;
         $this->setMailingAddress($contact->businesscity, $contact->businesscountry, $contact->businesspostalcode, $contact->businessstate, $contact->businessstreet, $props[$contactprops["businessaddress"]], $props, $contactprops);
     } elseif (isset($props[$contactprops["homeaddress"]])) {
         $props[$contactprops["mailingaddress"]] = 1;
         $this->setMailingAddress($contact->homecity, $contact->homecountry, $contact->homepostalcode, $contact->homestate, $contact->homestreet, $props[$contactprops["homeaddress"]], $props, $contactprops);
     } elseif (isset($props[$contactprops["otheraddress"]])) {
         $props[$contactprops["mailingaddress"]] = 3;
         $this->setMailingAddress($contact->othercity, $contact->othercountry, $contact->otherpostalcode, $contact->otherstate, $contact->otherstreet, $props[$contactprops["otheraddress"]], $props, $contactprops);
     }
     if (isset($contact->picture)) {
         $picbinary = base64_decode($contact->picture);
         $picsize = strlen($picbinary);
         if ($picsize < MAX_EMBEDDED_SIZE) {
             $props[$contactprops["haspic"]] = false;
             // TODO contact picture handling
             // check if contact has already got a picture. delete it first in that case
             // delete it also if it was removed on a mobile
             $picprops = mapi_getprops($mapimessage, array($props[$contactprops["haspic"]]));
             if (isset($picprops[$props[$contactprops["haspic"]]]) && $picprops[$props[$contactprops["haspic"]]]) {
                 ZLog::Write(LOGLEVEL_DEBUG, "Contact already has a picture. Delete it");
                 $attachtable = mapi_message_getattachmenttable($mapimessage);
                 mapi_table_restrict($attachtable, MAPIUtils::GetContactPicRestriction());
                 $rows = mapi_table_queryallrows($attachtable, array(PR_ATTACH_NUM));
                 if (isset($rows) && is_array($rows)) {
                     foreach ($rows as $row) {
                         mapi_message_deleteattach($mapimessage, $row[PR_ATTACH_NUM]);
                     }
                 }
             }
             // only set picture if there's data in the request
             if ($picbinary !== false && $picsize > 0) {
                 $props[$contactprops["haspic"]] = true;
                 $pic = mapi_message_createattach($mapimessage);
                 // Set properties of the attachment
                 $picprops = array(PR_ATTACH_LONG_FILENAME_A => "ContactPicture.jpg", PR_DISPLAY_NAME => "ContactPicture.jpg", 0x7fff000b => true, PR_ATTACHMENT_HIDDEN => false, PR_ATTACHMENT_FLAGS => 1, PR_ATTACH_METHOD => ATTACH_BY_VALUE, PR_ATTACH_EXTENSION_A => ".jpg", PR_ATTACH_NUM => 1, PR_ATTACH_SIZE => $picsize, PR_ATTACH_DATA_BIN => $picbinary);
                 mapi_setprops($pic, $picprops);
                 mapi_savechanges($pic);
             }
         }
     }
     if (isset($contact->asbody)) {
         $this->setASbody($contact->asbody, $props, $contactprops);
     }
     //set fileas
     if (defined('FILEAS_ORDER')) {
         $lastname = isset($contact->lastname) ? $contact->lastname : "";
         $firstname = isset($contact->firstname) ? $contact->firstname : "";
         $middlename = isset($contact->middlename) ? $contact->middlename : "";
         $company = isset($contact->companyname) ? $contact->companyname : "";
         $props[$contactprops["fileas"]] = Utils::BuildFileAs($lastname, $firstname, $middlename, $company);
     } else {
         ZLog::Write(LOGLEVEL_DEBUG, "FILEAS_ORDER not defined");
     }
     mapi_setprops($mapimessage, $props);
 }
示例#17
0
 /**
  * Function will be used to decode smime messages and convert it to normal messages.
  *
  * @param MAPISession       $session
  * @param MAPIStore         $store
  * @param MAPIAdressBook    $addressBook
  * @param MAPIMessage       $message smime message
  *
  * @access public
  * @return void
  */
 public static function ParseSmime($session, $store, $addressBook, &$mapimessage)
 {
     $props = mapi_getprops($mapimessage, array(PR_MESSAGE_CLASS));
     if (isset($props[PR_MESSAGE_CLASS]) && stripos($props[PR_MESSAGE_CLASS], 'IPM.Note.SMIME.MultipartSigned') !== false) {
         // this is a signed message. decode it.
         $attachTable = mapi_message_getattachmenttable($mapimessage);
         $rows = mapi_table_queryallrows($attachTable, array(PR_ATTACH_MIME_TAG, PR_ATTACH_NUM));
         $attnum = false;
         foreach ($rows as $row) {
             if (isset($row[PR_ATTACH_MIME_TAG]) && $row[PR_ATTACH_MIME_TAG] == 'multipart/signed') {
                 $attnum = $row[PR_ATTACH_NUM];
             }
         }
         if ($attnum !== false) {
             $att = mapi_message_openattach($mapimessage, $attnum);
             $data = mapi_openproperty($att, PR_ATTACH_DATA_BIN);
             mapi_message_deleteattach($mapimessage, $attnum);
             mapi_inetmapi_imtomapi($session, $store, $addressBook, $mapimessage, $data, array("parse_smime_signed" => 1));
             ZLog::Write(LOGLEVEL_DEBUG, "Convert a smime signed message to a normal message.");
         }
         mapi_setprops($mapimessage, array(PR_MESSAGE_CLASS => 'IPM.Note.SMIME.MultipartSigned'));
     }
     // TODO check if we need to do this for encrypted (and signed?) message as well
 }