~ubuntu-branches/ubuntu/hardy/squirrelmail/hardy-updates

« back to all changes in this revision

Viewing changes to src/compose.php

  • Committer: Bazaar Package Importer
  • Author(s): Thijs Kinkhorst
  • Date: 2005-02-06 21:41:51 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050206214151-z4n1o8mnttgzuj0y
Tags: 2:1.4.4-3
* Move default_pref config file from /var to /etc, as per Debian policy
  (Closes: #293281)
* [JvW] (finally) override two lintian warnings about nonstandard
  permissions that are intentional (Closes: #293366)

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
/**
4
4
 * compose.php
5
5
 *
6
 
 * Copyright (c) 1999-2003 The SquirrelMail Project Team
 
6
 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7
7
 * Licensed under the GNU GPL. For full terms see the file COPYING.
8
8
 *
9
9
 * This code sends a mail.
14
14
 *    - Send mail
15
15
 *    - Save As Draft
16
16
 *
17
 
 * $Id: compose.php,v 1.363 2004/01/31 17:45:16 braverock Exp $
 
17
 * @version $Id: compose.php,v 1.319.2.45 2005/01/03 15:06:28 kink Exp $
18
18
 * @package squirrelmail
19
19
 */
20
20
 
21
 
/** Path for SquirrelMail required files. */
 
21
/**
 
22
 * Path for SquirrelMail required files.
 
23
 * @ignore
 
24
 */
22
25
define('SM_PATH','../');
23
26
 
24
27
/* SquirrelMail required files. */
31
34
require_once(SM_PATH . 'functions/display_messages.php');
32
35
require_once(SM_PATH . 'class/deliver/Deliver.class.php');
33
36
require_once(SM_PATH . 'functions/addressbook.php');
34
 
require_once(SM_PATH . 'functions/identity.php');
 
37
require_once(SM_PATH . 'functions/forms.php');
35
38
 
36
39
/* --------------------- Get globals ------------------------------------- */
37
40
/** COOKIE VARS */
50
53
sqgetGlobalVar('smaction',$action);
51
54
sqgetGlobalVar('session',$session);
52
55
sqgetGlobalVar('mailbox',$mailbox);
53
 
if(!sqgetGlobalVar('identity',$identity)) {
54
 
    $identity=0;
55
 
}
 
56
sqgetGlobalVar('identity',$identity);
56
57
sqgetGlobalVar('send_to',$send_to);
57
58
sqgetGlobalVar('send_to_cc',$send_to_cc);
58
59
sqgetGlobalVar('send_to_bcc',$send_to_bcc);
85
86
sqgetGlobalVar('delete',                $delete,                SQ_POST);
86
87
sqgetGlobalVar('restoremessages',       $restoremessages,       SQ_POST);
87
88
if ( sqgetGlobalVar('return', $temp, SQ_POST) ) {
88
 
  $html_addr_search_done = 'Use Addresses';
 
89
    $html_addr_search_done = 'Use Addresses';
89
90
}
90
91
 
91
92
/** GET VARS */
93
94
 
94
95
/* Location (For HTTP 1.1 Header("Location: ...") redirects) */
95
96
$location = get_location();
96
 
/* Identities (fetch only once) */
97
 
$idents = get_identities();
98
97
 
99
98
/* --------------------- Specific Functions ------------------------------ */
100
99
 
101
100
function replyAllString($header) {
102
 
   global $include_self_reply_all, $idents;
103
 
   $excl_ar = array();
104
 
   /**
105
 
    * 1) Remove the addresses we'll be sending the message 'to'
106
 
    */
107
 
   $url_replytoall_avoid_addrs = '';
108
 
   if (isset($header->replyto)) {
109
 
      $excl_ar = $header->getAddr_a('replyto');
110
 
   }
111
 
   /**
112
 
    * 2) Remove our identities from the CC list (they still can be in the
113
 
    * TO list) only if $include_self_reply_all is turned off
114
 
    */
115
 
   if (!$include_self_reply_all) {
116
 
       foreach($idents as $id) {
117
 
           $excl_ar[strtolower(trim($id['email_address']))] = '';
118
 
        }
119
 
   }
120
 
 
121
 
   /**
122
 
    * 3) get the addresses.
123
 
    */
124
 
   $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
125
 
 
126
 
   /**
127
 
    * 4) generate the string.
128
 
    */
129
 
   $url_replytoallcc = '';
130
 
   foreach( $url_replytoall_ar as $email => $personal) {
131
 
      if ($personal) {
132
 
         // if personal name contains address separator then surround
133
 
         // the personal name with double quotes.
134
 
         if (strpos($personal,',') !== false) {
135
 
             $personal = '"'.$personal.'"';
136
 
         }
137
 
         $url_replytoallcc .= ", $personal <$email>";
138
 
      } else {
139
 
         $url_replytoallcc .= ', '. $email;
140
 
      }
141
 
   }
142
 
   $url_replytoallcc = substr($url_replytoallcc,2);
143
 
 
144
 
   return $url_replytoallcc;
 
101
    global $include_self_reply_all, $username, $data_dir;
 
102
    $excl_ar = array();
 
103
    /**
 
104
     * 1) Remove the addresses we'll be sending the message 'to'
 
105
     */
 
106
    $url_replytoall_avoid_addrs = '';
 
107
    if (isset($header->replyto)) {
 
108
        $excl_ar = $header->getAddr_a('replyto');
 
109
    }
 
110
    /**
 
111
     * 2) Remove our identities from the CC list (they still can be in the
 
112
     * TO list) only if $include_self_reply_all is turned off
 
113
     */
 
114
    if (!$include_self_reply_all) {
 
115
        $email_address = strtolower(trim(getPref($data_dir, $username, 'email_address')));
 
116
        $excl_ar[$email_address] = '';
 
117
        $idents = getPref($data_dir, $username, 'identities');
 
118
        if ($idents != '' && $idents > 1) {
 
119
            $first_id = false;
 
120
            for ($i = 1; $i < $idents; $i ++) {
 
121
                $cur_email_address = getPref($data_dir, $username,
 
122
                        'email_address' . $i);
 
123
                $cur_email_address = strtolower(trim($cur_email_address));
 
124
                $excl_ar[$cur_email_address] = '';
 
125
            }
 
126
        }
 
127
    }
 
128
 
 
129
    /**
 
130
     * 3) get the addresses.
 
131
     */
 
132
    $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
 
133
 
 
134
    /**
 
135
     * 4) generate the string.
 
136
     */
 
137
    $url_replytoallcc = '';
 
138
    foreach( $url_replytoall_ar as $email => $personal) {
 
139
        if ($personal) {
 
140
            // if personal name contains address separator then surround
 
141
            // the personal name with double quotes.
 
142
            if (strpos($personal,',') !== false) {
 
143
                $personal = '"'.$personal.'"';
 
144
            }
 
145
            $url_replytoallcc .= ", $personal <$email>";
 
146
        } else {
 
147
            $url_replytoallcc .= ', '. $email;
 
148
        }
 
149
    }
 
150
    $url_replytoallcc = substr($url_replytoallcc,2);
 
151
 
 
152
    return $url_replytoallcc;
145
153
}
146
154
 
147
 
function getReplyCitation($orig_from) {
 
155
function getReplyCitation($orig_from, $orig_date) {
148
156
    global $reply_citation_style, $reply_citation_start, $reply_citation_end;
149
157
    $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
150
 
//    $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
 
158
 
151
159
    /* First, return an empty string when no citation style selected. */
152
160
    if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
153
161
        return '';
160
168
 
161
169
    /* Otherwise, try to select the desired citation style. */
162
170
    switch ($reply_citation_style) {
163
 
    case 'author_said':
164
 
        $start = '';
165
 
        $end   = ' ' . _("said") . ':';
166
 
        break;
167
 
    case 'quote_who':
168
 
        $start = '<' . _("quote") . ' ' . _("who") . '="';
169
 
        $end   = '">';
170
 
        break;
171
 
    case 'user-defined':
172
 
        $start = $reply_citation_start .
173
 
         ($reply_citation_start == '' ? '' : ' ');
174
 
        $end   = $reply_citation_end;
175
 
        break;
176
 
    default:
177
 
        return '';
 
171
        case 'author_said':
 
172
            $start = '';
 
173
            $end   = ' ' . _("said") . ':';
 
174
            break;
 
175
        case 'quote_who':
 
176
            $start = '<' . _("quote") . ' ' . _("who") . '="';
 
177
            $end   = '">';
 
178
            break;
 
179
        case 'date_time_author':
 
180
            $start = 'On ' . getLongDateString($orig_date) . ', ';
 
181
            $end = ' ' . _("said") . ':';
 
182
            break;
 
183
        case 'user-defined':
 
184
            $start = $reply_citation_start .
 
185
                ($reply_citation_start == '' ? '' : ' ');
 
186
            $end   = $reply_citation_end;
 
187
            break;
 
188
        default:
 
189
            return '';
178
190
    }
179
191
 
180
192
    /* Build and return the citation string. */
184
196
function getforwardHeader($orig_header) {
185
197
    global $editor_size;
186
198
 
187
 
   $display = array( _("Subject") => strlen(_("Subject")),
188
 
                     _("From")    => strlen(_("From")),
189
 
                     _("Date")    => strlen(_("Date")),
190
 
                     _("To")      => strlen(_("To")),
191
 
                     _("Cc")      => strlen(_("Cc")) );
192
 
   $maxsize = max($display);
193
 
   $indent = str_pad('',$maxsize+2);
194
 
   foreach($display as $key => $val) {
195
 
      $display[$key] = $key .': '. str_pad('', $maxsize - $val);
196
 
   }
197
 
   $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
198
 
   $from = str_replace('&nbsp;',' ',$from);
199
 
   $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
200
 
   $to = str_replace('&nbsp;',' ',$to);
201
 
   $subject = decodeHeader($orig_header->subject,false,false,true);
202
 
   $subject = str_replace('&nbsp;',' ',$subject);
203
 
   $bodyTop =  str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) .
204
 
               "\n". $display[_("Subject")] . $subject . "\n" .
205
 
               $display[_("From")] . $from . "\n" .
206
 
               $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" .
207
 
               $display[_("To")] . $to . "\n";
208
 
   if ($orig_header->cc != array() && $orig_header->cc !='') {
209
 
      $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
210
 
      $cc = str_replace('&nbsp;',' ',$cc);
211
 
     $bodyTop .= $display[_("Cc")] .$cc . "\n";
212
 
  }
213
 
  $bodyTop .= str_pad('', $editor_size -2 , '-') .
214
 
              "\n\n";
215
 
  return $bodyTop;
 
199
    $display = array( _("Subject") => strlen(_("Subject")),
 
200
            _("From")    => strlen(_("From")),
 
201
            _("Date")    => strlen(_("Date")),
 
202
            _("To")      => strlen(_("To")),
 
203
            _("Cc")      => strlen(_("Cc")) );
 
204
    $maxsize = max($display);
 
205
    $indent = str_pad('',$maxsize+2);
 
206
    foreach($display as $key => $val) {
 
207
        $display[$key] = $key .': '. str_pad('', $maxsize - $val);
 
208
    }
 
209
    $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
 
210
    $from = str_replace('&nbsp;',' ',$from);
 
211
    $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
 
212
    $to = str_replace('&nbsp;',' ',$to);
 
213
    $subject = decodeHeader($orig_header->subject,false,false,true);
 
214
    $subject = str_replace('&nbsp;',' ',$subject);
 
215
    $bodyTop =  str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) .
 
216
        "\n". $display[_("Subject")] . $subject . "\n" .
 
217
        $display[_("From")] . $from . "\n" .
 
218
        $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" .
 
219
        $display[_("To")] . $to . "\n";
 
220
    if ($orig_header->cc != array() && $orig_header->cc !='') {
 
221
        $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
 
222
        $cc = str_replace('&nbsp;',' ',$cc);
 
223
        $bodyTop .= $display[_("Cc")] .$cc . "\n";
 
224
    }
 
225
    $bodyTop .= str_pad('', $editor_size -2 , '-') .
 
226
        "\n\n";
 
227
    return $bodyTop;
216
228
}
217
229
/* ----------------------------------------------------------------------- */
218
230
 
272
284
    sqsession_register($composesession,'composesession');
273
285
}
274
286
if (!isset($compose_messages)) {
275
 
  $compose_messages = array();
 
287
    $compose_messages = array();
276
288
}
277
289
if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) {
278
 
/* if (!array_key_exists($session, $compose_messages)) {  /* We can only do this in PHP >= 4.1 */
279
 
  $composeMessage = new Message();
280
 
  $rfc822_header = new Rfc822Header();
281
 
  $composeMessage->rfc822_header = $rfc822_header;
282
 
  $composeMessage->reply_rfc822_header = '';
283
 
  $compose_messages[$session] = $composeMessage;
284
 
  sqsession_register($compose_messages,'compose_messages');
 
290
    /* if (!array_key_exists($session, $compose_messages)) {  /* We can only do this in PHP >= 4.1 */
 
291
    $composeMessage = new Message();
 
292
    $rfc822_header = new Rfc822Header();
 
293
    $composeMessage->rfc822_header = $rfc822_header;
 
294
    $composeMessage->reply_rfc822_header = '';
 
295
    $compose_messages[$session] = $composeMessage;
 
296
    sqsession_register($compose_messages,'compose_messages');
285
297
} else {
286
 
  $composeMessage=$compose_messages[$session];
 
298
    $composeMessage=$compose_messages[$session];
287
299
}
288
300
 
289
301
if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
306
318
        /* If this is a resumed draft, then delete the original */
307
319
        if(isset($delete_draft)) {
308
320
            Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
309
 
                   "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
 
321
                    "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
310
322
            exit();
311
323
        }
312
324
        else {
315
327
                exit();
316
328
            }
317
329
            else {
318
 
                Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
319
 
                       "&startMessage=1&note=".urlencode($draft_message));
 
330
                Header("Location: $location/right_main.php?mailbox=" . urlencode($draft_folder) .
 
331
                        "&sort=$sort&startMessage=1&note=".urlencode($draft_message));
320
332
                exit();
321
333
            }
322
334
        }
325
337
 
326
338
if ($send) {
327
339
    if (isset($_FILES['attachfile']) &&
328
 
        $_FILES['attachfile']['tmp_name'] &&
329
 
        $_FILES['attachfile']['tmp_name'] != 'none') {
 
340
            $_FILES['attachfile']['tmp_name'] &&
 
341
            $_FILES['attachfile']['tmp_name'] != 'none') {
330
342
        $AttachFailure = saveAttachedFiles($session);
331
343
    }
332
344
    if (checkInput(false) && !isset($AttachFailure)) {
333
 
                if ($mailbox == "All Folders") {
334
 
                        /* We entered compose via the search results page */
335
 
                        $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
336
 
                }
 
345
        if ($mailbox == "All Folders") {
 
346
            /* We entered compose via the search results page */
 
347
            $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
 
348
        }
337
349
        $urlMailbox = urlencode (trim($mailbox));
338
350
        if (! isset($passed_id)) {
339
351
            $passed_id = 0;
340
352
        }
341
 
        /*
 
353
        /**
342
354
         * Set $default_charset to correspond with the user's selection
343
355
         * of language interface.
344
356
         */
345
357
        set_my_charset();
346
 
        /*
 
358
        /**
347
359
         * This is to change all newlines to \n
348
360
         * We'll change them to \r\n later (in the sendMessage function)
349
361
         */
350
362
        $body = str_replace("\r\n", "\n", $body);
351
363
        $body = str_replace("\r", "\n", $body);
352
364
 
353
 
        /*
 
365
        /**
354
366
         * Rewrap $body so that no line is bigger than $editor_size
355
367
         * This should only really kick in the sqWordWrap function
356
368
         * if the browser doesn't support "VIRTUAL" as the wrap type.
359
371
        $newBody = '';
360
372
        foreach ($body as $line) {
361
373
            if( $line <> '-- ' ) {
362
 
               $line = rtrim($line);
 
374
                $line = rtrim($line);
363
375
            }
364
376
            if (strlen($line) <= $editor_size + 1) {
365
377
                $newBody .= $line . "\n";
382
394
        unset($compose_messages[$session]);
383
395
        if ( isset($delete_draft)) {
384
396
            Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
385
 
                   "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
 
397
                    "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
386
398
            exit();
387
399
        }
388
400
        if ($compose_new_win == '1') {
391
403
        }
392
404
        else {
393
405
            Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
394
 
                   "&startMessage=$startMessage&mail_sent=yes");
 
406
                    "&startMessage=$startMessage");
395
407
        }
396
408
    } else {
397
409
        if ($compose_new_win == '1') {
401
413
            displayPageHeader($color, $mailbox);
402
414
        }
403
415
        if (isset($AttachFailure)) {
404
 
             plain_error_message(_("Could not move/copy file. File not attached"),
405
 
                                 $color);
 
416
            plain_error_message(_("Could not move/copy file. File not attached"),
 
417
                    $color);
406
418
        }
407
419
        checkInput(true);
408
420
        showInputForm($session);
409
421
        /* sqimap_logout($imapConnection); */
410
422
    }
411
423
} elseif (isset($html_addr_search_done)) {
412
 
        if ($compose_new_win == '1') {
413
 
            compose_Header($color, $mailbox);
414
 
        }
415
 
        else {
416
 
            displayPageHeader($color, $mailbox);
417
 
        }
 
424
    if ($compose_new_win == '1') {
 
425
        compose_Header($color, $mailbox);
 
426
    }
 
427
    else {
 
428
        displayPageHeader($color, $mailbox);
 
429
    }
418
430
 
419
431
    if (isset($send_to_search) && is_array($send_to_search)) {
420
432
        foreach ($send_to_search as $k => $v) {
441
453
    showInputForm($session);
442
454
} elseif (isset($html_addr_search)) {
443
455
    if (isset($_FILES['attachfile']) &&
444
 
        $_FILES['attachfile']['tmp_name'] &&
445
 
        $_FILES['attachfile']['tmp_name'] != 'none') {
 
456
            $_FILES['attachfile']['tmp_name'] &&
 
457
            $_FILES['attachfile']['tmp_name'] != 'none') {
446
458
        if(saveAttachedFiles($session)) {
447
459
            plain_error_message(_("Could not move/copy file. File not attached"), $color);
448
460
        }
456
468
    if (saveAttachedFiles($session)) {
457
469
        plain_error_message(_("Could not move/copy file. File not attached"), $color);
458
470
    }
459
 
        if ($compose_new_win == '1') {
460
 
            compose_Header($color, $mailbox);
461
 
        }
462
 
        else {
463
 
            displayPageHeader($color, $mailbox);
464
 
        }
 
471
    if ($compose_new_win == '1') {
 
472
        compose_Header($color, $mailbox);
 
473
    } else {
 
474
        displayPageHeader($color, $mailbox);
 
475
    }
465
476
    showInputForm($session);
466
477
}
467
478
elseif (isset($sigappend)) {
468
 
    $signature = $idents[$identity]['signature'];
469
 
 
 
479
    $idents = getPref($data_dir, $username, 'identities', 0);
 
480
    if ($idents > 1) {
 
481
       if ($identity == 'default') {
 
482
          $no = 'g';
 
483
       } else {
 
484
          $no = $identity;
 
485
       }
 
486
       $signature = getSig($data_dir, $username, $no);
 
487
    }
470
488
    $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature;
471
489
    if ($compose_new_win == '1') {
472
 
         compose_Header($color, $mailbox);
 
490
        compose_Header($color, $mailbox);
473
491
    } else {
474
492
        displayPageHeader($color, $mailbox);
475
493
    }
476
494
    showInputForm($session);
477
495
} elseif (isset($do_delete)) {
478
 
        if ($compose_new_win == '1') {
479
 
            compose_Header($color, $mailbox);
480
 
        }
481
 
        else {
482
 
            displayPageHeader($color, $mailbox);
483
 
        }
 
496
    if ($compose_new_win == '1') {
 
497
        compose_Header($color, $mailbox);
 
498
    } else {
 
499
        displayPageHeader($color, $mailbox);
 
500
    }
484
501
 
485
502
    if (isset($delete) && is_array($delete)) {
486
503
        $composeMessage = $compose_messages[$session];
505
522
     */
506
523
 
507
524
    if ($compose_new_win == '1') {
508
 
       compose_Header($color, $mailbox);
 
525
        compose_Header($color, $mailbox);
509
526
    } else {
510
 
       displayPageHeader($color, $mailbox);
 
527
        displayPageHeader($color, $mailbox);
511
528
    }
512
529
 
513
530
    $newmail = true;
529
546
 
530
547
    /* in case the origin is not read_body.php */
531
548
    if (isset($send_to)) {
532
 
       $values['send_to'] = $send_to;
 
549
        $values['send_to'] = $send_to;
533
550
    }
534
551
    if (isset($send_to_cc)) {
535
 
       $values['send_to_cc'] = $send_to_cc;
 
552
        $values['send_to_cc'] = $send_to_cc;
536
553
    }
537
554
    if (isset($send_to_bcc)) {
538
 
       $values['send_to_bcc'] = $send_to_bcc;
 
555
        $values['send_to_bcc'] = $send_to_bcc;
539
556
    }
540
557
    if (isset($subject)) {
541
 
       $values['subject'] = $subject;
 
558
        $values['subject'] = $subject;
542
559
    }
543
560
    showInputForm($session, $values);
544
561
}
547
564
 
548
565
/**************** Only function definitions go below *************/
549
566
 
550
 
function getforwardSubject($subject)
551
 
{
552
 
    if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
553
 
        (substr(strtolower($subject), 0, 5) != '[fwd:') &&
554
 
        (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
555
 
        $subject = '[Fwd: ' . $subject . ']';
556
 
    }
557
 
    return $subject;
558
 
}
559
567
 
560
568
/* This function is used when not sending or adding attachments */
561
569
function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
562
 
    global $editor_size, $default_use_priority, $body, $idents,
563
 
           $use_signature, $composesession, $data_dir, $username,
564
 
           $username, $key, $imapServerAddress, $imapPort, $compose_messages,
565
 
           $composeMessage;
 
570
    global $editor_size, $default_use_priority, $body,
 
571
        $use_signature, $composesession, $data_dir, $username,
 
572
        $username, $key, $imapServerAddress, $imapPort, $compose_messages,
 
573
        $composeMessage;
566
574
    global $languages, $squirrelmail_language, $default_charset;
567
575
 
 
576
    /*
 
577
     * Set $default_charset to correspond with the user's selection
 
578
     * of language interface. $default_charset global is not correct,
 
579
     * if message is composed in new window.
 
580
     */
 
581
    set_my_charset();
 
582
 
568
583
    $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
569
584
    $mailprio = 3;
570
585
 
571
586
    if ($passed_id) {
572
587
        $imapConnection = sqimap_login($username, $key, $imapServerAddress,
573
 
        $imapPort, 0);
 
588
                $imapPort, 0);
574
589
 
575
590
        sqimap_mailbox_select($imapConnection, $mailbox);
576
591
        $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
580
595
            /* redefine the messsage in case of message/rfc822 */
581
596
            $message = $message->getEntity($passed_ent_id);
582
597
            /* message is an entity which contains the envelope and type0=message
583
 
            * and type1=rfc822. The actual entities are childs from
584
 
            * $message->entities[0]. That's where the encoding and is located
585
 
            */
 
598
             * and type1=rfc822. The actual entities are childs from
 
599
             * $message->entities[0]. That's where the encoding and is located
 
600
             */
586
601
 
587
602
            $entities = $message->entities[0]->findDisplayEntity
588
 
            (array(), $alt_order = array('text/plain'));
 
603
                (array(), $alt_order = array('text/plain'));
589
604
            if (!count($entities)) {
590
605
                $entities = $message->entities[0]->findDisplayEntity
591
 
                (array(), $alt_order = array('text/plain','html/plain'));
 
606
                    (array(), $alt_order = array('text/plain','html/plain'));
592
607
            }
593
608
            $orig_header = $message->rfc822_header; /* here is the envelope located */
594
609
            /* redefine the message for picking up the attachments */
609
624
            $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
610
625
            $body_part_entity = $message->getEntity($ent);
611
626
            $bodypart = decodeBody($unencoded_bodypart,
612
 
            $body_part_entity->header->encoding);
 
627
                    $body_part_entity->header->encoding);
613
628
            if ($type1 == 'html') {
614
629
                $bodypart = str_replace("\n", ' ', $bodypart);
615
630
                $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
616
631
                $bodypart = str_replace(array('&nbsp;','&gt;','&lt;'),array(' ','>','<'),$bodypart);
617
632
                $bodypart = strip_tags($bodypart);
618
 
 
619
633
            }
620
634
            if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
621
 
                function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
 
635
                    function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
622
636
                if (mb_detect_encoding($bodypart) != 'ASCII') {
623
637
                    $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
624
638
                }
625
639
            }
626
640
 
627
 
        if (isset($body_part_entity->header->parameters['charset'])) {
628
 
            $actual = $body_part_entity->header->parameters['charset'];
629
 
        } else {
630
 
            $actual = 'us-ascii';
631
 
        }
632
 
 
633
 
        if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
634
 
        $bodypart = charset_decode($actual,$bodypart);
635
 
        }
 
641
            // charset encoding in compose form stuff
 
642
            if (isset($body_part_entity->header->parameters['charset'])) {
 
643
                $actual = $body_part_entity->header->parameters['charset'];
 
644
            } else {
 
645
                $actual = 'us-ascii';
 
646
            }
 
647
            if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
 
648
                $bodypart = charset_convert($actual,$bodypart,$default_charset,false);
 
649
            }
 
650
            // end of charset encoding in compose
636
651
 
637
652
            $body .= $bodypart;
638
653
        }
647
662
        //ClearAttachments($session);
648
663
 
649
664
        $identity = '';
 
665
        $idents = getPref($data_dir, $username, 'identities');
650
666
        $from_o = $orig_header->from;
 
667
        if (is_array($from_o)) {
 
668
            if (isset($from_o[0])) {
 
669
                $from_o = $from_o[0];
 
670
            }
 
671
        }
651
672
        if (is_object($from_o)) {
652
673
            $orig_from = $from_o->getAddress();
653
674
        } else {
655
676
        }
656
677
 
657
678
        $identities = array();
658
 
        if (count($idents) > 1) {
659
 
            foreach($idents as $nr=>$data) {
660
 
                $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
661
 
                if($enc_from_name == $orig_from) {
662
 
                    $identity = $nr;
 
679
        if (!empty($idents) && $idents > 1) {
 
680
            $identities[]  = '"'. getPref($data_dir, $username, 'full_name').
 
681
                '" <'.getPref($data_dir, $username, 'email_address').'>';
 
682
            for ($i = 1; $i < $idents; $i++) {
 
683
                $enc_from_name = '"'.
 
684
                    getPref($data_dir, $username, 'full_name' . $i) .
 
685
                    '" <' .
 
686
                    getPref($data_dir, $username, 'email_address' . $i) . '>';
 
687
                if ($enc_from_name == $orig_from && $i) {
 
688
                    $identity = $i;
663
689
                    break;
664
690
                }
665
691
                $identities[] = $enc_from_name;
669
695
            if ($identity_match) {
670
696
                $identity = $identity_match;
671
697
            }
672
 
        // we need identiy here fore draft case #845290
673
 
        // echo $identity."leer";
674
698
        }
675
699
 
676
700
        switch ($action) {
677
 
        case ('draft'):
678
 
            $use_signature = FALSE;
679
 
            $composeMessage->rfc822_header = $orig_header;
680
 
            $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
681
 
            $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
682
 
            $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
683
 
            $send_from = $orig_header->getAddr_s('from');
684
 
            $send_from_parts = new AddressStructure();
685
 
            $send_from_parts = $orig_header->parseAddress($send_from);
686
 
            $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host;
687
 
            $identities = get_identities();
688
 
            if (count($identities) > 0) {
689
 
                foreach($identities as $iddata) {
690
 
                    if ($send_from_add == $iddata['email_address']) {
691
 
                        $identity = $iddata['index'];
692
 
                        break;
 
701
            case ('draft'):
 
702
                $use_signature = FALSE;
 
703
                $composeMessage->rfc822_header = $orig_header;
 
704
                $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
 
705
                $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
 
706
                $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
 
707
                $subject = decodeHeader($orig_header->subject,false,false,true);
 
708
                /* remember the references and in-reply-to headers in case of an reply */
 
709
                $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
 
710
                $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
 
711
                $body_ary = explode("\n", $body);
 
712
                $cnt = count($body_ary) ;
 
713
                $body = '';
 
714
                for ($i=0; $i < $cnt; $i++) {
 
715
                    if (!ereg("^[>\\s]*$", $body_ary[$i])  || !$body_ary[$i]) {
 
716
                        sqWordWrap($body_ary[$i], $editor_size );
 
717
                        $body .= $body_ary[$i] . "\n";
693
718
                    }
694
 
                }
695
 
            }
696
 
            $subject = decodeHeader($orig_header->subject,false,true,true);
697
 
//            /* remember the references and in-reply-to headers in case of an reply */
698
 
            $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
699
 
            $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
700
 
            $body_ary = explode("\n", $body);
701
 
            $cnt = count($body_ary) ;
702
 
            $body = '';
703
 
            for ($i=0; $i < $cnt; $i++) {
704
 
                if (!ereg("^[>\\s]*$", $body_ary[$i])  || !$body_ary[$i]) {
705
 
                    sqWordWrap($body_ary[$i], $editor_size );
706
 
                    $body .= $body_ary[$i] . "\n";
707
 
                }
708
 
                unset($body_ary[$i]);
709
 
            }
710
 
            sqUnWordWrap($body);
711
 
            $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
712
 
            break;
713
 
        case ('edit_as_new'):
714
 
            $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
715
 
            $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
716
 
            $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
717
 
            $subject = decodeHeader($orig_header->subject,false,true,true);
718
 
            $mailprio = $orig_header->priority;
719
 
            $orig_from = '';
720
 
            $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
721
 
            sqUnWordWrap($body);
722
 
            break;
723
 
        case ('forward'):
724
 
            $send_to = '';
725
 
            $subject = getforwardSubject(decodeHeader($orig_header->subject,false,true,true));
726
 
            $body = getforwardHeader($orig_header) . $body;
727
 
            sqUnWordWrap($body);
728
 
            $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
729
 
            $body = "\n" . $body;
730
 
            break;
731
 
        case ('forward_as_attachment'):
732
 
            $subject = getforwardSubject(decodeHeader($orig_header->subject,false,true,true));
733
 
            $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
734
 
            $body = '';
735
 
            break;
736
 
        case ('reply_all'):
737
 
            if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) {
738
 
                $send_to = $orig_header->getAddr_s('mail_followup_to');
739
 
            } else {
 
719
                    unset($body_ary[$i]);
 
720
                }
 
721
                sqUnWordWrap($body);
 
722
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
 
723
                break;
 
724
            case ('edit_as_new'):
 
725
                $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true);
 
726
                $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true);
 
727
                $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true);
 
728
                $subject = decodeHeader($orig_header->subject,false,false,true);
 
729
                $mailprio = $orig_header->priority;
 
730
                $orig_from = '';
 
731
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
 
732
                sqUnWordWrap($body);
 
733
                break;
 
734
            case ('forward'):
 
735
                $send_to = '';
 
736
                $subject = decodeHeader($orig_header->subject,false,false,true);
 
737
                if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
 
738
                    (substr(strtolower($subject), 0, 5) != '[fwd:') &&
 
739
                    (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
 
740
                    $subject = '[Fwd: ' . $subject . ']';
 
741
                }
 
742
                $body = getforwardHeader($orig_header) . $body;
 
743
                sqUnWordWrap($body);
 
744
                $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
 
745
                $body = "\n" . $body;
 
746
                break;
 
747
            case ('forward_as_attachment'):
 
748
                $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
 
749
                $body = '';
 
750
                break;
 
751
            case ('reply_all'):
740
752
                $send_to_cc = replyAllString($orig_header);
741
 
                $send_to_cc = decodeHeader($send_to_cc,false,true,true);
742
 
            }
743
 
        case ('reply'):
744
 
            // skip this if send_to was already set right above here
745
 
            if(!$send_to) {
 
753
                $send_to_cc = decodeHeader($send_to_cc,false,false,true);
 
754
            case ('reply'):
746
755
                $send_to = $orig_header->reply_to;
747
756
                if (is_array($send_to) && count($send_to)) {
748
757
                    $send_to = $orig_header->getAddr_s('reply_to');
749
 
                } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
 
758
                } else if (is_object($send_to)) { /* unnessecarry, just for falesafe purpose */
750
759
                    $send_to = $orig_header->getAddr_s('reply_to');
751
760
                } else {
752
761
                    $send_to = $orig_header->getAddr_s('from');
753
762
                }
754
 
            }
755
 
            $send_to = decodeHeader($send_to,false,true,true);
756
 
            $subject = decodeHeader($orig_header->subject,false,true,true);
757
 
            $subject = str_replace('"', "'", $subject);
758
 
            $subject = trim($subject);
759
 
            if (substr(strtolower($subject), 0, 3) != 're:') {
760
 
                $subject = 'Re: ' . $subject;
761
 
            }
762
 
            /* this corrects some wrapping/quoting problems on replies */
763
 
            $rewrap_body = explode("\n", $body);
764
 
            $from =  (is_array($orig_header->from)) ? $orig_header->from[0] : $orig_header->from;
765
 
            sqUnWordWrap($body);    // unwrap and then reset it?!
766
 
            $body = '';
767
 
            $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
768
 
            foreach ($rewrap_body as $line) {
769
 
                if ($strip_sigs && substr($line,0,3) == '-- ') {
770
 
            break;
771
 
                }
772
 
                sqWordWrap($line, ($editor_size));
773
 
                if (preg_match("/^(>+)/", $line, $matches)) {
774
 
                    $gt = $matches[1];
775
 
                    $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
776
 
                } else {
777
 
                    $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
778
 
                }
779
 
            }
780
 
            $body = getReplyCitation($from) . $body;
781
 
            $composeMessage->reply_rfc822_header = $orig_header;
 
763
                $send_to = decodeHeader($send_to,false,false,true);
 
764
                $subject = decodeHeader($orig_header->subject,false,false,true);
 
765
//                $subject = str_replace('"', '&quot;', $subject);
 
766
                $subject = trim($subject);
 
767
                if (substr(strtolower($subject), 0, 3) != 're:') {
 
768
                    $subject = 'Re: ' . $subject;
 
769
                }
 
770
                /* this corrects some wrapping/quoting problems on replies */
 
771
                $rewrap_body = explode("\n", $body);
 
772
                $from =  (is_array($orig_header->from)) ? $orig_header->from[0] : $orig_header->from;
 
773
                sqUnWordWrap($body);
 
774
                $body = '';
 
775
                $cnt = count($rewrap_body);
 
776
                for ($i=0;$i<$cnt;$i++) {
 
777
                    sqWordWrap($rewrap_body[$i], ($editor_size));
 
778
                    if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
 
779
                        $gt = $matches[1];
 
780
                        $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($rewrap_body[$i])) ."\n";
 
781
                    } else {
 
782
                        $body .= '> ' . str_replace("\n", "\n> ", rtrim($rewrap_body[$i])) . "\n";
 
783
                    }
 
784
                    unset($rewrap_body[$i]);
 
785
                }
 
786
                $body = getReplyCitation($from , $orig_header->date) . $body;
 
787
                $composeMessage->reply_rfc822_header = $orig_header;
782
788
 
783
 
            break;
784
 
        default:
785
 
            break;
 
789
                break;
 
790
            default:
 
791
                break;
786
792
        }
787
793
        $compose_messages[$session] = $composeMessage;
788
794
        sqsession_register($compose_messages, 'compose_messages');
790
796
        sqimap_logout($imapConnection);
791
797
    }
792
798
    $ret = array( 'send_to' => $send_to,
793
 
                  'send_to_cc' => $send_to_cc,
794
 
                  'send_to_bcc' => $send_to_bcc,
795
 
                  'subject' => $subject,
796
 
                  'mailprio' => $mailprio,
797
 
                  'body' => $body,
798
 
                  'identity' => $identity );
 
799
            'send_to_cc' => $send_to_cc,
 
800
            'send_to_bcc' => $send_to_bcc,
 
801
            'subject' => $subject,
 
802
            'mailprio' => $mailprio,
 
803
            'body' => $body,
 
804
            'identity' => $identity );
799
805
 
800
806
    return ($ret);
801
807
} /* function newMail() */
802
808
 
803
809
function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
804
 
    global $attachment_dir, $username, $data_dir, $squirrelmail_language;
 
810
    global $attachment_dir, $username, $data_dir, $squirrelmail_language, $languages;
805
811
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
806
812
    if (!count($message->entities) ||
807
 
       ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
 
813
            ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
808
814
        if ( !in_array($message->entity_id, $entities) && $message->entity_id) {
809
 
           switch ($message->type0) {
810
 
           case 'message':
811
 
                if ($message->type1 == 'rfc822') {
812
 
                    $filename = $message->rfc822_header->subject;
813
 
                    if ($filename == "") {
814
 
                        $filename = "untitled-".$message->entity_id;
815
 
                    }
816
 
                    $filename .= '.msg';
817
 
                 } else {
818
 
                   $filename = $message->getFilename();
819
 
                 }
820
 
             break;
821
 
           default:
822
 
             if (!$message->mime_header) { /* temporary hack */
823
 
                 $message->mime_header = $message->header;
824
 
             }
825
 
             $filename = $message->getFilename();
826
 
             break;
827
 
           }
828
 
           $filename = str_replace('&nbsp;', ' ', decodeHeader($filename));
829
 
           if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
830
 
               function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
 
815
            switch ($message->type0) {
 
816
                case 'message':
 
817
                    if ($message->type1 == 'rfc822') {
 
818
                        $filename = $message->rfc822_header->subject;
 
819
                        if ($filename == "") {
 
820
                            $filename = "untitled-".$message->entity_id;
 
821
                        }
 
822
                        $filename .= '.msg';
 
823
                    } else {
 
824
                        $filename = $message->getFilename();
 
825
                    }
 
826
                    break;
 
827
                default:
 
828
                    if (!$message->mime_header) { /* temporary hack */
 
829
                        $message->mime_header = $message->header;
 
830
                    }
 
831
                    $filename = $message->getFilename();
 
832
                    break;
 
833
            }
 
834
            $filename = decodeHeader($filename, false, false);
 
835
            if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
 
836
                    function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
831
837
                $filename =  $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
832
 
           }
833
 
           $localfilename = GenerateRandomString(32, '', 7);
834
 
           $full_localfilename = "$hashed_attachment_dir/$localfilename";
835
 
           while (file_exists($full_localfilename)) {
836
 
               $localfilename = GenerateRandomString(32, '', 7);
837
 
               $full_localfilename = "$hashed_attachment_dir/$localfilename";
838
 
           }
839
 
           $message->att_local_name = $full_localfilename;
840
 
 
841
 
       $composeMessage->initAttachment($message->type0.'/'.$message->type1,$filename,
842
 
             $full_localfilename);
843
 
 
844
 
           /* Write Attachment to file */
845
 
           $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
846
 
           fputs($fp, decodeBody(mime_fetch_body($imapConnection,
847
 
              $passed_id, $message->entity_id),
848
 
              $message->header->encoding));
849
 
           fclose ($fp);
 
838
            }
 
839
            $localfilename = GenerateRandomString(32, '', 7);
 
840
            $full_localfilename = "$hashed_attachment_dir/$localfilename";
 
841
            while (file_exists($full_localfilename)) {
 
842
                $localfilename = GenerateRandomString(32, '', 7);
 
843
                $full_localfilename = "$hashed_attachment_dir/$localfilename";
 
844
            }
 
845
            $message->att_local_name = $full_localfilename;
 
846
 
 
847
            $composeMessage->initAttachment($message->type0.'/'.$message->type1,$filename,
 
848
                    $full_localfilename);
 
849
 
 
850
            /* Write Attachment to file */
 
851
            $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
 
852
            fputs($fp, decodeBody(mime_fetch_body($imapConnection,
 
853
                            $passed_id, $message->entity_id),
 
854
                        $message->header->encoding));
 
855
            fclose ($fp);
850
856
        }
851
857
    } else {
852
858
        for ($i=0, $entCount=count($message->entities); $i<$entCount;$i++) {
857
863
}
858
864
 
859
865
function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
860
 
                                      $passed_ent_id='', $imapConnection) {
 
866
        $passed_ent_id='', $imapConnection) {
861
867
    global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
862
868
    $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
863
869
    if (!$passed_ent_id) {
864
870
        $body_a = sqimap_run_command($imapConnection,
865
 
                                    'FETCH '.$passed_id.' RFC822',
866
 
                                    TRUE, $response, $readmessage,
867
 
                                    $uid_support);
 
871
                'FETCH '.$passed_id.' RFC822',
 
872
                TRUE, $response, $readmessage,
 
873
                $uid_support);
868
874
    } else {
869
875
        $body_a = sqimap_run_command($imapConnection,
870
 
                                     'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
871
 
                                     TRUE, $response, $readmessage, $uid_support);
 
876
                'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
 
877
                TRUE, $response, $readmessage, $uid_support);
872
878
        $message = $message->parent;
873
879
    }
874
880
    if ($response == 'OK') {
884
890
        fwrite ($fp, $body);
885
891
        fclose($fp);
886
892
        $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
887
 
                         $full_localfilename);
 
893
                $full_localfilename);
888
894
    }
889
895
    return $composeMessage;
890
896
}
891
897
 
892
898
function showInputForm ($session, $values=false) {
893
899
    global $send_to, $send_to_cc, $body, $startMessage,
894
 
           $passed_body, $color, $use_signature, $signature, $prefix_sig,
895
 
           $editor_size, $attachments, $subject, $newmail,
896
 
           $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
897
 
           $from_htmladdr_search, $location_of_buttons, $attachment_dir,
898
 
           $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
899
 
           $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
900
 
           $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
901
 
           $username, $compose_messages, $composesession, $default_charset;
 
900
        $passed_body, $color, $use_signature, $signature, $prefix_sig,
 
901
        $editor_size, $editor_height, $attachments, $subject, $newmail,
 
902
        $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
 
903
        $from_htmladdr_search, $location_of_buttons, $attachment_dir,
 
904
        $username, $data_dir, $identity, $draft_id, $delete_draft,
 
905
        $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
 
906
        $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
 
907
        $username, $compose_messages, $composesession, $default_charset;
902
908
 
903
909
    $composeMessage = $compose_messages[$session];
904
 
 
905
910
    if ($values) {
906
 
       $send_to = $values['send_to'];
907
 
       $send_to_cc = $values['send_to_cc'];
908
 
       $send_to_bcc = $values['send_to_bcc'];
909
 
       $subject = $values['subject'];
910
 
       $mailprio = $values['mailprio'];
911
 
       $body = $values['body'];
912
 
       $identity = (int) $values['identity'];
 
911
        $send_to = $values['send_to'];
 
912
        $send_to_cc = $values['send_to_cc'];
 
913
        $send_to_bcc = $values['send_to_bcc'];
 
914
        $subject = $values['subject'];
 
915
        $mailprio = $values['mailprio'];
 
916
        $body = $values['body'];
 
917
        $identity = (int) $values['identity'];
913
918
    } else {
914
 
       $send_to = decodeHeader($send_to);
915
 
       $send_to_cc = decodeHeader($send_to_cc);
916
 
       $send_to_bcc = decodeHeader($send_to_bcc);
 
919
        $send_to = decodeHeader($send_to, true, false);
 
920
        $send_to_cc = decodeHeader($send_to_cc, true, false);
 
921
        $send_to_bcc = decodeHeader($send_to_bcc, true, false);
917
922
    }
918
923
 
919
924
    if ($use_javascript_addr_book) {
920
 
        echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
921
 
             'function open_abook() { ' . "\n" .
922
 
             '  var nwin = window.open("addrbook_popup.php","abookpopup",' .
923
 
             '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
924
 
             '  if((!nwin.opener) && (document.windows != null))' . "\n" .
925
 
             '    nwin.opener = document.windows;' . "\n" .
926
 
             "}\n" .
927
 
             "// -->\n</SCRIPT>\n\n";
 
925
        echo "\n". '<script language="JavaScript">'."\n<!--\n" .
 
926
            'function open_abook() { ' . "\n" .
 
927
            '  var nwin = window.open("addrbook_popup.php","abookpopup",' .
 
928
            '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
 
929
            '  if((!nwin.opener) && (document.windows != null))' . "\n" .
 
930
            '    nwin.opener = document.windows;' . "\n" .
 
931
            "}\n" .
 
932
            "// -->\n</script>\n\n";
928
933
    }
929
934
 
930
935
    echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
931
 
         'enctype="multipart/form-data"';
 
936
        'enctype="multipart/form-data"';
932
937
    do_hook('compose_form');
933
938
 
934
939
    echo ">\n";
935
940
 
936
 
    echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
 
941
    echo addHidden('startMessage', $startMessage);
937
942
 
938
943
    if ($action == 'draft') {
939
 
        echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
 
944
        echo addHidden('delete_draft', $passed_id);
940
945
    }
941
946
    if (isset($delete_draft)) {
942
 
        echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
 
947
        echo addHidden('delete_draft', $delete_draft);
943
948
    }
944
949
    if (isset($session)) {
945
 
        echo '<input type="hidden" name="session" value="' . $session . "\">\n";
 
950
        echo addHidden('session', $session);
946
951
    }
947
952
 
948
953
    if (isset($passed_id)) {
949
 
        echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
 
954
        echo addHidden('passed_id', $passed_id);
950
955
    }
951
956
 
952
957
    if ($saved_draft == 'yes') {
953
 
        echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
 
958
        echo '<br /><center><b>'. _("Draft Saved").'</center></b>';
954
959
    }
955
960
    if ($mail_sent == 'yes') {
956
 
        echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
 
961
        echo '<br /><center><b>'. _("Your Message has been sent.").'</center></b>';
957
962
    }
958
963
    echo '<table align="center" cellspacing="0" border="0">' . "\n";
959
964
    if ($compose_new_win == '1') {
960
 
        echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
961
 
             '   <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
 
965
        echo '<table align="center" bgcolor="'.$color[0].'" width="100%" border="0">'."\n" .
 
966
            '   <tr><td></td>'. html_tag( 'td', '', 'right' ) . '<input type="button" name="Close" onClick="return self.close()" value="'._("Close").'" /></td></tr>'."\n";
962
967
    }
963
968
    if ($location_of_buttons == 'top') {
964
969
        showComposeButtonRow();
965
970
    }
966
971
 
967
972
    /* display select list for identities */
968
 
    if (count($idents) > 1) {
 
973
    $idents = getPref($data_dir, $username, 'identities', 0);
 
974
    if ($idents > 1) {
 
975
        $fn = getPref($data_dir, $username, 'full_name');
 
976
        $em = getPref($data_dir, $username, 'email_address');
969
977
        echo '   <tr>' . "\n" .
970
 
                    html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
971
 
                    _("From:") . '</td>' . "\n" .
972
 
                    html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
973
 
             '         <select name="identity">' . "\n" ;
974
 
        foreach($idents as $id=>$data) {
975
 
            echo '<option value="'.$id.'"';
976
 
            if($id == $identity) {
977
 
                echo ' selected';
978
 
            }
979
 
            echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
980
 
                 "</option>\n";
 
978
            html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
 
979
            _("From:") . '</td>' . "\n" .
 
980
            html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
 
981
            '         <select name="identity">' . "\n" .
 
982
            '         <option value="default">' .
 
983
            htmlspecialchars($fn);
 
984
        if ($em != '') {
 
985
            if ($fn != '') {
 
986
                echo htmlspecialchars(' <' . $em . '>') . "\n";
 
987
            } else {
 
988
                echo htmlspecialchars($em) . "\n";
 
989
            }
 
990
        }
 
991
        echo '</option>';
 
992
        for ($i = 1; $i < $idents; $i ++) {
 
993
            $fn = getPref($data_dir, $username, 'full_name' . $i);
 
994
            $em = getPref($data_dir, $username, 'email_address' . $i);
 
995
 
 
996
            echo '<option value="' . $i . '"';
 
997
            if (isset($identity) && $identity == $i) {
 
998
                echo ' selected="selected"';
 
999
            }
 
1000
            echo '>' . htmlspecialchars($fn);
 
1001
            if ($em != '') {
 
1002
                if ($fn != '') {
 
1003
                    echo htmlspecialchars(' <' . $em . '>') . "\n";
 
1004
                } else {
 
1005
                    echo htmlspecialchars($em) . "\n";
 
1006
                }
 
1007
            }
 
1008
            echo '</option>';
981
1009
        }
982
1010
 
983
1011
        echo '</select>' . "\n" .
984
 
             '      </td>' . "\n" .
985
 
             '   </tr>' . "\n";
 
1012
            '      </td>' . "\n" .
 
1013
            '   </tr>' . "\n";
986
1014
    }
 
1015
 
987
1016
    echo '   <tr>' . "\n" .
988
 
                html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
989
 
                _("To:") . '</TD>' . "\n" .
990
 
                html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
991
 
         '         <input type="text" name="send_to" value="' .
992
 
                   $send_to . '" size="60" /><br />' . "\n" .
993
 
         '      </td>' . "\n" .
994
 
         '   </tr>' . "\n" .
995
 
         '   <tr>' . "\n" .
996
 
                html_tag( 'td', '', 'right', $color[4] ) .
997
 
                _("CC:") . '</td>' . "\n" .
998
 
                html_tag( 'td', '', 'left', $color[4] ) .
999
 
         '         <input type="text" name="send_to_cc" size="60" value="' .
1000
 
                   $send_to_cc . '" /><br />' . "\n" .
1001
 
         '      </td>' . "\n" .
1002
 
         '   </tr>' . "\n" .
1003
 
         '   <tr>' . "\n" .
1004
 
                html_tag( 'td', '', 'right', $color[4] ) .
1005
 
                _("BCC:") . '</td>' . "\n" .
1006
 
                html_tag( 'td', '', 'left', $color[4] ) .
1007
 
         '         <input type="text" name="send_to_bcc" value="' .
1008
 
                $send_to_bcc . '" size="60" /><br />' . "\n" .
1009
 
         '      </td>' . "\n" .
1010
 
         '   </tr>' . "\n" .
1011
 
         '   <tr>' . "\n" .
1012
 
                html_tag( 'td', '', 'right', $color[4] ) .
1013
 
                _("Subject:") . '</td>' . "\n" .
1014
 
                html_tag( 'td', '', 'left', $color[4] ) . "\n";
1015
 
    echo '         <input type="text" name="subject" size="60" value="' .
1016
 
                   $subject . '" />' . "\n" .
1017
 
         '      </td>' . "\n" .
1018
 
         '   </tr>' . "\n\n";
 
1017
        html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
 
1018
        _("To") . ':</td>' . "\n" .
 
1019
        html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
 
1020
        addInput('send_to', $send_to, 60). '<br />' . "\n" .
 
1021
        '      </td>' . "\n" .
 
1022
        '   </tr>' . "\n" .
 
1023
        '   <tr>' . "\n" .
 
1024
        html_tag( 'td', '', 'right', $color[4] ) .
 
1025
        _("Cc") . ':</td>' . "\n" .
 
1026
        html_tag( 'td', '', 'left', $color[4] ) .
 
1027
        addInput('send_to_cc', $send_to_cc, 60). '<br />' . "\n" .
 
1028
        '      </td>' . "\n" .
 
1029
        '   </tr>' . "\n" .
 
1030
        '   <tr>' . "\n" .
 
1031
        html_tag( 'td', '', 'right', $color[4] ) .
 
1032
        _("Bcc") . ':</td>' . "\n" .
 
1033
        html_tag( 'td', '', 'left', $color[4] ) .
 
1034
        addInput('send_to_bcc', $send_to_bcc, 60).'<br />' . "\n" .
 
1035
        '      </td>' . "\n" .
 
1036
        '   </tr>' . "\n" .
 
1037
        '   <tr>' . "\n" .
 
1038
        html_tag( 'td', '', 'right', $color[4] ) .
 
1039
        _("Subject") . ':</td>' . "\n" .
 
1040
        html_tag( 'td', '', 'left', $color[4] ) . "\n";
 
1041
    echo '         '.addInput('subject', $subject, 60).
 
1042
        '      </td>' . "\n" .
 
1043
        '   </tr>' . "\n\n";
1019
1044
 
1020
1045
    if ($location_of_buttons == 'between') {
1021
1046
        showComposeButtonRow();
1023
1048
 
1024
1049
    /* why this distinction? */
1025
1050
    if ($compose_new_win == '1') {
1026
 
        echo '   <TR>' . "\n" .
1027
 
             '      <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
1028
 
             '         <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
1029
 
                       $editor_size . '" WRAP="VIRTUAL">';
 
1051
        echo '   <tr>' . "\n" .
 
1052
            '      <td bgcolor="' . $color[0] . '" colspan="2" align="center">' . "\n" .
 
1053
            '         <textarea name="body" id="body" rows="' . (int)$editor_height .
 
1054
            '" cols="' . (int)$editor_size . '" wrap="virtual">';
1030
1055
    }
1031
1056
    else {
1032
 
        echo '   <TR>' . "\n" .
1033
 
            '      <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
1034
 
            '         &nbsp;&nbsp;<TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
1035
 
                      $editor_size . '" WRAP="VIRTUAL">';
 
1057
        echo '   <tr>' . "\n" .
 
1058
            '      <td bgcolor="' . $color[4] . '" colspan="2">' . "\n" .
 
1059
            '         &nbsp;&nbsp;<textarea name="body" id="body" rows="' . (int)$editor_height .
 
1060
            '" cols="' . (int)$editor_size . '" wrap="virtual">';
1036
1061
    }
1037
1062
 
1038
1063
    if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1039
 
        $signature = $idents[$identity]['signature'];
 
1064
        if ($idents > 1) {
 
1065
            if ($identity == 'default') {
 
1066
                $no = 'g';
 
1067
            } else {
 
1068
                $no = $identity;
 
1069
            }
 
1070
            $signature = getSig($data_dir, $username, $no);
 
1071
        }
1040
1072
 
1041
1073
        if ($sig_first == '1') {
1042
1074
            if ($default_charset == 'iso-2022-jp') {
1043
1075
                echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1044
1076
            } else {
1045
 
            echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader($signature,false,false);
 
1077
                echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader($signature,false,false,true);
1046
1078
            }
1047
 
            echo "\n\n".decodeHeader($body,false,false);
 
1079
            echo "\n\n".htmlspecialchars(decodeHeader($body,false,false,true));
1048
1080
        }
1049
1081
        else {
1050
 
            echo "\n\n".decodeHeader($body,false,false);
 
1082
            echo "\n\n".htmlspecialchars(decodeHeader($body,false,false,true));
1051
1083
            if ($default_charset == 'iso-2022-jp') {
1052
1084
                echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1053
1085
            }else{
1054
 
            echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader($signature,false,false);
 
1086
                echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader($signature,false,false,true);
 
1087
            }
1055
1088
        }
1056
 
    }
1057
 
    }
1058
 
    else {
1059
 
       echo decodeHeader($body,false,false);
 
1089
    } else {
 
1090
        echo htmlspecialchars(decodeHeader($body,false,false,true));
1060
1091
    }
1061
1092
    echo '</textarea><br />' . "\n" .
1062
 
         '      </td>' . "\n" .
1063
 
         '   </tr>' . "\n";
 
1093
        '      </td>' . "\n" .
 
1094
        '   </tr>' . "\n";
1064
1095
 
1065
1096
 
1066
1097
    if ($location_of_buttons == 'bottom') {
1067
1098
        showComposeButtonRow();
1068
1099
    } else {
1069
1100
        echo '   <tr>' . "\n" .
1070
 
                    html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1071
 
             '         <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1072
 
             '         &nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n" .
1073
 
             '      </td>' . "\n" .
1074
 
             '   </tr>' . "\n";
 
1101
            html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
 
1102
            '         ' . addSubmit(_("Send"), 'send').
 
1103
            '         &nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n" .
 
1104
            '      </td>' . "\n" .
 
1105
            '   </tr>' . "\n";
1075
1106
    }
1076
1107
 
1077
1108
    /* This code is for attachments */
1078
 
        if ((bool) ini_get('file_uploads')) {
1079
 
 
1080
 
    /* Calculate the max size for an uploaded file.
1081
 
     * This is advisory for the user because we can't actually prevent
1082
 
     * people to upload too large files. */
1083
 
    $sizes = array();
1084
 
    /* php.ini vars which influence the max for uploads */
1085
 
    $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1086
 
    foreach($configvars as $var) {
1087
 
        /* skip 0 or empty values */
1088
 
        if( $size = getByteSize(ini_get($var)) ) {
1089
 
            $sizes[] = $size;
1090
 
        }
1091
 
    }
1092
 
 
1093
 
    if(count($sizes) > 0) {
1094
 
        $maxsize = '(max.&nbsp;' . show_readable_size( min( $sizes ) ) . ')';
1095
 
    } else {
1096
 
        $maxsize = '';
1097
 
    }
1098
 
    echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
1099
 
    echo '   <tr>' . "\n" .
1100
 
         '      <td colspan="2">' . "\n" .
1101
 
         '         <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
1102
 
                   ' border="0" bgcolor="'.$color[9].'">' . "\n" .
1103
 
         '            <tr>' . "\n" .
1104
 
         '               <td>' . "\n" .
1105
 
         '                 <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
1106
 
                           ' border="0">' . "\n" .
1107
 
         '                    <tr>' . "\n" .
1108
 
                                 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1109
 
                                 _("Attach:") . '</td>' . "\n" .
1110
 
                                 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1111
 
         '                          <input name="attachfile" size="48" type="file" />' . "\n" .
1112
 
         '                          &nbsp;&nbsp;<input type="submit" name="attach"' .
1113
 
                                    ' value="' . _("Add") .'">' . "\n" .
1114
 
                                    $maxsize .
1115
 
         '                       </td>' . "\n" .
1116
 
         '                    </tr>' . "\n";
1117
 
 
1118
 
 
1119
 
    $s_a = array();
1120
 
    if ($composeMessage->entities) {
1121
 
        foreach ($composeMessage->entities as $key => $attachment) {
1122
 
           $attached_file = $attachment->att_local_name;
1123
 
           if ($attachment->att_local_name || $attachment->body_part) {
1124
 
                $attached_filename = decodeHeader($attachment->mime_header->getParameter('name'));
1125
 
                $type = $attachment->mime_header->type0.'/'.
 
1109
    if ((bool) ini_get('file_uploads')) {
 
1110
 
 
1111
        /* Calculate the max size for an uploaded file.
 
1112
         * This is advisory for the user because we can't actually prevent
 
1113
         * people to upload too large files. */
 
1114
        $sizes = array();
 
1115
        /* php.ini vars which influence the max for uploads */
 
1116
        $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
 
1117
        foreach($configvars as $var) {
 
1118
            /* skip 0 or empty values, and -1 which means 'unlimited' */
 
1119
            if( $size = getByteSize(ini_get($var)) ) {
 
1120
                if ( $size != '-1' ) {
 
1121
                    $sizes[] = $size;
 
1122
                }
 
1123
            }
 
1124
        }
 
1125
 
 
1126
        if(count($sizes) > 0) {
 
1127
            $maxsize = '(max.&nbsp;' . show_readable_size( min( $sizes ) ) . ')';
 
1128
            echo addHidden('MAX_FILE_SIZE', min( $sizes ));
 
1129
        } else {
 
1130
            $maxsize = '';
 
1131
        }
 
1132
        echo '   <tr>' . "\n" .
 
1133
            '      <td colspan="2">' . "\n" .
 
1134
            '         <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
 
1135
            ' border="0" bgcolor="'.$color[9].'">' . "\n" .
 
1136
            '            <tr>' . "\n" .
 
1137
            '               <td>' . "\n" .
 
1138
            '                 <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
 
1139
            ' border="0">' . "\n" .
 
1140
            '                    <tr>' . "\n" .
 
1141
            html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
 
1142
            _("Attach:") . '</td>' . "\n" .
 
1143
            html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
 
1144
            '                          <input name="attachfile" size="48" type="file" />' . "\n" .
 
1145
            '                          &nbsp;&nbsp;<input type="submit" name="attach"' .
 
1146
            ' value="' . _("Add") .'" />' . "\n" .
 
1147
            $maxsize .
 
1148
            '                       </td>' . "\n" .
 
1149
            '                    </tr>' . "\n";
 
1150
 
 
1151
        $s_a = array();
 
1152
        if ($composeMessage->entities) {
 
1153
            foreach ($composeMessage->entities as $key => $attachment) {
 
1154
                $attached_file = $attachment->att_local_name;
 
1155
                if ($attachment->att_local_name || $attachment->body_part) {
 
1156
                    $attached_filename = decodeHeader($attachment->mime_header->getParameter('name'));
 
1157
                    $type = $attachment->mime_header->type0.'/'.
1126
1158
                        $attachment->mime_header->type1;
1127
1159
 
1128
 
                $s_a[] = '<table bgcolor="'.$color[0].
1129
 
                '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1130
 
                    $key . "\"></td><td>\n" . $attached_filename .
1131
 
                    '</td><td>-</td><td> ' . $type . '</td><td>('.
1132
 
                    show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
1133
 
           }
1134
 
        }
1135
 
    }
1136
 
    if (count($s_a)) {
1137
 
       foreach ($s_a as $s) {
1138
 
          echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1139
 
       }
1140
 
       echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1141
 
            _("Delete selected attachments") . "\">\n" .
1142
 
            '</td></tr>';
1143
 
    }
1144
 
    echo '                  </table>' . "\n" .
1145
 
         '               </td>' . "\n" .
1146
 
         '            </tr>' . "\n" .
1147
 
         '         </TABLE>' . "\n" .
1148
 
         '      </TD>' . "\n" .
1149
 
         '   </TR>' . "\n";
1150
 
        } // End of file_uploads if-block
 
1160
                    $s_a[] = '<table bgcolor="'.$color[0].
 
1161
                        '" border="0"><tr><td>'.
 
1162
                        addCheckBox('delete[]', FALSE, $key).
 
1163
                        "</td><td>\n" . $attached_filename .
 
1164
                        '</td><td>-</td><td> ' . $type . '</td><td>('.
 
1165
                        show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
 
1166
                }
 
1167
            }
 
1168
        }
 
1169
        if (count($s_a)) {
 
1170
            foreach ($s_a as $s) {
 
1171
                echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
 
1172
            }
 
1173
            echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
 
1174
                _("Delete selected attachments") . "\" />\n" .
 
1175
                '</td></tr>';
 
1176
        }
 
1177
        echo '                  </table>' . "\n" .
 
1178
            '               </td>' . "\n" .
 
1179
            '            </tr>' . "\n" .
 
1180
            '         </table>' . "\n" .
 
1181
            '      </td>' . "\n" .
 
1182
            '   </tr>' . "\n";
 
1183
    } // End of file_uploads if-block
1151
1184
    /* End of attachment code */
1152
1185
    if ($compose_new_win == '1') {
1153
 
        echo '</TABLE>'."\n";
 
1186
        echo '</table>'."\n";
1154
1187
    }
1155
1188
 
1156
 
    echo '</TABLE>' . "\n" .
1157
 
         '<input type="hidden" name="username" value="'. $username . "\">\n" .
1158
 
         '<input type=hidden name=smaction value="' . $action . "\">\n" .
1159
 
         '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1160
 
         "\">\n";
 
1189
    echo '</table>' . "\n" .
 
1190
        addHidden('username', $username).
 
1191
        addHidden('smaction', $action).
 
1192
        addHidden('mailbox', $mailbox);
1161
1193
    /*
1162
1194
       store the complete ComposeMessages array in a hidden input value
1163
1195
       so we can restore them in case of a session timeout.
1164
 
    */
 
1196
     */
1165
1197
    sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER);
1166
 
    echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1167
 
    echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
1168
 
    echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
1169
 
    echo '</FORM>';
 
1198
    echo addHidden('restoremessages', serialize($compose_messages)).
 
1199
        addHidden('composesession', $composesession).
 
1200
        addHidden('querystring', $queryString).
 
1201
        "</form>\n";
1170
1202
    if (!(bool) ini_get('file_uploads')) {
1171
 
      /* File uploads are off, so we didn't show that part of the form.
1172
 
         To avoid bogus bug reports, tell the user why. */
1173
 
      echo 'Because PHP file uploads are turned off, you can not attach files ';
1174
 
      echo "to this message.  Please see your system administrator for details.\r\n";
 
1203
        /* File uploads are off, so we didn't show that part of the form.
 
1204
           To avoid bogus bug reports, tell the user why. */
 
1205
        echo 'Because PHP file uploads are turned off, you can not attach files ';
 
1206
        echo "to this message.  Please see your system administrator for details.\r\n";
1175
1207
    }
1176
1208
 
1177
1209
    do_hook('compose_bottom');
1178
 
    echo '</BODY></HTML>' . "\n";
 
1210
    echo '</body></html>' . "\n";
1179
1211
}
1180
1212
 
1181
1213
 
1182
1214
function showComposeButtonRow() {
1183
1215
    global $use_javascript_addr_book, $save_as_draft,
1184
 
           $default_use_priority, $mailprio, $default_use_mdn,
1185
 
           $request_mdn, $request_dr,
1186
 
           $data_dir, $username;
 
1216
        $default_use_priority, $mailprio, $default_use_mdn,
 
1217
        $request_mdn, $request_dr,
 
1218
        $data_dir, $username;
1187
1219
 
1188
 
    echo '   <TR>' . "\n" .
1189
 
         '      <TD></TD>' . "\n" .
1190
 
         '      <TD>' . "\n";
 
1220
    echo '   <tr>' . "\n" .
 
1221
        '      <td></td>' . "\n" .
 
1222
        '      <td>' . "\n";
1191
1223
    if ($default_use_priority) {
1192
1224
        if(!isset($mailprio)) {
1193
 
            $mailprio = "3";
1194
 
    }
1195
 
    echo '          ' . _("Priority") .': <select name="mailprio">'.
1196
 
         '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
1197
 
         '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
1198
 
         '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
1199
 
         '</select>' . "\n";
 
1225
            $mailprio = '3';
 
1226
        }
 
1227
        echo '          ' . _("Priority") .
 
1228
            addSelect('mailprio', array(
 
1229
                        '1' => _("High"),
 
1230
                        '3' => _("Normal"),
 
1231
                        '5' => _("Low") ), $mailprio, TRUE);
1200
1232
    }
1201
1233
    $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1202
1234
    if ($default_use_mdn) {
1203
1235
        if ($mdn_user_support) {
1204
1236
            echo '          ' . _("Receipt") .': '.
1205
 
            '<input type="checkbox" name="request_mdn" value=1'.
1206
 
        ($request_mdn=='1'?' checked':'') .'>'. _("On Read").
1207
 
            ' <input type="checkbox" name="request_dr" value=1'.
1208
 
        ($request_dr=='1'?' checked':'') .'>'. _("On Delivery");
 
1237
                addCheckBox('request_mdn', $request_mdn == '1', '1'). _("On Read").
 
1238
                addCheckBox('request_dr',  $request_dr  == '1', '1'). _("On Delivery");
1209
1239
        }
1210
1240
    }
1211
1241
 
1212
 
    echo '      </TD>' . "\n" .
1213
 
         '   </TR>' . "\n" .
1214
 
         '   <TR>'  . "\n" .
1215
 
         '      <TD></TD>' . "\n" .
1216
 
         '      <TD>' . "\n" .
1217
 
         '         <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
 
1242
    echo '      </td>' . "\n" .
 
1243
        '   </tr>' . "\n" .
 
1244
        '   <tr>'  . "\n" .
 
1245
        '      <td></td>' . "\n" .
 
1246
        '      <td>' . "\n" .
 
1247
        '         <input type="submit" name="sigappend" value="' . _("Signature") . '" />' . "\n";
1218
1248
    if ($use_javascript_addr_book) {
1219
 
        echo "         <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1220
 
             "            <input type=button value=\\\""._("Addresses").
1221
 
                                 "\\\" onclick='javascript:open_abook();'>\");".
1222
 
             "            // --></SCRIPT><NOSCRIPT>\n".
1223
 
             "            <input type=submit name=\"html_addr_search\" value=\"".
1224
 
                              _("Addresses")."\">".
1225
 
             "         </NOSCRIPT>\n";
 
1249
        echo "         <script language=\"JavaScript\"><!--\n document.write(\"".
 
1250
            "            <input type=button value=\\\""._("Addresses").
 
1251
            "\\\" onclick=\\\"javascript:open_abook();\\\" />\");".
 
1252
            "            // --></script><noscript>\n".
 
1253
            '            <input type="submit" name="html_addr_search" value="'.
 
1254
            _("Addresses").'" />'.
 
1255
            "         </noscript>\n";
1226
1256
    } else {
1227
 
        echo '         <input type=submit name="html_addr_search" value="'.
1228
 
                                 _("Addresses").'">' . "\n";
 
1257
        echo '         <input type="submit" name="html_addr_search" value="'.
 
1258
            _("Addresses").'" />' . "\n";
1229
1259
    }
1230
1260
 
1231
1261
    if ($save_as_draft) {
1232
 
        echo '         <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
 
1262
        echo '         <input type="submit" name ="draft" value="' . _("Save Draft") . "\" />\n";
1233
1263
    }
1234
1264
 
1235
 
    echo '         <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
 
1265
    echo '         <input type="submit" name="send" value="'. _("Send") . '" />' . "\n";
1236
1266
    do_hook('compose_button_row');
1237
1267
 
1238
 
    echo '      </TD>' . "\n" .
1239
 
         '   </TR>' . "\n\n";
 
1268
    echo '      </td>' . "\n" .
 
1269
        '   </tr>' . "\n\n";
1240
1270
}
1241
1271
 
1242
1272
function checkInput ($show) {
1261
1291
/* True if FAILURE */
1262
1292
function saveAttachedFiles($session) {
1263
1293
    global $_FILES, $attachment_dir, $attachments, $username,
1264
 
           $data_dir, $compose_messages;
 
1294
        $data_dir, $compose_messages;
1265
1295
 
1266
1296
    /* get out of here if no file was attached at all */
1267
1297
    if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1279
1309
    // FIXME: we SHOULD prefer move_uploaded_file over rename because
1280
1310
    // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1281
1311
    if (!@rename($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1282
 
            if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1283
 
                return true;
1284
 
                }
 
1312
        if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
 
1313
            return true;
 
1314
        }
1285
1315
    }
1286
1316
    $message = $compose_messages[$session];
1287
1317
    $type = strtolower($_FILES['attachfile']['type']);
1317
1347
 
1318
1348
        switch(strtoupper(substr($ini_size, -1))) {
1319
1349
            case 'G':
1320
 
               $bytesize = 1073741824;
1321
 
               break;
 
1350
                $bytesize = 1073741824;
 
1351
                break;
1322
1352
            case 'M':
1323
 
               $bytesize = 1048576;
1324
 
               break;
 
1353
                $bytesize = 1048576;
 
1354
                break;
1325
1355
            case 'K':
1326
 
               $bytesize = 1024;
1327
 
               break;
 
1356
                $bytesize = 1024;
 
1357
                break;
1328
1358
        }
1329
1359
 
1330
1360
        return ($bytesize * (int)substr($ini_size, 0, -1));
1338
1368
   In the future the responsable backend should be automaticly loaded
1339
1369
   and conf.pl should show a list of available backends.
1340
1370
   The message also should be constructed by the message class.
1341
 
*/
 
1371
 */
1342
1372
 
1343
1373
function deliverMessage($composeMessage, $draft=false) {
1344
1374
    global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1345
 
           $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
1346
 
           $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1347
 
           $domain, $action, $default_move_to_sent, $move_to_sent;
 
1375
        $username, $popuser, $usernamedata, $identity, $data_dir,
 
1376
        $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
 
1377
        $domain, $action, $default_move_to_sent, $move_to_sent;
1348
1378
    global $imapServerAddress, $imapPort, $sent_folder, $key;
1349
1379
 
1350
 
    /* some browsers replace <space> by nonbreaking spaces &nbsp;
1351
 
       by replacing them back to spaces addressparsing works */
1352
 
    /* FIXME: How to handle in case of other charsets where "\240"
1353
 
       is not a non breaking space ??? */
1354
 
    /* THEFIX: browsers don't replace space with nbsp. SM replaces
1355
 
       space with nbsp when decodes headers. If problem still happens,
1356
 
       use cleanup_nbsp() */
1357
 
 
1358
 
//    $send_to = str_replace("\240",' ',$send_to);
1359
 
//    $send_to_cc = str_replace("\240",' ',$send_to_cc);
1360
 
//    $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
1361
 
 
1362
1380
    $rfc822_header = $composeMessage->rfc822_header;
1363
1381
 
1364
1382
    $abook = addressbook_init(false, true);
1367
1385
    $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
1368
1386
    $rfc822_header->priority = $mailprio;
1369
1387
    $rfc822_header->subject = $subject;
 
1388
 
1370
1389
    $special_encoding='';
1371
1390
    if (strtolower($default_charset) == 'iso-2022-jp') {
1372
1391
        if (mb_detect_encoding($body) == 'ASCII') {
1379
1398
    $composeMessage->setBody($body);
1380
1399
 
1381
1400
    if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1382
 
       $popuser = $usernamedata[1];
1383
 
       $domain  = $usernamedata[2];
1384
 
       unset($usernamedata);
 
1401
        $popuser = $usernamedata[1];
 
1402
        $domain  = $usernamedata[2];
 
1403
        unset($usernamedata);
1385
1404
    } else {
1386
 
       $popuser = $username;
 
1405
        $popuser = $username;
1387
1406
    }
1388
1407
    $reply_to = '';
1389
 
    $from_mail = $idents[$identity]['email_address'];
1390
 
    $full_name = $idents[$identity]['full_name'];
1391
 
    $reply_to  = $idents[$identity]['reply_to'];
 
1408
    if (isset($identity) && $identity != 'default') {
 
1409
        $from_mail = getPref($data_dir, $username,'email_address' . $identity);
 
1410
        $full_name = getPref($data_dir, $username,'full_name' . $identity);
 
1411
        $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
 
1412
    } else {
 
1413
        $from_mail = getPref($data_dir, $username, 'email_address');
 
1414
        $full_name = getPref($data_dir, $username, 'full_name');
 
1415
        $reply_to = getPref($data_dir, $username,'reply_to');
 
1416
    }
1392
1417
    if (!$from_mail) {
1393
 
       $from_mail = "$popuser@$domain";
 
1418
        $from_mail = "$popuser@$domain";
1394
1419
    }
1395
1420
    $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true);
1396
1421
    if ($full_name) {
1405
1430
        $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
1406
1431
    }
1407
1432
    if ($reply_to) {
1408
 
       $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
 
1433
        $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
1409
1434
    }
1410
1435
    /* Receipt: On Read */
1411
1436
    if (isset($request_mdn) && $request_mdn) {
1412
 
       $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true);
 
1437
        $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true);
1413
1438
    }
1414
1439
    /* Receipt: On Delivery */
1415
1440
    if (isset($request_dr) && $request_dr) {
1416
 
       $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail;
 
1441
        $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail;
1417
1442
    }
1418
1443
    /* multipart messages */
1419
1444
    if (count($composeMessage->entities)) {
1443
1468
        }
1444
1469
        if ($default_charset) {
1445
1470
            $content_type->properties['charset']=$default_charset;
1446
 
    }
 
1471
        }
1447
1472
    }
1448
1473
 
1449
1474
    $rfc822_header->content_type = $content_type;
1463
1488
        global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1464
1489
 
1465
1490
        $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
1466
 
        get_smtp_user($user, $pass);
 
1491
 
 
1492
        if ($smtp_auth_mech == 'none' && !$authPop) {
 
1493
                $user = '';
 
1494
                $pass = '';
 
1495
        } else {
 
1496
                global $key, $onetimepad;
 
1497
                $user = $username;
 
1498
                $pass = OneTimePadDecrypt($key, $onetimepad);
 
1499
        }
 
1500
 
1467
1501
        $stream = $deliver->initStream($composeMessage,$domain,0,
1468
 
                          $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
 
1502
                $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
1469
1503
    } elseif (!$draft) {
1470
 
       require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
1471
 
       global $sendmail_path;
1472
 
       $deliver = new Deliver_SendMail();
1473
 
       $stream = $deliver->initStream($composeMessage,$sendmail_path);
 
1504
        require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
 
1505
        global $sendmail_path;
 
1506
        $deliver = new Deliver_SendMail();
 
1507
        $stream = $deliver->initStream($composeMessage,$sendmail_path);
1474
1508
    } elseif ($draft) {
1475
 
       global $draft_folder;
1476
 
       require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
1477
 
       $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1478
 
                      $imapPort, 0);
1479
 
       if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1480
 
           require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
1481
 
           $imap_deliver = new Deliver_IMAP();
1482
 
           $length = $imap_deliver->mail($composeMessage);
1483
 
           sqimap_append ($imap_stream, $draft_folder, $length);
1484
 
           $imap_deliver->mail($composeMessage, $imap_stream);
1485
 
               sqimap_append_done ($imap_stream, $draft_folder);
1486
 
           sqimap_logout($imap_stream);
1487
 
           unset ($imap_deliver);
1488
 
           return $length;
 
1509
        global $draft_folder;
 
1510
        require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
 
1511
        $imap_stream = sqimap_login($username, $key, $imapServerAddress,
 
1512
                $imapPort, 0);
 
1513
        if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
 
1514
            require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
 
1515
            $imap_deliver = new Deliver_IMAP();
 
1516
            $length = $imap_deliver->mail($composeMessage);
 
1517
            sqimap_append ($imap_stream, $draft_folder, $length);
 
1518
            $imap_deliver->mail($composeMessage, $imap_stream);
 
1519
            sqimap_append_done ($imap_stream, $draft_folder);
 
1520
            sqimap_logout($imap_stream);
 
1521
            unset ($imap_deliver);
 
1522
            return $length;
1489
1523
        } else {
1490
 
           $msg  = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1491
 
           plain_error_message($msg, $color);
1492
 
           return false;
 
1524
            $msg  = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), $draft_folder);
 
1525
            plain_error_message($msg, $color);
 
1526
            return false;
1493
1527
        }
1494
1528
    }
1495
1529
    $succes = false;
1498
1532
        $succes = $deliver->finalizeStream($stream);
1499
1533
    }
1500
1534
    if (!$succes) {
1501
 
        $msg  = $deliver->dlv_msg . '<br>' .
1502
 
                _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
1503
 
                $deliver->dlv_server_msg;
 
1535
        $msg  = $deliver->dlv_msg . '<br />' .
 
1536
            _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
 
1537
            $deliver->dlv_server_msg;
1504
1538
        plain_error_message($msg, $color);
1505
1539
    } else {
1506
1540
        unset ($deliver);
1515
1549
        }
1516
1550
 
1517
1551
        if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none'))
1518
 
           && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
 
1552
                && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1519
1553
            $fld_sent = true;
1520
1554
        } else {
1521
1555
            $fld_sent = false;
1528
1562
        }
1529
1563
 
1530
1564
        if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) {
1531
 
            global $passed_id, $mailbox, $action;
1532
 
            if ($action == 'reply' || $action == 'reply_all') {
1533
 
                $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig');
1534
 
                if ($save_reply_with_orig) {
1535
 
                    $sent_folder = $mailbox;
1536
 
                }
1537
 
            }
1538
1565
            sqimap_append ($imap_stream, $sent_folder, $length);
1539
1566
            require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
1540
1567
            $imap_deliver = new Deliver_IMAP();
1548
1575
            sqimap_mailbox_select ($imap_stream, $mailbox);
1549
1576
            sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
1550
1577
        }
1551
 
            sqimap_logout($imap_stream);
 
1578
        sqimap_logout($imap_stream);
1552
1579
    }
1553
1580
    return $succes;
1554
1581
}
1555
1582
 
 
1583
// vim: et ts=4
1556
1584
?>