summaryrefslogtreecommitdiff
path: root/program/steps/addressbook/export.inc
blob: 69f8e2e0b449bac27dade4e495d8e6d23bdcb871 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

/*
 +-----------------------------------------------------------------------+
 | program/steps/addressbook/export.inc                                  |
 |                                                                       |
 | This file is part of the Roundcube Webmail client                     |
 | Copyright (C) 2008-2009, The Roundcube Dev Team                       |
 | Licensed under the GNU GPL                                            |
 |                                                                       |
 | PURPOSE:                                                              |
 |   Export the selected address book as vCard file                      |
 |                                                                       |
 +-----------------------------------------------------------------------+
 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
 +-----------------------------------------------------------------------+

 $Id:  $

*/

// get contacts for this user
$CONTACTS->set_page(1);
$CONTACTS->set_pagesize(99999);
$result = $CONTACTS->list_records(null, 0, true);

// send downlaod headers
send_nocacheing_headers();
header('Content-Type: text/x-vcard; charset='.RCMAIL_CHARSET);
header('Content-Disposition: attachment; filename="rcube_contacts.vcf"');

while ($result && ($row = $result->next())) {
  // we already have a vcard record
  if ($row['vcard']) {
    echo rcube_vcard::rfc2425_fold($row['vcard']) . "\n";
  }
  // copy values into vcard object
  else {
    $vcard = new rcube_vcard($row['vcard']);
    $vcard->reset();
    foreach ($row as $key => $values) {
      list($field, $section) = explode(':', $key);
      foreach ((array)$values as $value) {
        if (is_array($value) || strlen($value))
          $vcard->set($field, $value, strtoupper($section));
      }
    }

    echo $vcard->export(true) . "\n";
  }
}

exit;