svncommit
2006-11-21 84f9312e1d17725db6040554a993db38292d46bd
commit | author | age
4e17e6 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/mail/show.inc                                           |
6  |                                                                       |
7  | This file is part of the RoundCube Webmail client                     |
8  | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
30233b 9  | Licensed under the GNU GPL                                            |
4e17e6 10  |                                                                       |
T 11  | PURPOSE:                                                              |
12  |   Display a mail message similar as a usual mail application does     |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id$
19
20 */
21
22 require_once('Mail/mimeDecode.php');
23
24 $PRINT_MODE = $_action=='print' ? TRUE : FALSE;
25
26
27 // similar code as in program/steps/mail/get.inc
28 if ($_GET['_uid'])
29   {
8d4bcd 30   $MESSAGE = array('UID' => get_input_value('_uid', RCUBE_INPUT_GET));
T 31   $MESSAGE['headers'] = $IMAP->get_headers($MESSAGE['UID']);
32   $MESSAGE['structure'] = $IMAP->get_structure($MESSAGE['UID']);
33     
4e17e6 34   // go back to list if message not found (wrong UID)
8d4bcd 35   if (!$MESSAGE['headers'] || !$MESSAGE['structure'])
4e17e6 36     {
T 37     $_action = 'list';
38     return;
39     }
40
8d4bcd 41   $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['headers']->subject);
T 42   
4e17e6 43   if ($MESSAGE['structure'])
8d4bcd 44     list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message(
T 45       $MESSAGE['structure'],
46       array('safe' => (bool)$_GET['_safe'],
47             'prefer_html' => $CONFIG['prefer_html'],
48             'get_url' => $GET_URL.'&_part=%s')
49       );
4e17e6 50   else
8d4bcd 51     $MESSAGE['body'] = $IMAP->get_body($MESSAGE['UID']);
4e17e6 52
T 53
54   // mark message as read
55   if (!$MESSAGE['headers']->seen)
56     $IMAP->set_flag($_GET['_uid'], 'SEEN');
57
58   // give message uid to the client
8d4bcd 59   $javascript = sprintf("%s.set_env('uid', '%s');\n", $JS_OBJECT_NAME, $MESSAGE['UID']);
4e17e6 60   $javascript .= sprintf("%s.set_env('safemode', '%b');", $JS_OBJECT_NAME, $_GET['_safe']);
T 61
e6f360 62   $next = $prev = -1;
d17008 63   // get previous, first, next and last message UID
e6f360 64   if (!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') && 
8d4bcd 65       $IMAP->get_capability('sort')) 
T 66     {
67     // Only if we use custom sorting
68     $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
e6f360 69  
8d4bcd 70     $MESSAGE['index'] = array_search((string)$MESSAGE['UID'], $a_msg_index, TRUE);
T 71     $prev = isset($a_msg_index[$MESSAGE['index']-1]) ? $a_msg_index[$MESSAGE['index']-1] : -1 ;
d17008 72     $first = count($a_msg_index)>0 ? $a_msg_index[0] : -1;
8d4bcd 73     $next = isset($a_msg_index[$MESSAGE['index']+1]) ? $a_msg_index[$MESSAGE['index']+1] : -1 ;
d17008 74     $last = count($a_msg_index)>0 ? $a_msg_index[count($a_msg_index)-1] : -1;
8d4bcd 75     }
T 76   else
77     {
78     // this assumes that we are sorted by date_DESC
79     $seq = $IMAP->get_id($MESSAGE['UID']);
80     $prev = $IMAP->get_uid($seq + 1);
d17008 81     $first = $IMAP->get_uid($IMAP->messagecount());
8d4bcd 82     $next = $IMAP->get_uid($seq - 1);
d17008 83     $last = $IMAP->get_uid(1);
8d4bcd 84     $MESSAGE['index'] = $IMAP->messagecount() - $seq;
T 85     }
4e17e6 86   
e6f360 87   if ($prev > 0)
T 88     $javascript .= sprintf("\n%s.set_env('prev_uid', '%s');", $JS_OBJECT_NAME, $prev);
d17008 89   if ($first >0)
S 90     $javascript .= sprintf("\n%s.set_env('first_uid', '%s');", $JS_OBJECT_NAME, $first);
e6f360 91   if ($next > 0)
T 92     $javascript .= sprintf("\n%s.set_env('next_uid', '%s');", $JS_OBJECT_NAME, $next);
d17008 93   if ($last >0)
S 94     $javascript .= sprintf("\n%s.set_env('last_uid', '%s');", $JS_OBJECT_NAME, $last);
4e17e6 95
T 96   $OUTPUT->add_script($javascript);
97   }
98
99
100
101 function rcmail_message_attachments($attrib)
102   {
103   global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL, $JS_OBJECT_NAME;
104
105   if (sizeof($MESSAGE['attachments']))
106     {
107     // allow the following attributes to be added to the <ul> tag
108     $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
109     $out = '<ul' . $attrib_str . ">\n";
110
111     foreach ($MESSAGE['attachments'] as $attach_prop)
112       {
113       if ($PRINT_MODE)
114         $out .= sprintf('<li>%s (%s)</li>'."\n",
8d4bcd 115                         $attach_prop->filename,
T 116                         show_bytes($attach_prop->size));
4e17e6 117       else
078adf 118         $out .= sprintf('<li><a href="%s&amp;_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
ea206d 119                         htmlspecialchars($GET_URL),
8d4bcd 120                         $attach_prop->mime_id,
4e17e6 121                         $JS_OBJECT_NAME,
8d4bcd 122                         $attach_prop->mime_id,
T 123                         $attach_prop->mimetype,
124                         $attach_prop->filename);
4e17e6 125       }
T 126
127     $out .= "</ul>";
128     return $out;
129     }  
130   }
131
132
133
134 // return an HTML iframe for loading mail content
135 function rcmail_messagecontent_frame($attrib)
136   {
137   global $COMM_PATH, $OUTPUT, $GET_URL, $JS_OBJECT_NAME;
138   
139   // allow the following attributes to be added to the <iframe> tag
140   $attrib_str = create_attrib_string($attrib);
141   $framename = 'rcmailcontentwindow';
142   
143   $out = sprintf('<iframe src="%s" name="%s"%s>%s</iframe>'."\n",
144          $GET_URL,
145          $framename,
146          $attrib_str,
147          rcube_label('loading'));
148
149
150   $OUTPUT->add_script("$JS_OBJECT_NAME.set_env('contentframe', '$framename');");
151
152   return $out;
153   }
154
155
156 function rcmail_remote_objects_msg($attrib)
157   {
158   global $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
159   
160   if (!$attrib['id'])
161     $attrib['id'] = 'rcmremoteobjmsg';
162
163   // allow the following attributes to be added to the <div> tag
164   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
165   $out = '<div' . $attrib_str . ">";
166   
167   $out .= rep_specialchars_output(sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')" title="%s">%s</a>',
168                                   rcube_label('blockedimages'),
169                                   $JS_OBJECT_NAME,
170                                   rcube_label('showimages'),
171                                   rcube_label('showimages')));
172   
173   $out .= '</div>';
174   
175   $OUTPUT->add_script(sprintf("%s.gui_object('remoteobjectsmsg', '%s');", $JS_OBJECT_NAME, $attrib['id']));
176   return $out;
177   }
178
179
180 if ($_action=='print')
181   parse_template('printmessage');
182 else
183   parse_template('message');
184 ?>