1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Mime_Viewer_Partial extends Horde_Mime_Viewer_Base
24: {
25: 26: 27: 28: 29:
30: protected $_capability = array(
31: 'full' => false,
32: 'info' => true,
33: 'inline' => false,
34: 'raw' => false
35: );
36:
37: 38: 39: 40: 41:
42: protected $_metadata = array(
43: 'compressed' => false,
44: 'embedded' => true,
45: 'forceinline' => true
46: );
47:
48: 49: 50: 51: 52:
53: protected function _renderInfo()
54: {
55: $cache = $this->getConfigParam('imp_contents')->getViewCache();
56: $id = $this->_mimepart->getMimeId();
57:
58: if (isset($cache->partial) && isset($cache->partial[$id])) {
59: return array(
60: $id => array(
61: 'data' => null,
62: 'status' => $cache->partial[$id],
63: 'type' => 'text/plain; charset=' . $this->getConfigParam('charset')
64: )
65: );
66: } else {
67: return array($id => null);
68: }
69: }
70:
71: 72: 73: 74: 75: 76: 77:
78: protected function _getEmbeddedMimeParts()
79: {
80: $id = $this->_mimepart->getContentTypeParameter('id');
81: $number = $this->_mimepart->getContentTypeParameter('number');
82: $total = $this->_mimepart->getContentTypeParameter('total');
83:
84: if (is_null($id) || is_null($number) || is_null($total)) {
85: return null;
86: }
87:
88:
89: $query = new Horde_Imap_Client_Search_Query();
90: $query->headerText('Content-Type', $id);
91: $indices = $this->getConfigParam('imp_contents')->getMailbox()->runSearchQuery($query);
92:
93: 94:
95: $msg_count = count($indices);
96: if ($msg_count != $total) {
97: $status = new IMP_Mime_Status(sprintf(_("Cannot display message - found only %s of %s parts of this message in the current mailbox."), $msg_count, $total));
98: $status->action(IMP_Mime_Status::ERROR);
99:
100: $cache = $this->getConfigParam('imp_contents')->getViewCache();
101: $cache->partial[$this->_mimepart->getMimeId()] = $status;
102:
103: return null;
104: }
105:
106:
107: $parts = array();
108: foreach ($indices as $ob) {
109: foreach ($ob->uids as $val) {
110:
111: if ($val == $number) {
112: $parts[$number] = $this->_mimepart->getContents();
113: } else {
114: $ic = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($ob->mbox->getIndicesOb($val));
115: $parts[$ic->getMIMEMessage()->getContentTypeParameter('number')] = $ic->getBody();
116: }
117: }
118: }
119:
120:
121: ksort($parts, SORT_NUMERIC);
122:
123:
124: $mime_part = Horde_Mime_Part::parseMessage(implode('', $parts), array('forcemime' => true));
125:
126: return ($mime_part === false)
127: ? null
128: : $mime_part;
129: }
130:
131: }
132: