]> git.donarmstrong.com Git - roundcube.git/blob - program/steps/addressbook/mailto.inc
Imported Upstream version 0.7
[roundcube.git] / program / steps / addressbook / mailto.inc
1 <?php
2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/steps/addressbook/mailto.inc                                  |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2007, The Roundcube Dev Team                            |
9  | Licensed under the GNU GPL                                            |
10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Compose a recipient list with all selected contacts                 |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
18  $Id: copy.inc 471 2007-02-09 21:25:50Z thomasb $
19
20 */
21
22 $cids   = rcmail_get_cids();
23 $mailto = array();
24 $recipients = null;
25
26 foreach ($cids as $source => $cid)
27 {
28     $CONTACTS = $RCMAIL->get_address_book($source);
29
30     if ($CONTACTS->ready)
31     {
32         $CONTACTS->set_page(1);
33         $CONTACTS->set_pagesize(count($cid) + 2); // +2 to skip counting query
34         $recipients = $CONTACTS->search($CONTACTS->primary_key, $cid, 0, true, true, 'email');
35     }
36 }
37
38 if (!empty($_REQUEST['_gid']) && isset($_REQUEST['_source']))
39 {
40     $source = get_input_value('_source', RCUBE_INPUT_GPC);
41     $CONTACTS = $RCMAIL->get_address_book($source);
42     
43     $group_id = get_input_value('_gid', RCUBE_INPUT_GPC);
44     $group_data = $CONTACTS->get_group($group_id);
45     
46     // group has an email address assigned: use that
47     if ($group_data['email']) {
48         $mailto[] = format_email_recipient($group_data['email'][0], $group_data['name']);
49     }
50     else if ($CONTACTS->ready) {
51         $CONTACTS->set_group($group_id);
52         $CONTACTS->set_page(1);
53         $CONTACTS->set_pagesize(200); // limit somehow
54         $recipients = $CONTACTS->list_records();
55     }
56 }
57
58 if ($recipients)
59 {
60     while (is_object($recipients) && ($rec = $recipients->iterate())) {
61         $emails = $CONTACTS->get_col_values('email', $rec, true);
62         $mailto[] = format_email_recipient($emails[0], $rec['name']);
63     }
64 }
65
66 if (!empty($mailto))
67 {
68     $mailto_str = join(', ', $mailto);
69     $mailto_id = substr(md5($mailto_str), 0, 16);
70     $_SESSION['mailto'][$mailto_id] = urlencode($mailto_str);
71     $OUTPUT->redirect(array('task' => 'mail', '_action' => 'compose', '_mailto' => $mailto_id));
72 }
73 else {
74     $OUTPUT->show_message('nocontactsfound', 'warning');
75 }
76
77 // send response
78 $OUTPUT->send();