Jul 23

Get moodle face-to-face iCal invites to work with MS Exchange / Outlook

Thu, 07/23/2009 - 15:22 — peter

The Problem

Moodle's Face-to-Face module sends you an iCal invite that is not properly interpreted by MS Outlook client. The iCal invite comes through as a blank attachment. Apparently the iCal worked just fine on OWA and on Evolution running on Linux.

Our Environment

  1. Moodle v.1.94+
  2. MS Exchange server 2003 (don't know which patch level).

Disclaimer

The changes below are what got my problem fixed at work. I don't guarantee that it will work for you. Use this information at your own risk. I also won't pretend this is the best solution out there. I am positive it can be improve in many ways. If you have problems with this solution and if I have the time to revisit this in the future I may look into it.

A Tentative Solution

Change the /moodle/moodlelib.php and the /moodle/mod/facetoface/lib.php files on the following fashion:

moodle/mod/facetoface/lib.php

Around line 1374, change this code:

if (!email_to_user($user, $fromaddress, $attachment['subject'], $attachment['body'],
$attachment['htmlbody'], $attachment['filename'], $attachmentfilename)) {
into this:
if (!email_to_user($user, $fromaddress, $attachment['subject'], file_get_contents($CFG->dataroot . '/' .
 $attachment['filename']),'ical')) {

The change above will use the file attachment as the body if the user opted to send out an iCal invite and add a special marker ("ical") as the parameter for the changes we will make on the moodlelib.php

moodle/moodlelib.php

Around line 4117, after the global and static declarations, add the following code:

if ($messagehtml == 'ical') {
  $messagehtml = '';
  $is_this_an_ical_request = TRUE;
}

This will set a control variable if the user chose to send an iCal. Then, around the new line 4283, right before the if ($mail->Send()) {, add the following code:

if ($is_this_an_ical_request) {
  $mail->ContentType = 'text/calendar; method=REQUEST; charset="UTF-8"';
  $mail->Encoding = 'quoted-printable';
}

Optional Item: setting a smart default

In the interest of completeness, another change we did at work is to set the default option for the user to send just an iCal invite. This is done in the moodle/mod/facetoface/signup.html file, around lines 124 and 126. On line 124, remove the selected="selected" statement and make line 126 look like this:

<option value="<?php echo MDL_F2F_ICAL ?>" selected="selected"><?php print_string('notificationical', 'facetoface') ?>
</option>

Easy Peasy!
-PCP

Update!

As pointed out by a colleague, this fix apparently will not work with gmail.com. If there is sufficient interest I can work out a solution that works for both.