thomascube
2006-04-04 a403cdacf07656c0bbeb2c6bf00557070ef826ba
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
8c2e58 98         $out .= sprintf('<li><a href="%s&_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
T 99                         $GET_URL,
100                         $attach_prop['part_id'],
4e17e6 101                         $JS_OBJECT_NAME,
T 102                         $attach_prop['part_id'],
103                         $attach_prop['mimetype'],
104                         $attach_prop['filename']);
105       }
106
107     $out .= "</ul>";
108     return $out;
109     }  
110   }
111
112
113
114 // return an HTML iframe for loading mail content
115 function rcmail_messagecontent_frame($attrib)
116   {
117   global $COMM_PATH, $OUTPUT, $GET_URL, $JS_OBJECT_NAME;
118   
119   // allow the following attributes to be added to the <iframe> tag
120   $attrib_str = create_attrib_string($attrib);
121   $framename = 'rcmailcontentwindow';
122   
123   $out = sprintf('<iframe src="%s" name="%s"%s>%s</iframe>'."\n",
124          $GET_URL,
125          $framename,
126          $attrib_str,
127          rcube_label('loading'));
128
129
130   $OUTPUT->add_script("$JS_OBJECT_NAME.set_env('contentframe', '$framename');");
131
132   return $out;
133   }
134
135
136 function rcmail_remote_objects_msg($attrib)
137   {
138   global $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
139   
140   if (!$attrib['id'])
141     $attrib['id'] = 'rcmremoteobjmsg';
142
143   // allow the following attributes to be added to the <div> tag
144   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
145   $out = '<div' . $attrib_str . ">";
146   
147   $out .= rep_specialchars_output(sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')" title="%s">%s</a>',
148                                   rcube_label('blockedimages'),
149                                   $JS_OBJECT_NAME,
150                                   rcube_label('showimages'),
151                                   rcube_label('showimages')));
152   
153   $out .= '</div>';
154   
155   $OUTPUT->add_script(sprintf("%s.gui_object('remoteobjectsmsg', '%s');", $JS_OBJECT_NAME, $attrib['id']));
156   return $out;
157   }
158
159
160 if ($_action=='print')
161   parse_template('printmessage');
162 else
163   parse_template('message');
164 ?>