forked from BigBlueHat/atmailopen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompose.php
More file actions
230 lines (172 loc) · 7.04 KB
/
compose.php
File metadata and controls
230 lines (172 loc) · 7.04 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<?php
// +----------------------------------------------------------------+
// | compose.php |
// +----------------------------------------------------------------+
// | AtMail Open - Licensed under the Apache 2.0 Open-source License|
// | http://opensource.org/licenses/apache2.0.php |
// +----------------------------------------------------------------+
require_once('header.php');
require_once('Session.php');
require_once('Global.php');
require_once('Log.php');
require_once('SendMsg.php');
//require_once('PGP.php');
require_once('Mail/RFC822.php');
session_start();
// get global settings from config file
global $settings, $pref;
$var = array();
$atmail = new AtmailGlobal();
$auth =& $atmail->getAuthObj();
$atmail->httpheaders();
$atmail->status = $auth->getuser( $atmail->SessionID );
$atmail->username = $auth->username;
$atmail->pop3host = $auth->pop3host;
// check for language version
if (!$atmail->Language)
$atmail->Language = $pref['Language'];
// Print the error screen if the account has auth errors, or session timeout.
if ( $atmail->status == 1 )
$atmail->auth_error();
if ( $atmail->status == 2 )
$atmail->session_error();
// Which function
$var['func'] = $_REQUEST['func'];
// Check for an attachment upload that has gone over post_max_size
// Set func to 'attachment' as $_POST will be empty.
if (isset($_GET['sending_attachment']) && !count($_POST) && !count($_FILES)) {
$var['func'] = 'attachment';
}
// Load the account preferences
$atmail->loadprefs();
// Parse the users custom stylesheet
$var['atmailstyle'] = $atmail->parse("html/$atmail->Language/$atmail->LoginType/atmailstyle.css");
// Load the time to display in the compose window
$var['localtime'] = strftime("%c");
// Create a unqiue number - Each compose screen is unique. Used to
// reference which attachments are for what window. Based on the
// PID and a random number.
$var['unique'] = $atmail->param_escape('unique');
$var['delete'] = $_REQUEST['delete'];
if ( !$var['unique'] )
{
$var['unique'] = getmypid() + rand(0, 1000);
//$var['unique'] =~ s/\..*//g;
}
// Avoid any fake/malformed unique ID, e.g ../ in pathname
$var['unique'] = preg_replace('/\.\.\//', '', $var['unique']);
// see if something is cached
if (file_exists($atmail->tmpdir . ".ht$auth->SessionID"))
$var['PgpPass'] = 1;
// The From address of our
$var['FromAddress'] = $atmail->loadpersonalities();
// Calculate the height of the menubar ( if the Webadmin user toggles off certain features )
$h = $atmail->calcmenu_height();
foreach($h as $k => $v)
$var[$k] = $v;
// Display the attachment modal window
if ( $var['func'] == "attachmentmodal" )
{
print $atmail->parse("html/$atmail->Language/$atmail->LoginType/attachmentmodal.html", $var);
}
elseif ( $var['func'] == "attachmentmodalframe" ) {
$var['maxfilesize'] = ini_get('upload_max_filesize');
if (!is_numeric($var['maxfilesize'])) {
if (strpos($var['maxfilesize'], 'M') !== false)
$var['maxfilesize'] = intval($var['maxfilesize'])*1024*1024;
elseif (strpos($var['maxfilesize'], 'K') !== false)
$var['maxfilesize'] = intval($var['maxfilesize'])*1024;
elseif (strpos($var['maxfilesize'], 'G') !== false)
$var['maxfilesize'] = intval($var['maxfilesize'])*1024*1024*1024;
}
print $atmail->parse("html/$atmail->Language/$atmail->LoginType/attachment.html", $var );
}
// Rename an attachment, when forwarding via Ajax
elseif( $var['func'] == "renameattach") {
$sendmsg = new SendMsg(array('Account' => "$atmail->username@$atmail->pop3host"));
$AttachmentList = $_REQUEST['Attachment'];
// Loop through each attachment to rename on disk
if(is_array($AttachmentList))
foreach($AttachmentList as $attach) {
$attach = $atmail->myunescape($attach);
$sendmsg->renameattach($var['unique'], $attach);
}
echo "<ATTACH STATUS='OK'/>";
$atmail->end();
}
elseif ($var['func'] == "attachmentmodallist" )
{
$icon = $atmail->icon_hash();
$sendmsg = new SendMsg(array('Account' => "$atmail->username@$atmail->pop3host"));
// Delete the selected attachment
if ( $var['delete'] )
$var['status'] = $sendmsg->delete_attachment($var['delete'], $var['unique']);
// List the number of attachments . Based on the unique compose
// window and our logged in account
$h = $sendmsg->list_attachments($var['unique']);
foreach ($h as $k => $v)
{
$var['filename'] = $k;
if ( preg_match('/\.(\w+)$/', $var['filename'], $match) )
$var['ext'] = $match[1];
$var['size'] = $v['size'];
$var['mime'] = $v['mime'];
// Load the icon for the filename
$var['icon'] = $icon[strtolower($var['ext'])];
// Use the standard if none exists
if ( !$var['icon'] )
$var['icon'] = "plain.gif";
$var['AttachNames'] .= "{$var['filename']}; ";
// Build the HTML table that lists the attachments
$var['attachments'] .= $atmail->parse("html/$atmail->Language/$atmail->LoginType/attachfilemodal.html", $var );
// Increment the counter ( for the Javascript id field )
$var['id']++;
}
$var['AttachNames'] = preg_replace('/; $/', '', $var['AttachNames']);
print $atmail->parse("html/$atmail->Language/$atmail->LoginType/attachmentmodallist.html", $var );
}
// Print the attachment window
elseif ( $var['func'] == "attachment" )
{
$icon = $atmail->icon_hash();
$var['delete'] = $_REQUEST['delete'];
$var['unique'] = $atmail->param_escape('unique');
$sendmsg = new SendMsg(array('Account' => "$atmail->username@$atmail->pop3host"));
// Delete the selected attachment
if (isset($var['delete'])) {
$var['status'] = $sendmsg->delete_attachment( $var['delete'], $var['unique'] );
}
// Upload an attachment to the server if required
elseif (isset($_FILES['fileupload']))
{
$var['status'] = $sendmsg->add_attachment($var['unique']);
if ($var['status'] === false) {
print $atmail->parse("html/$atmail->Language/msg/attachtoolarge.html");
}
} elseif (isset($_GET['sending_attachment'])) {
// Probably exceeded post_max_size if we get here
print $atmail->parse("html/$atmail->Language/msg/attachtoolarge.html");
}
// List the number of attachments . Based on the unique compose
// window and our logged in account
$h = $sendmsg->list_attachments( $var['unique'] );
foreach ($h as $k => $v)
{
$var['filename'] = $k;
if ( preg_match('/\.(\w+)$/', $var['filename'], $match) )
$var['ext'] = $match[1];
$var['size'] = $v['size'];
$var['mime'] = $v['mime'];
// Load the icon for the filename
$var['icon'] = $icon[ strtolower( $var['ext'] ) ];
// Use the standard if none exists
if ( !$var['icon'] )
$var['icon'] = "plain.gif";
$var['AttachNames'] .= "{$var['filename']} ; ";
// Build the HTML table that lists the attachments
$var['attachments'] .= $atmail->parse("html/$atmail->Language/$atmail->LoginType/attachfile.html", $var);
}
echo "type = $atmail->LoginType";
print $atmail->parse("html/$atmail->Language/$atmail->LoginType/attachment.html", $var);
}
?>