squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

attachment_common.php
Go to the documentation of this file.
1 <?php
2 
17 require_once(SM_PATH . 'functions/global.php');
18 
21 
23 $FileExtensionToMimeType = array('bmp' => 'image/x-bitmap',
24  'gif' => 'image/gif',
25  'htm' => 'text/html',
26  'html' => 'text/html',
27  'jpg' => 'image/jpeg',
28  'jpeg' => 'image/jpeg',
29  'php' => 'text/plain',
30  'png' => 'image/png',
31  'rtf' => 'text/richtext',
32  'txt' => 'text/plain',
33  'patch'=> 'text/plain',
34  'vcf' => 'text/x-vcard');
35 
36 /* Register browser-supported image types */
37 sqgetGlobalVar('attachment_common_types', $attachment_common_types);
38 if (isset($attachment_common_types)) {
39  // var is used to detect activation of jpeg image types
40  unset($jpeg_done);
41  /* Don't run this before being logged in. That may happen
42  when plugins include mime.php */
43  foreach ($attachment_common_types as $val => $v) {
44  if ($val == 'image/gif')
45  register_attachment_common('image/gif', 'link_image');
46  elseif (($val == 'image/jpeg' || $val == 'image/pjpeg') and
47  (!isset($jpeg_done))) {
48  $jpeg_done = 1;
49  register_attachment_common('image/jpeg', 'link_image');
50  register_attachment_common('image/pjpeg', 'link_image');
51  }
52  elseif ($val == 'image/png')
53  register_attachment_common('image/png', 'link_image');
54  elseif ($val == 'image/x-xbitmap')
55  register_attachment_common('image/x-xbitmap', 'link_image');
56  elseif ($val == '*/*' || $val == 'image/*') {
61  if (! isset($jpeg_done)) {
62  $jpeg_done = 1;
63  register_attachment_common('image/jpeg', 'link_image');
64  register_attachment_common('image/pjpeg', 'link_image');
65  }
66  register_attachment_common('image/gif', 'link_image');
67  register_attachment_common('image/png', 'link_image');
68  register_attachment_common('image/x-xbitmap', 'link_image');
69  }
70  }
71  unset($jpeg_done);
72 }
73 
74 /* Register text-type attachments */
75 register_attachment_common('message/rfc822', 'link_message');
76 register_attachment_common('text/plain', 'link_text');
77 register_attachment_common('text/richtext', 'link_text');
78 
79 /* Register HTML */
80 register_attachment_common('text/html', 'link_html');
81 
82 
83 /* Register vcards */
84 register_attachment_common('text/x-vcard', 'link_vcard');
85 register_attachment_common('text/directory', 'link_vcard');
86 
87 /* Register rules for general types.
88  * These will be used if there isn't a more specific rule available. */
89 register_attachment_common('text/*', 'link_text');
90 register_attachment_common('message/*', 'link_text');
91 
92 /* Register "unknown" attachments */
93 register_attachment_common('application/octet-stream', 'octet_stream');
94 
95 
96 /* Function which optimizes readability of the above code */
97 
98 function register_attachment_common($type, $func) {
100  $squirrelmail_plugin_hooks['attachment ' . $type]['attachment_common'] =
101  'attachment_common_' . $func;
102 }
103 
104 
105 function attachment_common_link_text(&$Args) {
106 
107  global $squirrelmail_attachments_finished_handling;
108  if (!empty($squirrelmail_attachments_finished_handling[$Args[7]])) return;
109  $squirrelmail_attachments_finished_handling[$Args[7]] = TRUE;
110 
111  /* If there is a text attachment, we would like to create a "View" button
112  that links to the text attachment viewer.
113 
114  $Args[1] = the array of actions
115 
116  Use the name of this file for adding an action
117  $Args[1]['attachment_common'] = Array for href and text
118 
119  $Args[1]['attachment_common']['text'] = What is displayed
120  $Args[1]['attachment_common']['href'] = Where it links to */
121  sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
122 
123  $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING;
124  $Args[1]['attachment_common']['href'] =
125  set_url_var($Args[1]['attachment_common']['href'],
126  'ent_id',$Args[5]);
127 
128  /* The link that we created needs a name. */
129  $Args[1]['attachment_common']['text'] = _("View");
130 
131  /* Each attachment has a filename on the left, which is a link.
132  Where that link points to can be changed. Just in case the link above
133  for viewing text attachments is not the same as the default link for
134  this file, we'll change it.
135 
136  This is a lot better in the image links, since the defaultLink will just
137  download the image, but the one that we set it to will format the page
138  to have an image tag in the center (looking a lot like this text viewer) */
139  $Args[6] = $Args[1]['attachment_common']['href'];
140 }
141 
143 
144  global $squirrelmail_attachments_finished_handling;
145  if (!empty($squirrelmail_attachments_finished_handling[$Args[7]])) return;
146  $squirrelmail_attachments_finished_handling[$Args[7]] = TRUE;
147 
148  $Args[1]['attachment_common']['href'] = SM_PATH . 'src/read_body.php?startMessage=' .
149  $Args[2] . '&amp;passed_id=' . $Args[3] . '&amp;mailbox=' . $Args[4] .
150  '&amp;passed_ent_id=' . $Args[5] . '&amp;override_type0=message&amp;override_type1=rfc822';
151 
152  $Args[1]['attachment_common']['text'] = _("View");
153 
154  $Args[6] = $Args[1]['attachment_common']['href'];
155 }
156 
157 
158 function attachment_common_link_html(&$Args) {
159 
160  global $squirrelmail_attachments_finished_handling;
161  if (!empty($squirrelmail_attachments_finished_handling[$Args[7]])) return;
162  $squirrelmail_attachments_finished_handling[$Args[7]] = TRUE;
163 
164  sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
165 
166  $Args[1]['attachment_common']['href'] = SM_PATH . 'src/view_text.php?'. $QUERY_STRING.
167  /* why use the overridetype? can this be removed */
168  '&amp;override_type0=text&amp;override_type1=html';
169  $Args[1]['attachment_common']['href'] =
170  set_url_var($Args[1]['attachment_common']['href'],
171  'ent_id',$Args[5]);
172 
173  $Args[1]['attachment_common']['text'] = _("View");
174 
175  $Args[6] = $Args[1]['attachment_common']['href'];
176 }
177 
179 
180  global $squirrelmail_attachments_finished_handling;
181  if (!empty($squirrelmail_attachments_finished_handling[$Args[7]])) return;
182  $squirrelmail_attachments_finished_handling[$Args[7]] = TRUE;
183 
185 
186  sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
187 
188  $info['passed_id'] = $Args[3];
189  $info['mailbox'] = $Args[4];
190  $info['ent_id'] = $Args[5];
191 
193 
194  $Args[1]['attachment_common']['href'] = SM_PATH . 'src/image.php?'. $QUERY_STRING;
195  $Args[1]['attachment_common']['href'] =
196  set_url_var($Args[1]['attachment_common']['href'],
197  'ent_id',$Args[5]);
198 
199  $Args[1]['attachment_common']['text'] = _("View");
200 
201  $Args[6] = $Args[1]['attachment_common']['href'];
202 }
203 
204 
206 
207  global $squirrelmail_attachments_finished_handling;
208  if (!empty($squirrelmail_attachments_finished_handling[$Args[7]])) return;
209  $squirrelmail_attachments_finished_handling[$Args[7]] = TRUE;
210 
211  sqgetGlobalVar('QUERY_STRING', $QUERY_STRING, SQ_SERVER);
212 
213  $Args[1]['attachment_common']['href'] = SM_PATH . 'src/vcard.php?'. $QUERY_STRING;
214  $Args[1]['attachment_common']['href'] =
215  set_url_var($Args[1]['attachment_common']['href'],
216  'ent_id',$Args[5]);
217 
218  $Args[1]['attachment_common']['text'] = _("View Business Card");
219 
220  $Args[6] = $Args[1]['attachment_common']['href'];
221 }
222 
223 
226 
227  do_hook('attachment_common-load_mime_types');
228 
229  preg_match('/\.([^.]+)$/', $Args[7], $Regs);
230 
231  $Ext = '';
232  if (is_array($Regs) && isset($Regs[1])) {
233  $Ext = $Regs[1];
234  $Ext = strtolower($Regs[1]);
235  }
236 
237  if ($Ext == '' || ! isset($FileExtensionToMimeType[$Ext]))
238  return;
239 
240  $Ret = do_hook('attachment ' . $FileExtensionToMimeType[$Ext],
241  $Args[1], $Args[2], $Args[3], $Args[4], $Args[5], $Args[6],
242  $Args[7], $Args[8], $Args[9]);
243 
244  foreach ($Ret as $a => $b) {
245  $Args[$a] = $b;
246  }
247 }
248 
elseif
if(! sqgetGlobalVar('sound', $sound, SQ_GET)) elseif($sound=='(none)')
Definition: testsound.php:25
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$attachment_common_show_images_list
global $attachment_common_show_images_list
Definition: attachment_common.php:17
register_attachment_common
register_attachment_common($type, $func)
Definition: attachment_common.php:98
$attachment_common_types
global $attachment_common_types
Definition: attachment_common.php:22
set_url_var
set_url_var($url, $var, $val=null, $link=true)
Definition: html.php:109
$FileExtensionToMimeType
global $FileExtensionToMimeType
Definition: attachment_common.php:22
html
Definition: html.class.php:18
do_hook
do_hook($name)
Definition: plugin.php:42
attachment_common_link_text
attachment_common_link_text(&$Args)
Definition: attachment_common.php:105
attachment_common_link_html
attachment_common_link_html(&$Args)
Definition: attachment_common.php:158
$squirrelmail_plugin_hooks
global $squirrelmail_plugin_hooks
Definition: plugin.php:17
attachment_common_link_vcard
attachment_common_link_vcard(&$Args)
Definition: attachment_common.php:205
attachment_common_link_message
attachment_common_link_message(&$Args)
Definition: attachment_common.php:142
attachment_common_link_image
attachment_common_link_image(&$Args)
Definition: attachment_common.php:178
SQ_SERVER
const SQ_SERVER
Definition: global.php:20
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
attachment_common_octet_stream
attachment_common_octet_stream(&$Args)
Definition: attachment_common.php:224
_
_($str)
Definition: gettext.php:160
$attachment_common_show_images
$attachment_common_show_images
Definition: load_prefs.php:233