Results 1 to 5 of 5

Thread: Changing Calendar Organizer script

  1. #1
    snsparrish is offline Member
    Join Date
    Jun 2007
    Location
    Phoenix, AZ USA
    Posts
    13
    Rep Power
    8

    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.

  2. #2
    phoenix is offline Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,495
    Rep Power
    56

    Default

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


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

  3. #3
    Bevan Bennett is offline Active Member
    Join Date
    May 2007
    Location
    Los Angeles, CA
    Posts
    31
    Rep Power
    8

    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
    china is offline New Member
    Join Date
    Mar 2009
    Location
    Prague
    Posts
    3
    Rep Power
    6

    Default wrapped lines

    hi
    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
    msteamix is offline Junior Member
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    5
    Rep Power
    5

    Default

    Hello!

    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 .


LinkBacks (?)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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, 07:29 AM
  4. Replies: 2
    Last Post: 02-26-2007, 11: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
  •