Sending Kerio Calendar Event Reminders by Email


2012/09/14

One of the things I really wish Kerio would add to their Calendaring is the ability to send email reminders rather than just pop-ups. This has annoyed me for some time and while I hoped to see it in the upcoming Connect 8.0 release, it's not in there, so I wrote a server-side script to do the job.

The script is rough; I haven't expended a lot of effort on it. It does work, at least for the cases I tested. As usual, you need to be sure that it works for you before depending upon it.

Some notes:

This depends upon the "Reminder" box being checked. It only sends email when a reminder pop-up is scheduled.

Recurring events won't be seen after the first unless the pop-up is acknowledged. You could write more complicated code that didn't depend on that, but this isn't it. I think that eventually the pop-up might self-acknowledge, but I haven't tested that. It would make sense for it to do that, but I'm not sure about that.

As this will send email BEFORE the scheduled pop-up reminder, it makes sense to have it run frequently. On the other hand, if it has a lot to do, it could miss events if you run it too frequently. Again, more complicated code could deal with that but I didn't bother.


#!/usr/bin/perl
use Date::Manip;
# You could do this without Date::Manip, but it's more work.
#
$STORE="/opt/kerio/mailserver/store";
@DOMAINS=("aplawrence.com","foobar.com");
# Set these to match your system
#
$PERIOD=60 * 5; # 5 minute loop, change to whatever you like
# However, if it runs too often and there are many events to process,
# it can miss events.
$DEBUG=1; # set to 0 for normal operation
#
while (1) {
foreach(@DOMAINS) {
  $domain=$_;
  chdir("$STORE/mail/$domain");
  foreach(<*>) {
   # you could exclude users with 
   # next if /^sam$/;
   # next if /^bill/;
   # or just do a few selected:
   # next if (not /^tony$/ and not /^linda/);
   #
   $user=$_;
   chdir("$STORE/mail/$domain/$user/Calendar/#msgs") or next;   
   foreach(<*.eml>) {
     $message=$_;
     open(CAL,$message);
     @cal=<CAL>;close CAL;
     $alarm="";
     @attend="";$summary="";$organizer="";
     foreach(@cal) {
       $summary=$_ if /Summary:/i;
       $reminder=$_ if /TRIGGER.*PT/;
       $summary=~ s/.*://;
       push @attend,$_ if /ATTENDEE/;
       $organizer=$_ if /ORGANIZER/;
       $organizer=~ s/.*://;
       $alarm=$_ if /NEXT-ALARM/;
       }
       $reminder=~s/.*PT//;
     if ($alarm) {
       $alarm=~ s/.*://;
       $atime=UnixDate(ParseDate($alarm),"%s");
       $nowtime= $atime - time();
         # this next section might use some work - good enough for my use
         $reminder=~s/.*PT://;
         $multiplier=60 if $reminder=~ /M/;
         $multiplier=60 * 60  if $reminder=~ /H/;
         $multiplier=60 * 60 *24  if $reminder=~ /D/;
         $reminder=~ s/[D-M].*//;
         $reminder *= $multiplier;
         $starts_at=$atime + $reminder;
         #
       if ($DEBUG and ($nowtime > 0)) {
         print "\nChecking $user/Calendar/#msgs/$message\n";
         print "remaining $nowtime seconds for $summary" ;
         print "Starts at ", scalar localtime($starts_at),"\n";
       }
      if ($nowtime <= $PERIOD and $nowtime > 0) {
      # Note that the email is sent sometime BEFORE the reminder fires off
      # If you hate that, you'd need to spawn off another process
      # that would wait until the precise time.  It wasn't important
      # for me.
      #
       print "$summary $start $organizer ", scalar localtime($starts_at),"\n" if ($DEBUG);;
       open(SEND,"|/opt/kerio/mailserver/sendmail $organizer"); 
       print SEND "Mime-Version: 1.0\n";
       print SEND "Content-Type: text/html\n";
       print SEND "Content-Transfer-Encoding: 8BIT\n";
       print SEND "Subject: Reminder $summary\n";
       print SEND "\n$summary starts at ",scalar localtime($starts_at),"\n";
      # I'm just listing attendees here, but it wouldn't be hard 
      # to send each of them a reminder also.  
      #
       foreach(@attend) {
         print if $DEBUG;
         print SEND;
       }
       close SEND;
       print "\n\n" if $DEBUG;
     }
      
     }
   }
   }

  }
print "sleeping  $PERIOD\n" if $DEBUG;;
sleep $PERIOD;
}
 

By the way, one use for this would be to get calendar reminders sent by SMS. To do that, you'd define a user rule that identified these types of messages (Subject contains Reminder, perhaps) and forwarded them to your SMS mail gateway number (see SMS through E-Mail).



Got something to add? Send me email.





(OLDER) <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> -> Sending Kerio Calendar Event Reminders by Email


4 comments



Increase ad revenue 50-250% with Ezoic


More Articles by

Find me on Google+

© Anthony Lawrence







Sat Sep 15 06:52:35 2012: 11315   anonymous

gravatar


Connect 8.0 ?! The "next major version" which wil drop BES support ?
For those of us that aren't part of the developer program, would you by any chance have an ETA for Connect 8.x ?



Sat Sep 15 11:39:46 2012: 11317   TonyLawrence

gravatar


I don't know, but as we're seeing Knowledge Base articles that reference it, it can't be too far away.



Sat Sep 15 12:01:02 2012: 11318   TonyLawrence

gravatar


Fixed a bug - $start_at was only set if $DEBUG was.. corrected above.

Probably more bugs to come..



Sun Sep 16 13:51:39 2012: 11323   TonyLawrence

gravatar


As written here, this won't send the email on recurring events if popups events are not acknowledged.

It CAN be rewritten to fix that - I'll get around to it eventually.

------------------------
Kerio Connect Mailserver

Kerio Samepage

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us





UNIX is simple. It just takes a genius to understand its simplicity. (Dennis Ritchie)

Better to fight for something than live for nothing. (George S. Patton)








This post tagged: