Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Developers

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-27-2007, 10:10 AM
Member
 
Posts: 13
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?
Reply With Quote
  #2 (permalink)  
Old 08-27-2007, 05:27 PM
Moderator
 
Posts: 6,237
Default

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:
Quote:
zmmailbox -z -m user@domain.com 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:
Quote:
zmprov sm user@domain.com syncFolder /Calendar
You can also do this from the zmmailbox command instead of zmprov-kinda like:
Quote:
zmmailbox -z -m user@domain.com syncFolder /Calendar
OR
Quote:
zmmailbox -a admin -p password -m user@domain.com syncFolder /Calendar
OR
Quote:
zmmailbox
mbox>adminAuthenticate -u https://server.domain.com:7071 admin@domain.com password
mbox>selectMailbox user@domain.com
mbox user@domain.com>syncFolder /Calendar
SOAP:
Quote:
<FolderActionRequest>
<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}"]
[excludeFreeBusy="{exclude-free-busy-boolean}">
[<grant perm="..." gt="..." d="..." [args="..."] [key="..."]/>]
</action>
</FolderActionRequest>
Quote:
action op="sync" id="{list}"/>
- synchronize the folder's contents to the remote feed specified by the folder's {url}
---

Example:
Code:
#!/usr/bin/perl
my @zimbraAccounts = `/opt/zimbra/bin/zmprov getAllAccounts`;
foreach my $account (@zimbraAccounts) {
         chomp $account;
         my @allFolders = `/opt/zimbra/bin/zmmailbox -z -m $account  
getAllFolders`;
         for (@allFolders) {
                 chomp;
                 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: [SOLVED] Automatic IMAP/POP retrieval
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 user@domain.com | grep zimbraDataSourcePollingInterval
Try setting the account level:
zmprov ma user@domain.com zimbraDataSourcePollingInterval 15m

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

You'll see a bunch of [ScheduledTask] [name=user@domain.com;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)

--Edit--
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):
Code:
$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
Reply With Quote
  #3 (permalink)  
Old 08-28-2007, 10:07 AM
Member
 
Posts: 13
Default looks good

Thanks, I'll give that a try.
Reply With Quote
  #4 (permalink)  
Old 08-27-2008, 01:08 PM
Loyal Member
 
Posts: 95
Default

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?
Reply With Quote
  #5 (permalink)  
Old 08-28-2008, 05:53 AM
Member
 
Posts: 13
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.


Code:
#!/usr/bin/php
<?

/*
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- espeakers.com

*/



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', 'www.espeakers.com'); //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
	exec($x,$lines);


	//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");
					shell_exec($x);
				}
			}
		}

	}
}


fwrite($logfile, "\n\nDONE at ".date('n-j-Y H:i')."\n\n");
fclose($logfile);

																																																													?>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.