# HG changeset patch # User wolfgang.scherer@gmx.de # Date 2012-03-30 16:13:40 # Node ID a570202d27938592c8312040cdfef3d7c0ace2a1 # Parent 0eae87d3d1de50cd30559309d8e34d6aca8d9812 index.php: Umlaut and HTML-escaping fixed. Display enhancement. lib/util.php: vacation_split/vacation_join functions to centralize the gory details. Message `Content-Type: text/plain; charset="utf-8"' and `Content-Transfer-Encoding: quoted-printable' added. lib/language.php: Add administrator manual headline. diff --git a/index.php b/index.php --- a/index.php +++ b/index.php @@ -83,6 +83,7 @@ if (!$is_admin) { span.label { width: 100px; display: inline-block; + vertical-align: top; } hr.sep { width: 550px; @@ -155,20 +156,30 @@ if ($forward_active) if (!file_exists($vacation_msg_file)) { $vacation_msg = get_text('vacation'); + $decode = False; } else { $vacation_msg = file_get_contents($vacation_msg_file); + $decode = True; } -$lines = explode("\n", $vacation_msg); -$vacation_subject = array_shift($lines); -$vacation_subject = preg_replace('/^[Ss]ubject: */', '', $vacation_subject); -while (True) { - $line = array_shift($lines); - if (empty($line)) { - break; - } -} -$vacation_body = implode($lines, "\n"); +// $lines = explode("\n", $vacation_msg); +// $vacation_subject = array_shift($lines); +// $vacation_subject = preg_replace('/^[Ss]ubject: */', '', $vacation_subject); +// $vacation_headers = Array(); +// // remove additional headers +// while (True) { +// $line = array_shift($lines); +// if (empty($line)) { +// break; +// } +// $vacation_headers[] = $line; +// } +// $vacation_body = implode($lines, "\n"); + +$vacation_parts = vacation_split($vacation_msg, $decode); +$vacation_subject = $vacation_parts[0]; +$vacation_headers = $vacation_parts[1]; +$vacation_body = $vacation_parts[2]; // -------------------------------------------------- // |||:sec:||| Set vacation(1) parameters @@ -192,7 +203,7 @@ if ($vacation_setup || $vacation_clear) if ($vacation_clear) { system(sprintf( '%s -u %s %s %s -i', - $SUDO_CMD, $SUDO_OPT_H, $user, $VACATION_CMD)); + $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD)); break; } if (empty ($vacation_subject)) { @@ -210,8 +221,7 @@ if ($vacation_setup || $vacation_clear) sprintf($VACATION_FORWARD_ENTRY, $user)); // Prepare vacation(1) message - $vacation_msg = sprintf( - "Subject: %s\n\n%s\n", $vacation_subject, $vacation_body); + $vacation_msg = vacation_join($vacation_subject, $vacation_body); $vacation_msg_pipe = popen(sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $vacation_msg_file), @@ -269,8 +279,10 @@ if ($_debug) { } // column names -$form[] = ''; -$form[] = ''; +$form[] = ''; +$form[] = sprintf('', get_text('refresh')); +$form[] = ''; +$form[] = '
'; $trow = Array(); $trow[] = get_text('user'); $trow[] = get_text('forward_to'); @@ -337,14 +349,14 @@ if ($forward_active) { // subject $form[] = sprintf('%s*:', get_text('subject')); $form[] = ( - '
'); // message $form[] = sprintf('%s*:', get_text('message')); $form[] = ( '
'); + .' style="vertical-align: top;">' . htmlspecialchars($vacation_body, ENT_NOQUOTES, "UTF-8") . '
'); $form[] = ' '; $form[] = ( @@ -355,7 +367,6 @@ if ($forward_active) { // actions $form[] = '
'; $form[] = ' '; -$form[] = sprintf('', get_text('refresh')); $form[] = sprintf('
', get_text('save')); $form[] = '
'; @@ -374,7 +385,7 @@ pclose($vacation_ausgabe); if (!empty ($vacation_list)) { $form[] = shl(get_text('reply_history')); - $form[] = '
'; + // $form[] = '
'; $form[] = '
';
     $form[] = $vacation_list;
     $form[] = '
'; @@ -382,7 +393,7 @@ if (!empty ($vacation_list)) { $form[] = ' '; $form[] = sprintf('
', get_text('delete')); if ($is_admin) { - echo ('
'); + $form[] = ('
'); } } else { $form[] = shl(get_text('reply_history_empty')); @@ -396,6 +407,7 @@ echo implode($form, "\n"); // -------------------------------------------------- if ($is_admin) { + echo shl(get_text('manual_headline')); echo (sprintf('%s
'."\n", get_text('manual_link'), get_text('manual'))); } diff --git a/lib/language.php b/lib/language.php --- a/lib/language.php +++ b/lib/language.php @@ -49,6 +49,7 @@ Your message has been forwarded to a co- 'reply_history' => 'Autoreply History', 'delete' => 'Delete', + 'manual_headline' => 'Administrator Manual', 'manual' => 'Manual', 'manual_link' => 'doc/README.html', // |:here:| @@ -83,6 +84,7 @@ Ihre Mail wird zur Bearbeitung an meine 'reply_history' => 'Automatisch Beantwortete Emails', 'delete' => 'Löschen', + 'manual_headline' => 'Administratorhandbuch', 'manual' => 'Anleitung', 'manual_link' => 'doc/README-de.html', // |:here:| diff --git a/lib/util.php b/lib/util.php --- a/lib/util.php +++ b/lib/util.php @@ -244,6 +244,71 @@ function error_msg($message) echo sprintf('%s'."\n", $message); } +// -------------------------------------------------- +// |||:sec:||| vaccation(1) message +// -------------------------------------------------- + +function vacation_split($message, $decode) +{ + $lines = explode("\n", $message); + $subject = array_shift($lines); + $subject = preg_replace('/^[Ss]ubject: */', '', $subject); + $headers = Array(); + // remove additional headers + while (True) { + $line = array_shift($lines); + if (empty($line)) { + break; + } + $headers[] = $line; + } + $headers = implode($headers, "\n"); + $body = implode($lines, "\n"); + if ( $decode ) + { + if ( preg_match("/^=[?]/", $subject) ) + { + $subject = preg_replace('/^=[?]utf-8[?]Q[?]/', '', $subject); + $subject = preg_replace('/[?]=$/', '', $subject); + $subject = quoted_printable_decode($subject); + } + $body = quoted_printable_decode($body); + } + return Array($subject, $headers, $body); +} + +function vacation_join($subject, $body, $headers=Null) +{ + $subject = trim($subject); + $subjectq = quoted_printable_encode($subject); + if ( $subjectq != $subject ) + { + $subject = sprintf('=?utf-8?Q?%s?=', $subjectq); + } + $subject = 'Subject: ' . $subject; + $headera = Array( + $subject, + 'Content-Type: text/plain;'."\n" + .' charset="utf-8"'."\n" + .'Content-Transfer-Encoding: quoted-printable'); + if (!empty($headers)) + { + $headers = trim($headers); + if (!empty($headers)) + { + $headers = preg_replace("/\n\n+/", "\n", $headers); + $headera[] = $headers; + } + } + $headers = implode($headera, "\n"); + if (empty($body)) + { + $body = ''; + } + return sprintf("%s\n\n%s\n", + $headers, quoted_printable_encode($body)); +} + // // :ide-menu: Emacs IDE Menu - Buffer @BUFFER@ // . M-x `eIDE-menu' ()(eIDE-menu "z")