]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/mail/show.inc
Imported Upstream version 0.1~beta2.2~dfsg
[roundcube.git] / program / steps / mail / show.inc
1 <?php
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                      |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
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: show.inc 277 2006-07-19 19:36:35Z thomasb $
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   $next = $prev = -1;
68   // get previous and next message UID
69   if (!($_SESSION['sort_col'] == 'date' && $_SESSION['sort_order'] == 'DESC') && 
70       $IMAP->get_capability('sort')) {
71       // Only if we use custom sorting
72       $a_msg_index = $IMAP->message_index(NULL, $_SESSION['sort_col'], $_SESSION['sort_order']);
73  
74       $MESSAGE['index'] = array_search((string)$_GET['_uid'], $a_msg_index, TRUE);
75       $prev = isset($a_msg_index[$MESSAGE['index']-1]) ? $a_msg_index[$MESSAGE['index']-1] : -1 ;
76       $next = isset($a_msg_index[$MESSAGE['index']+1]) ? $a_msg_index[$MESSAGE['index']+1] : -1 ;
77   } else {
78       // this assumes that we are sorted by date_DESC
79       $seq = $IMAP->get_id($_GET['_uid']);
80       $prev = $IMAP->get_uid($seq + 1);
81       $next = $IMAP->get_uid($seq - 1);
82       $MESSAGE['index'] = $IMAP->messagecount() - $seq;
83   }
84   
85   if ($prev > 0)
86     $javascript .= sprintf("\n%s.set_env('prev_uid', '%s');", $JS_OBJECT_NAME, $prev);
87   if ($next > 0)
88     $javascript .= sprintf("\n%s.set_env('next_uid', '%s');", $JS_OBJECT_NAME, $next);
89
90   $OUTPUT->add_script($javascript);
91   }
92
93
94
95 function rcmail_message_attachments($attrib)
96   {
97   global $CONFIG, $OUTPUT, $PRINT_MODE, $MESSAGE, $GET_URL, $JS_OBJECT_NAME;
98
99   if (sizeof($MESSAGE['attachments']))
100     {
101     // allow the following attributes to be added to the <ul> tag
102     $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
103     $out = '<ul' . $attrib_str . ">\n";
104
105     foreach ($MESSAGE['attachments'] as $attach_prop)
106       {
107       if ($PRINT_MODE)
108         $out .= sprintf('<li>%s (%s)</li>'."\n",
109                         $attach_prop['filename'],
110                         show_bytes($attach_prop['size']));
111       else
112         $out .= sprintf('<li><a href="%s&amp;_part=%s" onclick="return %s.command(\'load-attachment\',{part:\'%s\', mimetype:\'%s\'},this)">%s</a></li>'."\n",
113                         htmlentities($GET_URL),
114                         $attach_prop['part_id'],
115                         $JS_OBJECT_NAME,
116                         $attach_prop['part_id'],
117                         $attach_prop['mimetype'],
118                         $attach_prop['filename']);
119       }
120
121     $out .= "</ul>";
122     return $out;
123     }  
124   }
125
126
127
128 // return an HTML iframe for loading mail content
129 function rcmail_messagecontent_frame($attrib)
130   {
131   global $COMM_PATH, $OUTPUT, $GET_URL, $JS_OBJECT_NAME;
132   
133   // allow the following attributes to be added to the <iframe> tag
134   $attrib_str = create_attrib_string($attrib);
135   $framename = 'rcmailcontentwindow';
136   
137   $out = sprintf('<iframe src="%s" name="%s"%s>%s</iframe>'."\n",
138          $GET_URL,
139          $framename,
140          $attrib_str,
141          rcube_label('loading'));
142
143
144   $OUTPUT->add_script("$JS_OBJECT_NAME.set_env('contentframe', '$framename');");
145
146   return $out;
147   }
148
149
150 function rcmail_remote_objects_msg($attrib)
151   {
152   global $CONFIG, $OUTPUT, $JS_OBJECT_NAME;
153   
154   if (!$attrib['id'])
155     $attrib['id'] = 'rcmremoteobjmsg';
156
157   // allow the following attributes to be added to the <div> tag
158   $attrib_str = create_attrib_string($attrib, array('style', 'class', 'id'));
159   $out = '<div' . $attrib_str . ">";
160   
161   $out .= rep_specialchars_output(sprintf('%s&nbsp;<a href="#loadimages" onclick="%s.command(\'load-images\')" title="%s">%s</a>',
162                                   rcube_label('blockedimages'),
163                                   $JS_OBJECT_NAME,
164                                   rcube_label('showimages'),
165                                   rcube_label('showimages')));
166   
167   $out .= '</div>';
168   
169   $OUTPUT->add_script(sprintf("%s.gui_object('remoteobjectsmsg', '%s');", $JS_OBJECT_NAME, $attrib['id']));
170   return $out;
171   }
172
173
174 if ($_action=='print')
175   parse_template('printmessage');
176 else
177   parse_template('message');
178 ?>