Hi,

I hacked this little script to import ics files into SOGo. It reuses the
URL that permits this import from the web interface.

Hope this helps.

-- 
Anthony Milan

Centre Hospitalier de Saint-Brieuc
Direction du système d'information
22027 Saint-Brieuc Cedex 1
Tél : 02 96 01 78 39 (67839)
Fax : 02 96 01 75 57

#!/usr/bin/perl -w
# Debian Packages: libwww-perl

use strict;
use Getopt::Long;
use LWP::UserAgent;
use HTML::Form;
use HTTP::Cookies;

use constant USAGEMSG =>  <<USAGE;
Usage: perl getics.pl --user <username> --pwd <password>  [--in <filename>]
        --user  <username>   Login name for calendar account (required)
        --pwd   <password>   Password for account (required)
        --in    <filename>   Name of calendar file - default "calendar.ics"
        --pre   <# of days>  Ignore calendar entries older than '# of days' - 
default 7
                             Set to '99' to include all events.
USAGE

my ($user,$pwd);
my $infile = "calendar.ics";

die USAGEMSG unless GetOptions('user=s' => \$user,
                               'pwd=s'  => \$pwd,
                               'in:s'  => \$infile );

# Check we have all the required values...
die USAGEMSG unless ($user && $pwd) ;

# Set our SOGo URL to use
my $base = 'https://webmail.ch-stbrieuc.fr/SOGo/so';

# Init
my $ua = LWP::UserAgent->new(
    agent =>
'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.2.8) 
Gecko/20100722 Firefox/3.6.8',
    cookie_jar => HTTP::Cookies->new(
        file     => 'cookies.txt',
        autosave => 1,
    )
);

my $req = HTTP::Request->new( GET => "${base}" );

my $res = $ua->request($req);
die $res->status_line if not $res->is_success;

# Login form
my $form = ( HTML::Form->parse( $res->content, $base ) )[0];

# Set values
$form->find_input('userName')->value($user);
$form->find_input('password')->value($pwd);

# Ok
$res = $ua->request( $form->click );

# Post calendar file
$res = $ua->post(
    "$base/$user/Calendar/personal/import",
    Content_Type => 'form-data',
    'Content'    => [
        fileinput    => $infile,
        calendarFile => [
            $infile => 'Calendar.ics' => 'text/calendar'
        ]
    ],

);
die $res->status_line if not $res->is_success;

-- 
[email protected]
https://inverse.ca/sogo/lists

Reply via email to