thomascube
2006-02-22 745b1466fc76d5ded589e2469328086002430c1c
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   {
30   $MESSAGE = array();
31   $MESSAGE['headers'] = $IMAP->get_headers($_GET['_uid']);
32   $MESSAGE['source'] = rcmail_message_source($_GET['_uid']);
33   
34   // go back to list if message not found (wrong UID)
35   if (!$MESSAGE['headers'] || !$MESSAGE['source'])
36     {
37     $_action = 'list';
38     return;
39     }
40
41   $mmd = new Mail_mimeDecode($MESSAGE['source']);
42   $MESSAGE['structure'] = $mmd->decode(array('include_bodies' => TRUE,
43                                              'decode_headers' => FALSE,
44                                              'decode_bodies' => FALSE));
45                                              
46   $mmd->getMimeNumbers($MESSAGE['structure']);
47
48   $MESSAGE['subject'] = $IMAP->decode_header($MESSAGE['structure']->headers['subject']);
49
50   if ($MESSAGE['structure'])
51     list($MESSAGE['parts'], $MESSAGE['attachments']) = rcmail_parse_message($MESSAGE['structure'],
52                                                                            array('safe' => (bool)$_GET['_safe'],
53                                                                                  'prefer_html' => $CONFIG['prefer_html'],
54                                                                                  'get_url' => $GET_URL.'&_part=%s'));
55   else
56     $MESSAGE['body'] = $IMAP->get_body($_GET['_uid']);
57
58
59   // mark message as read
60   if (!$MESSAGE['headers']->seen)
61     $IMAP->set_flag($_GET['_uid'], 'SEEN');
62
63   // give message uid to the client
64   $javascript = sprintf("%s.set_env('uid', '%s');\n", $JS_OBJECT_NAME, $_GET['_uid']);
65   $javascript .= sprintf("%s.set_env('safemode', '%b');", $JS_OBJECT_NAME, $_GET['_safe']);
66
67   // get previous and next message UID
b076a4 68   $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
4e17e6 69   $MESSAGE['index'] = array_search((string)$_GET['_uid'], $a_msg_index, TRUE);
T 70   
71   if (isset($a_msg_index[$MESSAGE['index']-1]))
72     $javascript .= sprintf("\n%s.set_env('prev_uid', '%s');", $JS_OBJECT_NAME, $a_msg_index[$MESSAGE['index']-1]);
73   if (isset($a_msg_index[$MESSAGE['index']+1]))
74     $javascript .= sprintf("\n%s.set_env('next_uid', '%s');", $JS_OBJECT_NAME, $a_msg_index[$MESSAGE['index']+1]);
75
76   $OUTPUT->add_script($javascript);
77   }
78
79
80
81 function rcmail_message_attachments($attrib)
82   {
83   global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL, $JS_OBJECT_NAME;
84
85   if (sizeof($MESSAGE['attachments']))
86     {
87     // allow the following attributes to be added to the <ul> tag
88     $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
89     $out = '<ul' . $attrib_str . ">\n";
90
91     foreach ($MESSAGE['attachments'] as $attach_prop)
92       {
93       if ($PRINT_MODE)
94         $out .= sprintf('<li>%s (%s)</li>'."\n",
95                         $attach_prop['filename'],
96                         show_bytes($attach_prop['size']));
97       else
98         $out .= sprintf('<li><a href="#attachment" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
99                         $JS_OBJECT_NAME,
100                         $attach_prop['part_id'],
101                         $attach_prop['mimetype'],
102                         $attach_prop['filename']);
103     /* direct link
104       else
105         $out .= sprintf('<li><a href="%s&_part=%s&_frame=1" target="rcubemailattachment">%s</a></li>'."\n",
106                         $GET_URL,
107                         $attach_prop['part_id'],
108                         $attach_prop['filename']);
109     */
110       }
111
112     $out .= "</ul>";
113     return $out;
114     }  
115   }
116
117
118
119 // return an HTML iframe for loading mail content
120 function rcmail_messagecontent_frame($attrib)
121   {
122   global $COMM_PATH, $OUTPUT, $GET_URL, $JS_OBJECT_NAME;
123   
124   // allow the following attributes to be added to the <iframe> tag
125   $attrib_str = create_attrib_string($attrib);
126   $framename = 'rcmailcontentwindow';
127   
128   $out = sprintf('<iframe src="%s" name="%s"%s>%s</iframe>'."\n",
129          $GET_URL,
130          $framename,
131          $attrib_str,
132          rcube_label('loading'));
133
134
135   $OUTPUT->add_script("$JS_OBJECT_NAME.set_env('contentframe', '$framename');");
136
137   return $out;
138   }
139
140
141 function rcmail_remote_objects_msg($attrib)
142   {
143   global $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
144   
145   if (!$attrib['id'])
146     $attrib['id'] = 'rcmremoteobjmsg';
147
148   // allow the following attributes to be added to the <div> tag
149   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
150   $out = '<div' . $attrib_str . ">";
151   
152   $out .= rep_specialchars_output(sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')" title="%s">%s</a>',
153                                   rcube_label('blockedimages'),
154                                   $JS_OBJECT_NAME,
155                                   rcube_label('showimages'),
156                                   rcube_label('showimages')));
157   
158   $out .= '</div>';
159   
160   $OUTPUT->add_script(sprintf("%s.gui_object('remoteobjectsmsg', '%s');", $JS_OBJECT_NAME, $attrib['id']));
161   return $out;
162   }
163
164
165 if ($_action=='print')
166   parse_template('printmessage');
167 else
168   parse_template('message');
169 ?>