Navigation

advert

Import addresses from .CSV in RoundCube

Introduction

This howto goes through a simple step by step process of adding a .CSV importer to RoundCube Web Mail client.

The .CSV file can be exported from Outlook and Thunderbird, amongst other mail clients, so the address book can be imported into RoundCube.

This is a step by step how to: following the instructions exactly will allow you to use the address book importer.

Skill level: Medium

Download

To begin with, download the patch file. If you cannot apply patches, you can download the .tar.gz instead. These are heavily commented and can easily be changed to suit your needs.

Download the patch at http://www.rmacd.com/howto/rc-csv/roundcube-csv.patch

Download .tar.gz http://www.rmacd.com/howto/rc-csv/roundcubemail-0.1-rc1-CSV.tar.gz

Extract and place the folder into the root directory of the RoundCube installation.

Apply the patch automatically (recommended)

Apply the patch manually

Applying the Patch Automatically

Not applied patches before? It’s easy. Simply move to the working directory

$ cd  /srv/www/testing/roundcube-0.1rc1/

download the patch

$ wget http://www.rmacd.com/howto/rc-csv/roundcube-csv.patch 

or move the patch into your working directory

$ mv  /path/to/patch.patch .

test the patch

$ patch --dry-run –p1  roundcube-csv.patch

and apply the patch

$ patch –p1  roundcube-csv.patch

Manual Patching

First download the files included in package csv_upload.tar.gz.

$ tar –zxvf to extract  the files.

Now move csv_upload to the root of your RC installation.

Two files must now be moved; uploadcsv.inc and uploadcsv.html.

mv uploadcsv.inc /path/to/rc/installation/program/steps/addressbook/
mv uploadcsv.html /path/to/rc/installation/skins/default/templates/

Now, open index.php in the root of your RC installation.

About line 48, where it says

// define global vars
$OUTPUT_TYPE = 'html';
$INSTALL_PATH =  dirname(__FILE__);

replace

$MAIN_TASKS =  array('mail','settings','addressbook','logout');

with

$MAIN_TASKS =  array('mail','settings','addressbook','logout','uploadcsv');

Further down, look for the lines which say

if ($_action=='mailto')
include('program/steps/addressbook/mailto.inc');

after these lines (but before the closing "]" bracket), add the lines:

if ($_action=='uploadcsv')
include('csv_upload/addr.php');

Then, just before the line

// parse main template
$OUTPUT->send($_task);

Add the following:

// include task specific files
if ($_task=='uploadcsv')
{
if ($_action=='uploadcsv')
include('csv_upload/addr.php');
}

Save and exit this file.

Now open the file program/steps/addressbook/func.inc. This file defines the main functions of the address book.

Before the line

// register UI objects
$OUTPUT->add_handlers(array(

Add the following:

function upload_csv()  {
$out = sprintf("<a  href=\"javascript:openpopup()\" onClick=\"popurl='$COMM_PATH?_task=uploadcsv&_action=uploadcsv';  dimensions='width=600,height=600'\">Import .CSV  File...</a>");
return $out;
}

At the bottom of this file, you will see a short list

'addresslist' =>  'rcmail_contacts_list',
'addressframe' =>  'rcmail_contact_frame',
'recordscountdisplay'  => 'rcmail_rowcount_display',
'searchform' =>  'rcmail_search_form'

Add a comma to the last line, and add another below it as follows:

'searchform' =>  'rcmail_search_form', //note the  comma!
'uploadcsv' =>  'upload_csv' // no comma here!

Now, save and exit that file.

Open the file skins/default/addresses.css. This file handles the display properties of the address book, and allows us to change where the text appears on the page. At the bottom of this file, add the following css code:

#uploadcsv
{
position:absolute;
top: 40px;
right:35px;
color:#0000FF;
z-index:3000;
}

Save and close this file.

Only another couple of files to go!

Now open the file skins/default/includes/links.html. This allows us to add a JavaScript function to handle creating a popup for users to upload their address book in. After the line

<link  rel="stylesheet" type="text/css"  href="/common.css" />

Add the following:

<script  type="text/javascript">
function openpopup(){
winpops=window.open(popurl,"",dimensions  + ",scrollbars=yes,resizable=yes")
}
</script>

Save and close this file as well.

Now, to make the link appear on the address book page, we add an element to the address book template. Open the file skins/default/templates/addressbook.html, and before the element

<div  id="quicksearchbar">
Add the following
<div id="uploadcsv">
<roundcube:object  name="uploadcsv" />
</div>

And you’re done!

Updated Sunday, 23 November, 2008