#!/usr/bin/perl # ############################################################################ # # Name: vcalxical.pl # Author: pete@rasterweb.net # # $Id: vcalxical.pl,v 1.9 2004/09/10 15:53:13 pete Exp pete $ # ############################################################################ # # There must be only ONE of each of these at the beginning and end of the file # otherwise you get just one event... # BEGIN:VCALENDAR # END:VCALENDAR ############################################################################ # use use Net::IMAP::Simple; ############################################################################ # set variables my $host = 'exchange.example.com'; # IMAP server my $username = 'pete'; my $password = '********'; my $mailbox = 'Calendar'; my $msg = ''; my $cap = 0; ############################################################################ # create object my $server = new Net::IMAP::Simple($host); $server->login($username, $password); my $number_of_messages = $server->select($mailbox); my $events = 0; ############################################################################ # loop thru msgs print "BEGIN:VCALENDAR\n"; print "VERSION:2.0\n"; foreach $msg (1..$number_of_messages) { my $lines = $server->get($msg); foreach $line (@$lines) { chomp($line); $line =~ s/BEGIN:VCALENDAR//; $line =~ s/END:VCALENDAR//; if ($line !~ /^\w.*\S:\S.*$/) { next; } if ($line =~ /BEGIN:VEVENT/) { $events = 1; } if ($events > 0) { push (@lines, $line); } } $msg = join ('', @lines); $msg =~ s/\r/\n/gs; print $msg; undef @lines; } print "END:VCALENDAR"; $server->quit(); __END__ =head1 NAME vcalxical.pl =head1 DESCRIPTION Reads an IMAP mailbox from an Exchange server that is *really* a calendar and pulls out the VCALENDAR parts which are then suitable for importing into something like Apple's iCal... Or at least that's the general idea. It works for me, YMMV... =head1 USAGE Run from the command line, it prints to STDOUT. To save to a file do something like this: perl vcalxical.pl >exchange.ics If running on Mac OS X the 'ics' extensions should set the file to be importable by iCal. =head1 AUTHOR pete Epete@rasterweb.netE =head1 LICENSE This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. =cut