thomascube
2006-08-23 6c76c91951d259f59b2b7a42b8fe895dcc0ef21b
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;
4e17e6 63   // get previous and next 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 ;
72     $next = isset($a_msg_index[$MESSAGE['index']+1]) ? $a_msg_index[$MESSAGE['index']+1] : -1 ;
73     }
74   else
75     {
76     // this assumes that we are sorted by date_DESC
77     $seq = $IMAP->get_id($MESSAGE['UID']);
78     $prev = $IMAP->get_uid($seq + 1);
79     $next = $IMAP->get_uid($seq - 1);
80     $MESSAGE['index'] = $IMAP->messagecount() - $seq;
81     }
4e17e6 82   
e6f360 83   if ($prev > 0)
T 84     $javascript .= sprintf("\n%s.set_env('prev_uid', '%s');", $JS_OBJECT_NAME, $prev);
85   if ($next > 0)
86     $javascript .= sprintf("\n%s.set_env('next_uid', '%s');", $JS_OBJECT_NAME, $next);
4e17e6 87
T 88   $OUTPUT->add_script($javascript);
89   }
90
91
92
93 function rcmail_message_attachments($attrib)
94   {
95   global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL, $JS_OBJECT_NAME;
96
97   if (sizeof($MESSAGE['attachments']))
98     {
99     // allow the following attributes to be added to the <ul> tag
100     $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
101     $out = '<ul' . $attrib_str . ">\n";
102
103     foreach ($MESSAGE['attachments'] as $attach_prop)
104       {
105       if ($PRINT_MODE)
106         $out .= sprintf('<li>%s (%s)</li>'."\n",
8d4bcd 107                         $attach_prop->filename,
T 108                         show_bytes($attach_prop->size));
4e17e6 109       else
078adf 110         $out .= sprintf('<li><a href="%s&amp;_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
T 111                         htmlentities($GET_URL),
8d4bcd 112                         $attach_prop->mime_id,
4e17e6 113                         $JS_OBJECT_NAME,
8d4bcd 114                         $attach_prop->mime_id,
T 115                         $attach_prop->mimetype,
116                         $attach_prop->filename);
4e17e6 117       }
T 118
119     $out .= "</ul>";
120     return $out;
121     }  
122   }
123
124
125
126 // return an HTML iframe for loading mail content
127 function rcmail_messagecontent_frame($attrib)
128   {
129   global $COMM_PATH, $OUTPUT, $GET_URL, $JS_OBJECT_NAME;
130   
131   // allow the following attributes to be added to the <iframe> tag
132   $attrib_str = create_attrib_string($attrib);
133   $framename = 'rcmailcontentwindow';
134   
135   $out = sprintf('<iframe src="%s" name="%s"%s>%s</iframe>'."\n",
136          $GET_URL,
137          $framename,
138          $attrib_str,
139          rcube_label('loading'));
140
141
142   $OUTPUT->add_script("$JS_OBJECT_NAME.set_env('contentframe', '$framename');");
143
144   return $out;
145   }
146
147
148 function rcmail_remote_objects_msg($attrib)
149   {
150   global $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
151   
152   if (!$attrib['id'])
153     $attrib['id'] = 'rcmremoteobjmsg';
154
155   // allow the following attributes to be added to the <div> tag
156   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
157   $out = '<div' . $attrib_str . ">";
158   
159   $out .= rep_specialchars_output(sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')" title="%s">%s</a>',
160                                   rcube_label('blockedimages'),
161                                   $JS_OBJECT_NAME,
162                                   rcube_label('showimages'),
163                                   rcube_label('showimages')));
164   
165   $out .= '</div>';
166   
167   $OUTPUT->add_script(sprintf("%s.gui_object('remoteobjectsmsg', '%s');", $JS_OBJECT_NAME, $attrib['id']));
168   return $out;
169   }
170
171
172 if ($_action=='print')
173   parse_template('printmessage');
174 else
175   parse_template('message');
176 ?>