Export ical/vcard

From Open-Xchange
Revision as of 08:16, 22 May 2013 by Tierlieb (talk | contribs) (+cat)

This is an example script that is able to get contacts,appointments,tasks as well as the global addressbook ical/vcard format.

NOTE:This example does the http request for the login as GET, so user name and password is logged in the apache log. The example only works for users that are created with the language en_US

~/bin> ./extract.sh --help
usage ./extract.sh serverurl user password
#!/bin/bash

SERVER=http://your.ox.server
USER=user@context
PASSWORD=userspw

test "$1" = "--help" && echo "usage $0 serverurl user password" && exit 1

test -z $1 || SERVER=$1
test -z $2 || USER=$2
test -z $3 || PASSWORD=$3

CURL='curl -b cookies -c cookies -H Expect: -s -L --location-trusted -k'

SESSION=`$CURL "$SERVER/ajax/login?action=login&name=$USER&password=$PASSWORD" \
        |sed 's/^.*session\":\"\([0-9A-Fa-f]*\)\".*$/\1/'`

echo $SESSION | grep "error" && echo "got no session, login failed" && exit 1

P_FOLDERS=`$CURL -X GET "$SERVER/ajax/folders?action=list&columns=1%2C301%2C300%2C307%2C304%2C306%2C302%2C305%2C308%2C311%2C2%2C314%2C313%2C315&session=$SESSION&parent=1"`

TASK="not found"
TASK=`echo $P_FOLDERS | sed 's/,\"tasks\".*$//' | sed 's/.*\[\([0-9]*\)$/\1/'`
CAL="not found"
CAL=`echo $P_FOLDERS | sed 's/,\"calendar\".*$//' | sed 's/.*\[\([0-9]*\)$/\1/'`
CON="not found"
CON=`echo $P_FOLDERS | sed 's/,\"contacts\".*$//' | sed 's/.*\[\([0-9]*\)$/\1/'`

echo ------------------------------------------------------
echo exporting private task folder $TASK:
echo ------------------------------------------------------
$CURL $URL -X GET "$SERVER/ajax/export?action=ICAL&session=$SESSION&folder=$TASK"
echo ------------------------------------------------------
echo exporting private calendar folder $CAL:
echo ------------------------------------------------------
$CURL $URL -X GET "$SERVER/ajax/export?action=ICAL&session=$SESSION&folder=$CAL"
echo ------------------------------------------------------
echo exporting private contacts folder $CON:
echo ------------------------------------------------------
$CURL $URL -X GET "$SERVER/ajax/export?action=VCARD&session=$SESSION&folder=$CON"
echo ------------------------------------------------------
echo "exporting global address book contacts folder 6:"
echo ------------------------------------------------------
$CURL $URL -X GET "$SERVER/ajax/export?action=VCARD&session=$SESSION&folder=6"
echo ------------------------------------------------------