Results 1 to 5 of 5

Thread: Changing Calendar Organizer script

  1. #1
    Join Date
    Jun 2007
    Phoenix, AZ USA
    Rep Power

    Default Changing Calendar Organizer script

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

    The error when trying to change a calendar item is:

    msg - invalid request: Changing organizer of an appointment/task is not allowed:,
    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:

    $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>;
            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>;
                    # Search and replace
                    @newcal = ();
                    for (@mycal) { 
                    # Push newcal info into the new file newcalendar.ics
                    $newcalfile = "/home/zimbra/$newaccountname/newcalendar.ics";
                    open (NEWCAL, ">$newcalfile");
                    print NEWCAL (@newcal);
                    # Empty the old calendar - we don't delete it so any shares or settings should stay in place
                    # command is :zmmailbox -z-m 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 pru "Calendar Name" /home/zimbra/
                    $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.

  2. #2
    phoenix is offline Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Vannes, France
    Rep Power


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


    Acompli: A new adventure for Co-Founder KevinH.

  3. #3
    Join Date
    May 2007
    Los Angeles, CA
    Rep Power

    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...

  4. #4
    Join Date
    Mar 2009
    Rep Power

    Default wrapped lines

    be carefull for calendars imported from outlook with long ORAGANIZER lines what are wrapped to two lines in middle of email. in this case script fails.

  5. #5
    Join Date
    Feb 2010
    Rep Power



    We found one problem with this script: The status of whether I accepted an old appointment someone invited me to is lost.

    Edit: That is with ZCS 7.1.0. Need to update forum account info .

Similar Threads

  1. changing text in calendar sharing dialog
    By gking in forum Administrators
    Replies: 0
    Last Post: 10-31-2007, 02:27 AM
  2. calendar .ics file: changing default DESCRIPTION?
    By paulmr in forum Administrators
    Replies: 1
    Last Post: 03-21-2007, 10:28 AM
  3. Outlook/Zimbra Private Appointments Issue
    By Smurthey in forum Zimbra Connector for Outlook
    Replies: 0
    Last Post: 03-09-2007, 06:29 AM
  4. Replies: 2
    Last Post: 02-26-2007, 10:37 AM
  5. MTA is Dying after yum update
    By tonyawbrey in forum Administrators
    Replies: 27
    Last Post: 04-02-2006, 06:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts