Пример #1
0
/**
 * Send an iMIP message since they look like a non-local user.
 *  
 * @param string $method The METHOD parameter from the iTIP
 * @param string $to_email The e-mail address we're going to send to
 * @param vCalendar $vcal The iTIP part of the message.
 */
function doImipMessage($method, $to_email, vCalendar $itip)
{
    global $c, $request;
    header('Debug: Sending iMIP ' . $method . ' message to ' . $to_email);
    $mime = new MultiPart();
    $mime->addPart($itip->Render(), 'text/calendar; charset=UTF-8; method=' . $method);
    $friendly_part = isset($c->iMIP->template[$method]) ? $c->iMIP->template[$method] : <<<EOTEMPLATE
This is a meeting ##METHOD## which your e-mail program should be able to
import into your calendar.  Alternatively you could save the attachment
and load that into your calendar instead.
EOTEMPLATE;
    $components = $itip->GetComponents('VTIMEZONE', false);
    $replaceable = array('METHOD', 'DTSTART', 'DTEND', 'SUMMARY', 'DESCRIPTION', 'URL');
    foreach ($replaceable as $pname) {
        $search = '##' . $pname . '##';
        if (strstr($friendly_part, $search) !== false) {
            $property = $itip->GetProperty($pname);
            if (empty($property)) {
                $property = $components[0]->GetProperty($pname);
            }
            if (empty($property)) {
                $replace = '';
            } else {
                switch ($pname) {
                    case 'DTSTART':
                    case 'DTEND':
                        $when = new RepeatRuleDateTime($property);
                        $replace = $when->format('c');
                        break;
                    default:
                        $replace = $property->GetValue();
                }
            }
            $friendly_part = str_replace($search, $replace, $friendly_part);
        }
    }
    $mime->addPart($friendly_part, 'text/plain');
    $email = new EMail();
    $email->SetFrom($request->principal->email());
    $email->AddTo($to_email);
    $email->SetSubject($components[0]->GetPValue('SUMMARY'));
    $email->SetBody($mime->getMimeParts());
    if (isset($c->iMIP->pretend_email)) {
        $email->Pretend($mime->getMimeHeaders());
    } else {
        if (!isset($c->iMIP->send_email) || !$c->iMIP->send_email) {
            $email->PretendLog($mime->getMimeHeaders());
        } else {
            $email->Send($mime->getMimeHeaders());
        }
    }
}
Пример #2
0
/**
* Essentially what we are doing is:
*
DELETE FROM caldav_data JOIN calendar_item USING(dav_id)
      WHERE dav_name LIKE '/someprincipal/%'
        AND (
          (rrule IS NULL AND dtend < archive_before_date)
           OR (last_instance_end < archive_before_date)
        )
*/
$recent = new RepeatRuleDateTime(gmdate('Ymd\\THis\\Z'));
$recent->modify('P-6D');
$archive_before_date = new RepeatRuleDateTime(gmdate('Ymd\\THis\\Z'));
$archive_before_date->modify($args->older);
if ($archive_before_date > $recent) {
    echo "Cowardly refusing to archive events before " + $archive_before_date->format('Y-m-d H:i:s') + "\n";
}
if ($args->debug) {
    printf("Archiving event instances finished before '%s'\n", $archive_before_date->UTC());
}
// SQL to create an archive collection but only if it doesn't exist already.
$archive_collection_sql = <<<EOSQL
INSERT INTO collection (user_no, parent_container, dav_name, dav_etag, dav_displayname, is_calendar,
                        created, modified, public_events_only, publicly_readable, is_addressbook,
                        resourcetypes, schedule_transp, timezone, description)
     SELECT user_no, parent_container, :archive_dav_name, random(),
            'Archive of ' || dav_displayname, true, current_timestamp, current_timestamp, false, false, false,
            resourcetypes, schedule_transp, timezone, 
            'Archive of ' || CASE WHEN description IS NULL OR description = '' THEN dav_name ELSE description END
       FROM collection 
      WHERE dav_name = :collection_dav_name