Copyright 2007-2010 Klarälvdalens Datakonsult AB Copyright 2010-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Gunnar Wrobel (wrobel@pardus.de)
示例#1
0
 private function KolabWriteTask($message, $id)
 {
     if (!$id) {
         $uid = strtoupper(md5(uniqid(time())));
     } else {
         $uid = $id;
     }
     $object = array('uid' => $uid, 'start' => $message->utcstartdate, 'due' => $message->utcduedate, 'name' => u2w($message->subject));
     if (isset($message->rtf)) {
         $object['body'] = $this->rtf2text($message->rtf);
     }
     if ($message->reminderset == 1) {
         $object['alarm'] = ($message->remindertime - $message->utcstartdate) / 60;
     }
     //categories
     if (isset($message->categories)) {
         $object['categories'] = u2w(join(',', $message->categories));
     }
     switch ($message->importance) {
         case 0:
             $object["priority"] = 5;
             break;
         case 1:
             $object["priority"] = 3;
             break;
         case 2:
             $object["priority"] = 1;
             break;
     }
     if ($message->complete == 1) {
         $object['completed'] = 100;
         $object['completed_date'] = $message->datecompleted;
     } else {
         $object['completed'] = 0;
     }
     switch ($message->sensitivity) {
         case 1:
         case 2:
             $object["sensitivity"] = "private";
             break;
         case 3:
             $object["sensitivity"] = "confidential";
     }
     //recurence
     if (isset($message->recurrence)) {
         $object["recurrence"] = $this->kolabWriteReccurence($message->reccurence);
     }
     $format = Horde_Kolab_Format::factory('XML', 'task');
     $xml = $format->save($object);
     unset($format);
     // set the mail
     // attach the XML file
     $mail = $this->mail_attach("kolab.xml", 0, $xml, "kolab message", "text/plain", "plain", "application/x-vnd.kolab.task");
     //add header
     $h["from"] = $this->_email;
     $h["to"] = $this->_email;
     $h["X-Mailer"] = "z-push-Kolab Backend";
     $h["subject"] = $object["uid"];
     $h["message-id"] = "<" . strtoupper(md5(uniqid(time()))) . ">";
     $h["date"] = date(DATE_RFC2822);
     foreach (array_keys($h) as $i) {
         $header = $header . $i . ": " . $h[$i] . "\r\n";
     }
     //return the mail formatted
     return array($object['uid'], $h['date'], $header . $mail[0] . "\r\n" . $mail[1]);
 }
示例#2
0
文件: Folder.php 项目: horde/horde
 /**
  * Save an object in this folder.
  *
  * @param array  $object       The array that holds the data of the object.
  * @param int    $data_version The format handler version.
  * @param string $object_type  The type of the kolab object.
  * @param string $id           The IMAP id of the old object if it
  *                             existed before
  * @param array  $old_object   The array that holds the current data of the
  *                             object.
  *
  * @return boolean True on success.
  */
 public function saveObject(&$object, $data_version, $object_type, $id = null, &$old_object = null)
 {
     // Select folder
     $this->_driver->select($this->_path);
     $new_headers = new Horde_Mime_Headers();
     $new_headers->setEOL("\r\n");
     $formats = $this->getFormats();
     $handlers = array();
     foreach ($formats as $type) {
         $handlers[$type] =& Horde_Kolab_Format::factory($type, $object_type, $data_version);
         if (is_a($handlers[$type], 'PEAR_Error')) {
             if ($type == 'XML') {
                 return $handlers[$type];
             }
             Horde::log(sprintf('Loading format handler "%s" failed: %s', $type, $handlers[$type]->getMessage()), 'ERR');
             continue;
         }
     }
     if ($id != null) {
         /** Update an existing kolab object */
         if (!in_array($id, $this->_driver->getUids($this->_path))) {
             return PEAR::raiseError(sprintf(Horde_Kolab_Storage_Translation::t("The message with ID %s does not exist. This probably means that the Kolab object has been modified by somebody else while you were editing it. Your edits have been lost."), $id));
         }
         /** Parse email and load Kolab format structure */
         $result = $this->parseMessage($id, $handlers['XML']->getMimeType(), true, $formats);
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
         list($old_message, $part_ids, $mime_message, $mime_headers) = $result;
         if (is_a($old_message, 'PEAR_Error')) {
             return $old_message;
         }
         if (isset($object['_attachments']) && isset($old_object['_attachments'])) {
             $attachments = array_keys($object['_attachments']);
             foreach (array_keys($old_object['_attachments']) as $attachment) {
                 if (!in_array($attachment, $attachments)) {
                     foreach ($mime_message->getParts() as $part) {
                         if ($part->getName() === $attachment) {
                             foreach (array_keys($mime_message->_parts) as $key) {
                                 if ($mime_message->_parts[$key]->getMimeId() == $part->getMimeId()) {
                                     unset($mime_message->_parts[$key]);
                                     break;
                                 }
                             }
                             $mime_message->_generateIdMap($mime_message->_parts);
                         }
                     }
                 }
             }
         }
         $object = array_merge($old_object, $object);
         if (isset($attachments)) {
             foreach ($mime_message->getParts() as $part) {
                 $name = $part->getName();
                 foreach ($attachments as $attachment) {
                     if ($name === $attachment) {
                         $object['_attachments'][$attachment]['id'] = $part->getMimeId();
                     }
                 }
             }
         }
         /** Copy email header */
         if (!empty($mime_headers) && !$mime_headers === false) {
             foreach ($mime_headers as $header => $value) {
                 $new_headers->addheader($header, $value);
             }
         }
     } else {
         $mime_message = $this->_prepareNewMessage($new_headers);
         $mime_part_id = false;
     }
     if (isset($object['_attachments'])) {
         $attachments = array_keys($object['_attachments']);
         foreach ($attachments as $attachment) {
             $data = $object['_attachments'][$attachment];
             if (!isset($data['content']) && !isset($data['path'])) {
                 /**
                  * There no new content and no new path. Do not rewrite the
                  * attachment.
                  */
                 continue;
             }
             $part = new Horde_Mime_Part();
             $part->setType(isset($data['type']) ? $data['type'] : null);
             $part->setContents(isset($data['content']) ? $data['content'] : file_get_contents($data['path']));
             $part->setCharset('UTF-8');
             $part->setTransferEncoding('quoted-printable');
             $part->setDisposition('attachment');
             $part->setName($attachment);
             if (!isset($data['id'])) {
                 $mime_message->addPart($part);
             } else {
                 $mime_message->alterPart($data['id'], $part);
             }
         }
     }
     foreach ($formats as $type) {
         $new_content = $handlers[$type]->save($object);
         if (is_a($new_content, 'PEAR_Error')) {
             return $new_content;
         }
         /** Update mime part */
         $part = new Horde_Mime_Part();
         $part->setType($handlers[$type]->getMimeType());
         $part->setContents($new_content);
         $part->setCharset('UTF-8');
         $part->setTransferEncoding('quoted-printable');
         $part->setDisposition($handlers[$type]->getDisposition());
         $part->setDispositionParameter('x-kolab-type', $type);
         $part->setName($handlers[$type]->getName());
         if (!isset($part_ids) || $part_ids[$type] === false) {
             $mime_message->addPart($part);
         } else {
             $mime_message->alterPart($part_ids[$type], $part);
         }
     }
     // Update email headers
     $new_headers->addHeader('From', $this->_driver->getAuth());
     $new_headers->addHeader('To', $this->_driver->getAuth());
     $new_headers->addHeader('Date', date('r'));
     $new_headers->addHeader('X-Kolab-Type', $handlers['XML']->getMimeType());
     $new_headers->addHeader('Subject', $object['uid']);
     $new_headers->addHeader('User-Agent', 'Horde::Kolab::Storage v0.2');
     $new_headers->addHeader('MIME-Version', '1.0');
     $mime_message->addMimeHeaders(array('headers' => $new_headers));
     $msg = $new_headers->toString() . $mime_message->toString(array('canonical' => true, 'headers' => false));
     // delete old email?
     if ($id != null) {
         $this->_driver->deleteMessages($this->_path, $id);
     }
     // store new email
     try {
         $result = $this->_driver->appendMessage($this->_path, $msg);
     } catch (Horde_Kolab_Storage_Exception $e) {
         if ($id != null) {
             $this->_driver->undeleteMessages($id);
         }
     }
     // remove deleted object
     if ($id != null) {
         $this->_driver->expunge($this->_path);
     }
 }
示例#3
0
文件: Old.php 项目: jubinpatel/horde
 /**
  * Synchronize the data cache for the current folder.
  *
  * @param string $history_ignore Object uid that should not be
  *                               updated in the History
  *
  * @return NULL
  */
 public function synchronize($history_ignore = null)
 {
     $this->_cache->load($this->_cache_key, $this->_data_version);
     $result = $this->_folder->getStatus();
     list($validity, $nextid, $ids) = $result;
     $changes = $this->_folderChanged($validity, $nextid, array_keys($this->_cache->uids), $ids);
     if ($changes) {
         $modified = array();
         $recent_uids = array_diff($ids, array_keys($this->_cache->uids));
         $formats = $this->_folder->getFormats();
         $handler = Horde_Kolab_Format::factory('Xml', $this->_object_type, $this->_data_version);
         $count = 0;
         foreach ($recent_uids as $id) {
             if ($this->_type == 'annotation' && $id != 1) {
                 continue;
             }
             try {
                 $mime = $this->_folder->parseMessage($id, $handler->getMimeType(), false);
                 $text = $mime[0];
             } catch (Horde_Kolab_Storage_Exception $e) {
                 Horde::log($mime, 'WARN');
                 $text = false;
             }
             if ($text) {
                 $object = $handler->load($text);
                 if (is_a($object, 'PEAR_Error')) {
                     $this->_cache->ignore($id);
                     $object->addUserInfo('STORAGE ID: ' . $id);
                     Horde::log($object, 'WARN');
                     continue;
                 }
             } else {
                 $object = false;
             }
             if ($object !== false) {
                 $message =& $mime[2];
                 $handler_type = $handler->getMimeType();
                 foreach ($message->getParts() as $part) {
                     $name = $part->getName();
                     $type = $part->getType();
                     $dp = $part->getDispositionParameter('x-kolab-type');
                     if (!empty($name) && $type != $handler_type || !empty($dp) && in_array($dp, $formats)) {
                         $object['_attachments'][$name]['type'] = $type;
                         $object['_attachments'][$name]['key'] = $this->_cache_key . '/' . $object['uid'] . ':' . $name;
                         //@todo: Check what to do with this call
                         //$part->transferDecodeContents();
                         $result = $this->_cache->storeAttachment($object['_attachments'][$name]['key'], $part->getContents());
                         if (is_a($result, 'PEAR_Error')) {
                             Horde::log(sprintf('Failed storing attachment of object %s: %s', $id, $result->getMessage()), 'ERR');
                             $object = false;
                             break;
                         }
                     }
                 }
             }
             if ($object !== false) {
                 $this->_cache->store($id, $object['uid'], $object);
                 $mod_ts = time();
                 if (is_array($changes) && in_array($object['uid'], $changes) && $object['uid'] != $history_ignore) {
                     $this->_updateHistory($object['uid'], $mod_ts, 'modify');
                     $modified[] = $object['uid'];
                 } else {
                     $this->_updateHistory($object['uid'], $mod_ts, 'add');
                 }
             } else {
                 $this->_cache->ignore($id);
             }
             // write out cache once in a while so if the browser times out
             // we don't have to start from the beginning.
             if ($count > 500) {
                 $count = 0;
                 $this->_cache->save();
             }
             $count++;
         }
         $this->_cache->save();
         if (is_array($changes)) {
             $deleted = array_diff($changes, $modified);
             foreach ($deleted as $deleted_oid) {
                 if ($deleted_oid != $history_ignore) {
                     $this->_updateHistory($deleted_oid, time(), 'delete');
                 }
             }
         }
     }
 }