File: view.php3

package info (click to toggle)
imp 3%3A2.2.6-5.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 5,476 kB
  • ctags: 766
  • sloc: php: 4,253; sh: 831; makefile: 98; perl: 50; pascal: 15
file content (134 lines) | stat: -rw-r--r-- 4,219 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/*
  
  File: view.php3
  $Author: chuck $
  $Revision: 2.8.2.27 $
  $Date: 2001/02/28 05:47:59 $
  
  IMP: Copyright 1998, 1999, 2000 Charles J. Hagenbuch <chuck@horde.org>
  
  You should have received a copy of the GNU Public
  License along with this package; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.
  
*/

require '../lib/horde.lib';
require './lib/imp.lib';           /* IMPlib is the IMP function library  */
require './lib/mimetypes.lib';     /* Mime functions */
require './config/defaults.php3';  /* Defaults configuration file */
require './config/lang.php3';
require './config/html.php3';
require './config/mime.php3';

$language = select_lang();
require './lib/postconf.php3';
$lang = new HordeLocaleLang();
$this_client = new WebClient;

error_reporting($default->error_level);  /* set error level from imp.lib   */

// NOTE: this check for safe_mode will only work if safe_mode is enabled
// in the PHP .ini file; get_cfg_var() doesn't read PHP variables set in
// the Apache configuration files.
if (!get_cfg_var('safe_mode')) {
  set_time_limit($default->max_execution_time);
}

if ($this_client->workaround_broken_ie_download) {
  page_open(array('sess' => 'HordeSessionCached'));
} else {
  page_open(array('sess' => 'HordeSession'));
}
  
page_close();
if (!isset($imp) || !is_object($imp)) {
    header("Location: login.php3?reason=logout");
    exit;
}
$imp->unpickle();
$imp->authenticate();

$structure = imap_fetchstructure($imp->stream, $index, FT_UID);
$foo = false;
$attachments = MimeParseStructure($structure, '', $foo);
if (!isset($actionID)) $actionID = NO_ACTION;
if (($actionID != SAVE_MESSAGE) && ($actionID != VIEW_SOURCE)) {
  $mime = $attachments[$bodypart];
  mimeParse($mime);
}

/* Run through action handlers */
switch ($actionID) {
 case NO_ACTION:
	 break;
	 
 case DOWNLOAD_ATTACH:
	 header("Content-Type: application/x-unknown-$mime->TYPE-$mime->SUBTYPE");    /* This should force a save file dialog...  */
     if ($this_client->broken_disposition) {
         header('Content-Disposition: filename=' . decode_mime_string($mime->name));
     } else {
         header('Content-Disposition: attachment; filename=' . decode_mime_string($mime->name));
     }
	 break;
	 
 case VIEW_ATTACH:
	 if (isset($mime->conf['view_function'])) {
		 header('Content-Type: text/html');
		 header('Content-Disposition: inline; filename=' . decode_mime_string($mime->name));
		 $func = $mime->conf['view_function'];
		 echo $func($mime);
		 exit;
	 }
	 
	 header("Content-Type: $mime->TYPE/$mime->SUBTYPE");
     header('Content-Disposition: inline; filename=' . decode_mime_string($mime->name));
	 break;
	 
 case VIEW_SOURCE:
	 $msg = imap_fetchheader($imp->stream, $index, FT_UID) . "\n" . imap_body($imp->stream, $index, FT_UID);
	 header('Content-Type: text/plain');
	 header('Content-Disposition: inline; filename="Message Source"');
	 header('Content-Length: ' . strlen($msg));
	 echo $msg;
	 exit; 
	 break;
	 
 case SAVE_MESSAGE:
	 $h = imap_header($imp->stream, imap_msgno($imp->stream, $index));
	 if (!empty($h->subject))
		 $name = preg_replace('|\W|', '_', trim(decode_mime_string($h->subject)));
	 else
		 $name = 'message';
	 
	 $from = trim(decode_mime_string(isset($h->fromaddress) ? $h->fromaddress : ''));
     $date = strftime('%a %b %d %H:%M:%S %Y', $h->udate);
	 $body  = 'From ' . $from . ' ' . $date . "\n";
	 $body .= imap_fetchheader($imp->stream, $index, FT_UID);
	 $body .= imap_body ($imp->stream, $index, FT_UID);
     $body = str_replace("\r\n", "\n", $body);
	 
	 header('Content-Type: application/RFC822');
     if ($this_client->broken_disposition) {
         header('Content-Disposition: filename=' . $name);
     } else {
         header('Content-Disposition: attachment; filename=' . $name);
     }
	 break;
}

if ($actionID != SAVE_MESSAGE) {
    $body = imap_fetchbody($imp->stream, $index, $bodypart, FT_UID);
    
    if ($mime->encoding == ENCBASE64)
        $body = imap_base64($body);
    else if ($mime->encoding == ENCQUOTEDPRINTABLE && ($qprint_msg = imap_qprint($body)))
        $body = $qprint_msg;
}

header('Content-Length: ' . strlen($body));
echo $body;

?>