From: Michael J. Rubinsky Date: Sat, 17 Jan 2009 23:14:51 +0000 (-0500) Subject: Refactor for new Horde_Mime library. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4fb51025432866561c0db8db86021be9bb1676ba;p=horde.git Refactor for new Horde_Mime library. This should be everything in kronolith except the ContactAutoCompleter.php file. --- diff --git a/kronolith/attendees.php b/kronolith/attendees.php index 233208d7f..c4341aede 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -48,8 +48,7 @@ case 'add': break; } - require_once 'Horde/MIME.php'; - foreach (MIME::rfc822Explode($newAttendees) as $newAttendee) { + foreach (Horde_Mime_Address::explode($newAttendees) as $newAttendee) { // Parse the address without validation to see what we can get out of // it. We allow email addresses (john@example.com), email address with // user information (John Doe ), and plain names @@ -85,8 +84,8 @@ case 'add': $name = empty($newAttendeeParsedPart->personal) ? '' : $newAttendeeParsedPart->personal; - $newAttendeeParsedPartNew = MIME::encodeAddress( - MIME::rfc822WriteAddress($newAttendeeParsedPart->mailbox, + $newAttendeeParsedPartNew = Horde_Mime::encodeAddress( + Horde_Mime_Address::writeAddress($newAttendeeParsedPart->mailbox, $newAttendeeParsedPart->host, $name)); $newAttendeeParsedPartValidated = $parser->parseAddressList( $newAttendeeParsedPartNew, '', null, true); @@ -122,8 +121,7 @@ case 'edit': if (empty($attendees[$actionValue]['name'])) { $editAttendee = $actionValue; } else { - require_once 'Horde/MIME.php'; - $editAttendee = MIME::trimEmailAddress( + $editAttendee = Horde_Mime_Address::trimAddress( $attendees[$actionValue]['name'] . (strpos($actionValue, '@') === false ? '' diff --git a/kronolith/lib/Driver.php b/kronolith/lib/Driver.php index 829bebf6a..03e7ff5ad 100644 --- a/kronolith/lib/Driver.php +++ b/kronolith/lib/Driver.php @@ -740,12 +740,11 @@ class Kronolith_Event { } if ($v1) { if (!empty($status['name'])) { - require_once 'Horde/MIME.php'; if (!empty($email)) { $email = ' <' . $email . '>'; } $email = $status['name'] . $email; - $email = MIME::trimEmailAddress($email); + $email = Horde_Mime_Address::trimAddress($email); } } else { if (!empty($status['name'])) { @@ -960,7 +959,6 @@ class Kronolith_Event { // ATTENDEE. $attendee = $vEvent->getAttribute('X-ATTENDEE'); if (!is_a($attendee, 'PEAR_Error')) { - require_once 'Horde/MIME.php'; if (!is_array($attendee)) { $attendee = array($attendee); @@ -972,7 +970,7 @@ class Kronolith_Event { for ($i = 0; $i < count($attendee); ++$i) { $attendee[$i] = str_replace(array('MAILTO:', 'mailto:'), '', $attendee[$i]); - $email = MIME::bareAddress($attendee[$i]); + $email = Horde_Mime_Address::bareAddress($attendee[$i]); // Default according to rfc2445: $attendance = KRONOLITH_PART_REQUIRED; // vCalendar 2.0 style: diff --git a/kronolith/lib/FreeBusy.php b/kronolith/lib/FreeBusy.php index 3073df601..03d79f84e 100644 --- a/kronolith/lib/FreeBusy.php +++ b/kronolith/lib/FreeBusy.php @@ -133,7 +133,6 @@ class Kronolith_FreeBusy { { require_once 'Horde/iCalendar.php'; require_once 'Mail/RFC822.php'; - require_once 'Horde/MIME.php'; /* Properly handle RFC822-compliant email addresses. */ static $rfc822; @@ -150,7 +149,7 @@ class Kronolith_FreeBusy { return PEAR::raiseError(_("No valid email address found")); } - $email = MIME::rfc822WriteAddress($res[0]->mailbox, $res[0]->host); + $email = Horde_Mime_Address::writeAddress($res[0]->mailbox, $res[0]->host); /* Check if we can retrieve a VFB from the Free/Busy URL, if one is * set. */ diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index aaa022a29..27917fdac 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -1792,10 +1792,9 @@ class Kronolith { return ''; } - require_once 'Horde/MIME.php'; $attendees = array(); foreach ($_SESSION['kronolith']['attendees'] as $email => $attendee) { - $attendees[] = empty($attendee['name']) ? $email : MIME::trimEmailAddress($attendee['name'] . (strpos($email, '@') === false ? '' : ' <' . $email . '>')); + $attendees[] = empty($attendee['name']) ? $email : Horde_Mime_Address::trimAddress($attendee['name'] . (strpos($email, '@') === false ? '' : ' <' . $email . '>')); } return implode(', ', $attendees); @@ -1834,12 +1833,8 @@ class Kronolith { return; } - require_once 'Horde/MIME.php'; - require_once 'Horde/MIME/Headers.php'; - require_once 'Horde/MIME/Message.php'; - $myemail = explode('@', $myemail); - $from = MIME::rfc822WriteAddress($myemail[0], isset($myemail[1]) ? $myemail[1] : '', $ident->getValue('fullname')); + $from = Horde_Mime_Address::writeAddress($myemail[0], isset($myemail[1]) ? $myemail[1] : '', $ident->getValue('fullname')); $mail_driver = $conf['mailer']['type']; $mail_params = $conf['mailer']['params']; @@ -1895,10 +1890,9 @@ class Kronolith { } if ($event->getAttendees()) { - require_once 'Horde/MIME.php'; $attendee_list = array(); foreach ($event->getAttendees() as $mail => $attendee) { - $attendee_list[] = empty($attendee['name']) ? $mail : MIME::trimEmailAddress($attendee['name'] . (strpos($mail, '@') === false ? '' : ' <' . $mail . '>')); + $attendee_list[] = empty($attendee['name']) ? $mail : Horde_Mime_Address::trimAddress($attendee['name'] . (strpos($mail, '@') === false ? '' : ' <' . $mail . '>')); } $message .= sprintf(_("Attendees: %s"), implode(', ', $attendee_list)) . "\n\n"; } @@ -1913,13 +1907,9 @@ class Kronolith { $message .= "\n\n" . sprintf(_("If your email client doesn't support iTip requests you can use one of the following links to accept or decline the event.\n\nTo accept the event:\n%s\n\nTo accept the event tentatively:\n%s\n\nTo decline the event:\n%s\n"), Util::addParameter($attend_link, 'a', 'accept', false), Util::addParameter($attend_link, 'a', 'tentative', false), Util::addParameter($attend_link, 'a', 'decline', false)); } - $mime = new MIME_Part('multipart/alternative'); - $body = new MIME_Part('text/plain', $message, NLS::getCharset()); - $body->setTransferEncoding('quoted-printable'); - + /* Build the iCalendar data */ require_once 'Horde/Data.php'; require_once 'Horde/iCalendar.php'; - $iCal = new Horde_iCalendar(); $iCal->setAttribute('METHOD', $method); $iCal->setAttribute('X-WR-CALNAME', String::convertCharset($share->get('name'), NLS::getCharset(), 'utf-8')); @@ -1928,30 +1918,21 @@ class Kronolith { $vevent->setAttribute('RECURRENCE-ID', $instance, array('VALUE' => 'DATE')); } $iCal->addComponent($vevent); - $ics = new MIME_Part('text/calendar', $iCal->exportvCalendar()); + + /* text/calendar part */ + $ics = new Horde_Mime_Part(); + $ics->setType('text/calendar'); + $ics->setContents($iCal->exportvCalendar()); $ics->setName($filename); $ics->setContentTypeParameter('METHOD', $method); $ics->setCharset(NLS::getCharset()); - $mime->addPart($body); - $mime->addPart($ics); - $mime = &MIME_Message::convertMimePart($mime); - - /* Build the notification headers. */ - $recipient = empty($status['name']) ? $email : MIME::trimEmailAddress($status['name'] . ' <' . $email . '>'); - - $msg_headers = new MIME_Headers(); - $msg_headers->addReceivedHeader(); - $msg_headers->addMessageIdHeader(); - $msg_headers->addHeader('Date', date('r')); - $msg_headers->addHeader('From', MIME::encodeAddress($from, NLS::getCharset())); - $msg_headers->addHeader('To', MIME::encodeAddress($recipient, NLS::getCharset())); - $msg_headers->addHeader('Subject', MIME::encode($subject, NLS::getCharset())); + $recipient = empty($status['name']) ? $email : Horde_Mime_Address::trimAddress($status['name'] . ' <' . $email . '>'); + $mail = new Horde_Mime_Mail($subject, $message, $recipient, $from, NLS::getCharset()); require_once KRONOLITH_BASE . '/lib/version.php'; - $msg_headers->addHeader('User-Agent', 'Kronolith ' . KRONOLITH_VERSION); - $msg_headers->addMIMEHeaders($mime); - - $status = $mime->send($email, $msg_headers, $mail_driver, $mail_params); + $mail->addHeader('User-Agent', 'Kronolith ' . KRONOLITH_VERSION); + $mail->addMimePart($ics); + $status = $mail->send($mail_driver, $mail_params); if (!is_a($status, 'PEAR_Error')) { $notification->push( sprintf(_("The event notification to %s was successfully sent."), $recipient), @@ -1984,9 +1965,6 @@ class Kronolith { require_once 'Horde/Group.php'; require_once 'Horde/Identity.php'; - require_once 'Horde/MIME.php'; - require_once 'Horde/MIME/Headers.php'; - require_once 'Horde/MIME/Message.php'; $groups = &Group::singleton(); $calendar = $event->getCalendar(); @@ -2007,6 +1985,7 @@ class Kronolith { $recipients[$user] = Kronolith::_notificationPref($user, 'read', $calendar); } } + foreach ($share->listGroups(PERMS_READ) as $group) { $group = $groups->getGroupById($group); if (is_a($group, 'PEAR_Error')) { @@ -2038,7 +2017,7 @@ class Kronolith { if (!isset($addresses[$vals['lang']][$vals['tf']][$vals['df']])) { $addresses[$vals['lang']][$vals['tf']][$vals['df']] = array(); } - $addresses[$vals['lang']][$vals['tf']][$vals['df']][] = MIME::rfc822WriteAddress($mailbox, $host, $identity->getValue('fullname')); + $addresses[$vals['lang']][$vals['tf']][$vals['df']][] = Horde_Mime_Address::writeAddress($mailbox, $host, $identity->getValue('fullname')); } if (!$addresses) { @@ -2053,12 +2032,6 @@ class Kronolith { $mail_params['password'] = Auth::getCredential('password'); } - $msg_headers = new MIME_Headers(); - $msg_headers->addMessageIdHeader(); - $msg_headers->addAgentHeader(); - $msg_headers->addHeader('Date', date('r')); - $msg_headers->addHeader('From', $from); - foreach ($addresses as $lang => $twentyFour) { NLS::setLang($lang); @@ -2079,9 +2052,6 @@ class Kronolith { break; } - $msg_headers->removeHeader('Subject'); - $msg_headers->addHeader('Subject', $subject . ' ' . $event->title); - foreach ($twentyFour as $tf => $dateFormat) { foreach ($dateFormat as $df => $df_recipients) { $message = "\n" @@ -2092,14 +2062,14 @@ class Kronolith { $event->start->strftime($tf ? '%R' : '%I:%M%p')) . "\n\n" . $event->getDescription(); - $mime = new MIME_Message(); - $body = new MIME_Part('text/plain', String::wrap($message, 76, "\n"), NLS::getCharset()); - - $mime->addPart($body); - $msg_headers->addMIMEHeaders($mime); - + $mime_mail = new Horde_Mime_Mail($subject . ' ' . $event->title, + null, + implode(',', $df_recipients), + $from, + NLS::getCharset()); + $mime_mail->setBody($message, NLS::getCharset(), true); Horde::logMessage(sprintf('Sending event notifications for %s to %s', $event->title, implode(', ', $df_recipients)), __FILE__, __LINE__, PEAR_LOG_DEBUG); - $sent = $mime->send(implode(', ', $df_recipients), $msg_headers, $mail_driver, $mail_params); + $sent = $mime_mail->send($mail_driver, $mail_params, false, false); if (is_a($sent, 'PEAR_Error')) { return $sent; } diff --git a/kronolith/lib/Views/Event.php b/kronolith/lib/Views/Event.php index 015b1dab7..af87dc184 100644 --- a/kronolith/lib/Views/Event.php +++ b/kronolith/lib/Views/Event.php @@ -42,7 +42,6 @@ class Kronolith_View_Event { return; } - require_once 'Horde/MIME.php'; require_once 'Horde/Text.php'; require_once 'Horde/Text/Filter.php'; diff --git a/kronolith/scripts/agenda.php b/kronolith/scripts/agenda.php index 90a23c899..f217ebf2c 100644 --- a/kronolith/scripts/agenda.php +++ b/kronolith/scripts/agenda.php @@ -12,8 +12,8 @@ */ // Find the base file path of Horde. -@define('HORDE_BASE', dirname(__FILE__) . '/../..'); - +//@define('HORDE_BASE', dirname(__FILE__) . '/../..'); +@define('HORDE_BASE', '/private/var/www/html/horde'); // Find the base file path of Kronolith. @define('KRONOLITH_BASE', dirname(__FILE__) . '/..'); diff --git a/kronolith/templates/attendees/attendees.inc b/kronolith/templates/attendees/attendees.inc index ea286a2b9..8d88be4bb 100644 --- a/kronolith/templates/attendees/attendees.inc +++ b/kronolith/templates/attendees/attendees.inc @@ -55,7 +55,7 @@ function switchDateView(view, date) $status): ?> getImageDir('horde')) . ' ' . Horde::link('#', sprintf(_("Edit %s"), $name), '', '', "performAction('edit', decodeURIComponent('" . rawurlencode($email) . "')); return false;") . Horde::img('edit.png', '', null, $registry->getImageDir('horde')) . '' ?> - '))) ?> + '))) ?>