Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
  5 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 06-06-2007, 09:18 AM
snsparrish snsparrish is offline
Member
 
Join Date: Jun 2007
Location: Phoenix, AZ USA
ZCS Version: Release 4.5.6_GA_1044.RHEL4_64_20070706134444 RHEL4_64 NETWORK edition
Posts: 13
snsparrish is on a distinguished road
Default Changing Calendar Organizer script

When you move a user account from domain1.com to domain2.com, the users calendar items don't get updated so all appointments become read-only.

The error when trying to change a calendar item is:

Code:
msg - invalid request: Changing organizer of an appointment/task is not allowed: old=user@domain1.com, new=user@domain2.com
code - service.INVALID_REQUEST
method - ZmCsfeCommand.prototype.invoke
detail - soap:Sender
This happens when you change the user's name within the same domain as well.

I wrote a little perl script to "fix" the calendars of changed users.

This script was necessary for us after our 200-user Zimbra rollout and the senior leadership decided to change the domain and username format. I thought I'd share it with the community for those who have similar problems.

It exports the calendar, does a simple find/replace, emptys the old calendar, and imports the new hacked calendar.

You'll need to give create a home directory for the zimbra user at /home/zimbra and give ownership to that directory to the zimbra user. It creates a number of files for that user (old calendar, new calendar, logs) inside of that folder for each user you run the script for. This was necessary for me to keep track if something went wrong.

Run the script as the zimbra user and feed it two arguments: the new account name and the old account name.

Usage is as follows:
fixcal.pl newaccountname@newdomain.com oldaccountname@olddomain.com

Code:
#!/usr/bin/perl
$newaccountname = $ARGV[0];
$oldaccountname = $ARGV[1];
print "Working on $newaccountname\n";
print "Old Account name is $oldaccountname\n";
    # Create a dir for this user
        $argtext = "mkdir /home/zimbra/$newaccountname";
        @args = ($argtext);
        system(@args) == 0 or print "Unable to create folder $newaccountname: $?";
    # Now we get all the calendars associated with this account
        $argtext = "zmmailbox -z-m $newaccountname gaf | grep appo >> /home/zimbra/$newaccountname/cal_list";
        @args = ($argtext);
        system(@args) == 0 or print "Unable to get the list of calendars for $newaccountname: $?";
        $calfile = "/home/zimbra/$newaccountname/cal_list";
        open(CALS, $calfile);
        @lines = <CALS>;
        close(CALS);
        foreach $line(@lines){
            # Only shared calendars contain a colon.
            if ($line !~ m/:/i) {
                $pos = index($line, "\/") + 1;
                $calendar = substr($line, $pos);
                chomp $calendar;
                # URL encode the calendar string.
                use CGI;
                $calendarurlstyle = CGI::escape($calendar); 
                # Get the calendar and export it to a file
                $argtext = "zmmailbox -z-m $newaccountname gru $calendarurlstyle > /home/zimbra/$newaccountname/calendar";
                @args = ($argtext);
                system(@args) == 0 or print "Unable to get calendar $calendar for $newaccountname: $?";
                print "$newaccountname had $calendar exported\n";

                # Open the calendar and replace the old account name with the new one.
                $calfile = "/home/zimbra/$newaccountname/calendar";
                open(CAL, $calfile);
                @mycal = <CAL>;
                close(CALS);
                # Search and replace
                @newcal = ();
                for (@mycal) { 
                    s/$oldaccountname/$newaccountname/; 
                    push(@newcal,$_);
                }
                # Push newcal info into the new file newcalendar.ics
                $newcalfile = "/home/zimbra/$newaccountname/newcalendar.ics";
                open (NEWCAL, ">$newcalfile");
                seek(NEWCAL,0,0);
                print NEWCAL (@newcal);
                close(NEWCAL);
               
                # Empty the old calendar - we don't delete it so any shares or settings should stay in place
                # command is :zmmailbox -z-m useraccount@fh.org ef "Calendar Name"
                $argtext = "zmmailbox -z-m $newaccountname ef \"$calendar\"";
                @args = ($argtext);
                system(@args) == 0 or print "Unable to empty the $calendar folder for $newaccountname: $?";
                print "$newaccountname had $calendar emptied\n";

                # Import the new calendar
                # command is: zmmailbox -z-m useraccount@fh.org pru "Calendar Name" /home/zimbra/useraccount@fh.org/newcalendar.ics
                $argtext = "zmmailbox -z-m $newaccountname pru \"$calendarurlstyle\" $newcalfile";
                @args = ($argtext);
                system(@args) == 0 or print "Unable to import the new calendar $calendar for $newaccountname: $?";
                print "$newaccountname had $calendar imported\n";
            } 
        }
print "Finished $newaccountname\n";
Hope that helps others.
Reply With Quote
  #2 (permalink)  
Old 06-06-2007, 09:52 AM
phoenix phoenix is offline
Zimbra Employee
 
Join Date: Sep 2005
Location: Vannes, France
Posts: 7,479
phoenix is on a distinguished road
Default

Thanks for posting that. I'll make this thread a sticky.
__________________
Regards


Bill
Reply With Quote
  #3 (permalink)  
Old 10-04-2007, 02:43 PM
Bevan Bennett Bevan Bennett is offline
Senior Member
 
Join Date: May 2007
Location: Los Angeles, CA
Posts: 31
Bevan Bennett is on a distinguished road
Default One caveat

I tried this on one account and noticed one unintended side-effect of the process:

All meetings that were organized by someone other than the user become more "owned" by the user... the user still can't edit the content of the meetings, but they CAN now delete them and cause them to vanish forever from their calendar (usually you can only set your reply status for other people's meetings). The meeting does not get canceled or vanish from other attendee's calendars, and the person who deleted still appears on those calendars as an attendee.

The meetings don't get disassociated from their originals, fortunately, so a change made by the originator still gets propagated to the user (unless they deleted it).

Something to watch out for...
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.zimbra.com/forums/administrators/9328-changing-calendar-organizer-script.html
Posted By For Type Date
hlribeiro's bookmarks tagged with This thread Refback 09-14-2007 12:44 PM
calendar + Zimbra - SWiK This thread Refback 08-17-2007 11:42 PM
Administrators - Page 13 - Zimbra - Forums This thread Refback 07-03-2007 12:07 PM
calendar - SWiK This thread Refback 06-20-2007 04:16 PM
Changing Organizer script - Zimbra - Forums - SWiK This thread Refback 06-20-2007 02:51 PM

Similar Threads
Thread Thread Starter Forum Replies Last Post
changing text in calendar sharing dialog gking Administrators 0 10-31-2007 02:27 AM
calendar .ics file: changing default DESCRIPTION? paulmr Administrators 1 03-21-2007 10:28 AM
Outlook/Zimbra Private Appointments Issue Smurthey Zimbra Connector for Outlook 0 03-09-2007 06:29 AM
calendar migration to Zimbra 4.5 NE / SOAP / organizer urban@abak Migration 2 02-26-2007 10:37 AM
MTA is Dying after yum update tonyawbrey Administrators 27 04-02-2006 06:11 PM


freshmeat.net sourceforge.net The best Java IDE



 

Search Engine Optimization by vBSEO 3.0.0