source: subversion/branches/devel-vnext/program/steps/mail/compose.inc @ 631

Last change on this file since 631 was 631, checked in by till, 6 years ago

+ addressbook plugin

  • Property svn:executable set to *
File size: 6.7 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/steps/mail/compose.inc                                        |
6 |                                                                       |
7 | This file is part of the RoundCube Webmail client                     |
8 | Copyright (C) 2005, RoundCube Dev. - Switzerland                      |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Compose a new mail message with all headers and attachments         |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id: compose.inc 579 2007-05-18 13:11:22Z thomasb $
19
20*/
21
22require_once 'Mail/mimeDecode.php';
23require_once 'lib/html2text.inc';
24
25// define constants for message compose mode
26define('RCUBE_COMPOSE_REPLY',   0x0106);
27define('RCUBE_COMPOSE_FORWARD', 0x0107);
28define('RCUBE_COMPOSE_DRAFT',   0x0108);
29
30$registry = rc_registry::getInstance();
31$CONFIG   = $registry->get('CONFIG', 'core');
32
33// remove an attachment
34if ($_action == 'remove-attachment' && preg_match('/^rcmfile([0-9]+)$/', $_POST['_file'], $regs)) {
35    $id = $regs[1];
36    if (is_array($_SESSION['compose']['attachments'][$id]) !== false) {
37        $status = @unlink($_SESSION['compose']['attachments'][$id]['path']);
38        if ($status === false) {
39            rc_main::tfk_debug('Could not delete attachment.');
40        }
41        $_SESSION['compose']['attachments'][$id] = NULL;
42        $OUTPUT->command('remove_from_attachment_list', "rcmfile$id");
43        $OUTPUT->send();
44        exit;
45    }
46}
47
48// this version does not support HTML mails
49$CONFIG['htmleditor'] = false;
50$CONFIG = $registry->set('CONFIG', $CONFIG, 'core');
51
52
53$MESSAGE_FORM = $registry->set('MESSAGE_FORM', NULL, 'core');
54$MESSAGE      = $registry->set('MESSAGE', NULL, 'core');
55
56// Nothing below is called during message composition, only at "new/forward/reply/draft" initialization or
57// if a compose-ID is given (i.e. when the compose step is opened in a new window/tab).
58// Since there are many ways to leave the compose page improperly, it seems necessary to clean-up an old
59// compose when a "new/forward/reply/draft" is called - otherwise the old session attachments will appear
60
61if (
62    !is_array($_SESSION['compose'])
63    || $_SESSION['compose']['id'] != rc_main::get_input_value('_id', RCUBE_INPUT_GET)
64) {
65    rcmail_compose_cleanup();
66    $_SESSION['compose'] = array('id' => uniqid(rand()));
67}
68
69// add some labels to client
70rc_main::rcube_add_label(
71    'nosubject',
72    'norecipientwarning',
73    'nosubjectwarning',
74    'nobodywarning',
75    'notsentwarning',
76    'savingmessage',
77    'sendingmessage',
78    'messagesaved',
79    'converting'
80);
81
82// add config parameter to client script
83$OUTPUT->set_env(
84        'draft_autosave',
85        !empty($CONFIG['drafts_mbox']) ? $CONFIG['draft_autosave'] : 0
86);
87
88
89// get reference message and set compose mode
90if ($msg_uid = rc_main::get_input_value('_reply_uid', RCUBE_INPUT_GET)) {
91    $compose_mode = RCUBE_COMPOSE_REPLY;
92}
93elseif ($msg_uid = rc_main::get_input_value('_forward_uid', RCUBE_INPUT_GET)) {
94    $compose_mode = RCUBE_COMPOSE_FORWARD;
95}
96elseif ($msg_uid = rc_main::get_input_value('_draft_uid', RCUBE_INPUT_GET)) {
97    $compose_mode = RCUBE_COMPOSE_DRAFT;
98}
99$registry->set('compose_mode', $compose_mode, 'core');
100
101if (empty($msg_uid) === false) {
102
103    //rc_main::tfk_debug('We got uid: ' . $msg_uid);
104    //rc_main::tfk_debug('Compose mode: '  . $compose_mode);
105
106    // similar as in program/steps/mail/show.inc
107    $MESSAGE = array('UID' => $msg_uid);
108    $MESSAGE['structure'] = $IMAP->get_structure($msg_uid);
109    $MESSAGE['headers']   = $MESSAGE['structure']->headers; //$IMAP->get_headers($msg_uid);
110    $MESSAGE['subject']   = $IMAP->decode_header($MESSAGE['headers']->subject);
111    $MESSAGE['parts']     = $IMAP->get_mime_numbers($MESSAGE['structure']);
112
113
114    //rc_main::tfk_debug('Reference message: ' . var_export($MESSAGE, true));
115
116    if ($compose_mode == RCUBE_COMPOSE_REPLY) {
117        $_SESSION['compose']['reply_uid']   = $msg_uid;
118        $_SESSION['compose']['reply_msgid'] = $MESSAGE['headers']->messageID;
119        $_SESSION['compose']['references']  = $MESSAGE['headers']->reference;
120        $_SESSION['compose']['references'] .= !empty($MESSAGE['headers']->reference) ? ' ' : '';
121        $_SESSION['compose']['references'] .= $MESSAGE['headers']->messageID;
122
123        if (!empty($_GET['_all'])) {
124            $MESSAGE['reply_all'] = 1;
125        }
126    }
127    elseif ($compose_mode == RCUBE_COMPOSE_FORWARD) {
128        $_SESSION['compose']['forward_uid'] = $msg_uid;
129    }
130    elseif ($compose_mode == RCUBE_COMPOSE_DRAFT) {
131        $_SESSION['compose']['draft_uid'] = $msg_uid;
132    }
133}
134$registry->set('MESSAGE', $MESSAGE, 'core');
135
136/****** compose mode functions ********/
137require_once 'include/rcube/rcmail_compose.php';
138
139//rc_main::tfk_debug('Passed require for rcmail_compose functions.');
140
141// register UI objects
142$OUTPUT->add_handlers(
143            array(
144                'composeheaders'        => 'rcmail_compose_headers',
145                'composesubject'        => 'rcmail_compose_subject',
146                'composebody'           => 'rcmail_compose_body',
147                'composeattachmentlist' => 'rcmail_compose_attachment_list',
148                'composeattachmentform' => 'rcmail_compose_attachment_form',
149                'composeattachment'     => 'rcmail_compose_attachment_field',
150                'priorityselector'      => 'rcmail_priority_selector',
151                'receiptcheckbox'       => 'rcmail_receipt_checkbox',
152            )
153);
154
155
156/****** get contacts for this user and add them to client scripts ********/
157require_once 'include/rcube_contacts.inc';
158require_once 'include/rcube_contacts_macbay.inc';
159
160if (isset($CONFIG['addressbook_plugin'])) {
161    $CONTACTS = new rcube_contacts_macbay($_SESSION['username'], $_SESSION['password']);
162}
163else {
164    $DB = $registry->get('DB', 'core');
165
166    $CONTACTS = new rcube_contacts($DB, $_SESSION['user_id']);
167    $CONTACTS->set_pagesize(1000);
168}
169if ($result = $CONTACTS->list_records()) {
170    $a_contacts = array();
171    while ($sql_arr = $result->iterate()) {
172        if ($sql_arr['email']) {
173            $a_contacts[] = rc_main::format_email_recipient(
174                                $sql_arr['email'],
175                                rc_main::JQ($sql_arr['name'])
176            );
177        }
178    }
179    $OUTPUT->set_env('contacts', $a_contacts);
180}
181$OUTPUT->parse('compose', true);
182?>
Note: See TracBrowser for help on using the repository browser.