Results 1 to 5 of 5

Thread: [SOLVED] reload calendar feeds with code

  1. #1
    Join Date
    Apr 2007
    Rep Power

    Default [SOLVED] reload calendar feeds with code

    I've got a scenario where some important calendar data is contained in an external iCalendar feed. My users subscribe to it, no problem, but external calendars don't refresh their data unless the user does a right-click on it and chooses 'reload'.

    I need to know a programmatic way to do this. Is there a REST URL or a SOAP service I can hit so that I can iterate through a list of users and force a particular iCalendar feed to reload?

    How about a zm* command on the server?

  2. #2
    Join Date
    May 2006
    Rep Power


    If you search bugzilla there are a few RFE's for automatic refresh:
    Bug 12390 - automatically reload remote calendars & Bug 6491 - Allow automatic / scheduled reloading of feeds

    In the meantime, as an .ics calendar is technically just a linked folder (similar for RSS):
    zmmailbox -z -m createFolder -c gray -F "#" --view appointment --url "http://somewhere/.ics" /CalendarName

    First you going to need to get the 'folder' name:
    zmmailbox -z -m gaf
    (of course script it so you can find the external .ics url easier than hunting through everyone's folders)

    Then once you know all those:
    zmprov sm syncFolder /Calendar
    You can also do this from the zmmailbox command instead of zmprov-kinda like:
    zmmailbox -z -m syncFolder /Calendar
    zmmailbox -a admin -p password -m syncFolder /Calendar
    mbox>adminAuthenticate -u password
    mbox>syncFolder /Calendar
    <action id="{list}" op="read|delete|rename|move|trash|empty|color|gran t|url|import|sync|fb|[!]check|update|[!]syncon" [l="{target-folder}"]
    [name="{new-name}"] [color="{new-color}"] [zid="{grantee-zimbra-id}"] [url="{target-url}"]
    [<grant perm="..." gt="..." d="..." [args="..."] [key="..."]/>]
    action op="sync" id="{list}"/>
    - synchronize the folder's contents to the remote feed specified by the folder's {url}

    my @zimbraAccounts = `/opt/zimbra/bin/zmprov getAllAccounts`;
    foreach my $account (@zimbraAccounts) {
             chomp $account;
             my @allFolders = `/opt/zimbra/bin/zmmailbox -z -m $account  
             for (@allFolders) {
                     next unless /appo/;
                     my $sync = `/opt/zimbra/bin/zmmailbox -z -m $account  
    syncFolder "$1"` if $_ =~ m/^.*(\/.*) .*$/;
                     print $sync;
    If you're curious, for external mail IMAP/POP accounts (data sources) see:
    Quote Originally Posted by mmorse View Post
    Keep in mind that zimbraDataSourcePollingInterval should inherited from the COS > to the account > to the data source. If a child object sets the value to '' null, it's supposed to inherit the parent value - if set to 0 or left unset via that chain, it's turned off. Edit: It does but provisioning isn't set properly: Bug 33151- data polling interval inheritance issue

    Let's check the account level:
    zmprov ga | grep zimbraDataSourcePollingInterval
    Try setting the account level:
    zmprov ma zimbraDataSourcePollingInterval 15m

    Check the individual datasource level:
    zmprov gds
    Set the individual datasource level:
    zmprov mds [external IMAP/POP account data source name] zimbraDataSourcePollingInterval 15m

    You'll see a bunch of [ScheduledTask] [;mid=x;ds=name;] datasource - Import completed. in /opt/zimbra/log/mailbox.log if it's working correctly.

    Bug 6491 - Allow automatic / scheduled reloading of feeds
    Bug 12390 - automatically reload remote calendars (separate control attribute)

    To increase performance:

    "Every time you run zmprov or zmmailbox, it has to crank up a new jvm. But you can run a batch of commands in a single zmprov or zmmailbox command. It would be better to aggregate the list of sync folder commands and then send all to one invocation of zmmailbox."

    Something like this (heh btw that's not true perl syntax):
    $cmds="select mailbox user1\n"
    $cmds += "syncFolder /world-cup-schedule\n"
    $cmds += "select mailbox user2\n"
    $cmds += "syncFolder /overpriced-concerts\n"
    open ZMMAILBOX "| zmmailbox"
    print ZMMAILBOX $cmds
    Last edited by mmorse; 03-18-2009 at 10:36 AM. Reason: performance

  3. #3
    Join Date
    Apr 2007
    Rep Power

    Default looks good

    Thanks, I'll give that a try.

  4. #4
    Join Date
    Jun 2008
    Minneapolis, MN
    Rep Power


    This seems to work, but how can I script this easily so I don't have to have a cron command run every 60 seconds?

  5. #5
    Join Date
    Apr 2007
    Rep Power

    Default PHP code to refresh iCalendar feeds

    I never came up with a way to do it without a cronjob, but I can save you a little time making one -- here's the PHP script to do it. I have this set in cron to run 4 times a day.

    this script is meant to be run periodically by cron.
    It needs to be run as user ZIMBRA.
    It needs to run on PHP 4, because that's what the Zimbra server has on it
    Dave Reed, eSpeakers
    dreed -at-
    define ('GET_USERLIST', 'nice zmprov gaa');
    define ('GET_CALENDARS', 'nice zmmailbox -z -m mbox gaf');
    define ('SYNC_CALENDAR', 'nice zmmailbox -z -m mbox syncFolder calname');
    define ('EVENT_CAL_IDENTIFIER', ''); //use this  to single out only certain calendars for update
    define('LOGFILE', '/opt/zimbra/contrib/logs/update_calendars_log.txt');
    $logfile = fopen(LOGFILE, 'w+');
    fwrite($logfile, 'STARTING AT '.date('n-j-Y H:i')."\n\n");
    //get a list of all the users on the system
    exec(GET_USERLIST, $mailboxes);
    fwrite($logfile, '(about to operate on '.count($mailboxes).' accounts)'."\n\n");
    //iterate over each user's mailbox and update any event calendar feeds
    foreach ($mailboxes as $mailbox) {
    	echo "looking through user $mailbox...\n";
    	fwrite($logfile, "looking through user $mailbox...\n");
    	$x = preg_replace('/mbox/', $mailbox, GET_CALENDARS);
    	$lines = array(); //the exec on the next line will append to lines, so we need to clear it out first
    	//go thru all the user's mailboxes, looking for an iCalendar feed
    	foreach ($lines as $line) {
    		//the calendar names always start with a 'slash' character
    		if (preg_match('/(\/.*)/i',  $line, $matches)) {
    			$s = $matches[0];
    			if (strpos($s, EVENT_CAL_IDENTIFIER)) {
    				//we've got a match that should get synched
    				if (preg_match('/(.*)\s\(/i', $s, $matches)) {
    					$calname = trim($matches[1]);
    					$x = preg_replace(array('/mbox/', '/calname/'), array(escapeshellarg($mailbox), escapeshellarg($calname)), SYNC_CALENDAR);
    					fwrite($logfile, "    reloading calendar: $calname\n");
    fwrite($logfile, "\n\nDONE at ".date('n-j-Y H:i')."\n\n");

Similar Threads

  1. Postfix problem
    By jimbo in forum Administrators
    Replies: 46
    Last Post: 07-23-2007, 05:24 AM
  2. 3.0 to 4.5.3 Upgrade failed (mysql error)
    By dealt in forum Installation
    Replies: 35
    Last Post: 03-19-2007, 10:30 PM
  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. Calendar Use Case
    By enthenergy in forum Administrators
    Replies: 2
    Last Post: 12-01-2006, 05:16 PM
  5. M2 Experiences?
    By jordandeamattson in forum Users
    Replies: 17
    Last Post: 11-22-2005, 02:32 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