Changeset - r5:a570202d2793
[Not reviewed]
v0.2 default
0 3 0
Wolfgang Scherer (ws) - 13 years ago 2012-03-30 16:13:40
wolfgang.scherer@gmx.de
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.
3 files changed with 99 insertions and 20 deletions:
0 comments (0 inline, 0 general)
index.php
Show inline comments
 
@@ -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[] = '<span class="label"></span>';
 
$form[] = '<span style="display: inline-block;"><table border="0" cellspacing="0" cellpadding="2" style="width: 410px;">';
 
$form[] = '<span class="label">';
 
$form[] = sprintf('<input type="submit" name="holen" value="%s" />', get_text('refresh'));
 
$form[] = '</span>';
 
$form[] = '<span style="display: inline-block;"><table border="0" cellspacing="0" cellpadding="2" style="width: 410px; vertical-align: top;">';
 
$trow = Array();
 
$trow[] = get_text('user');
 
$trow[] = get_text('forward_to');
 
@@ -337,14 +349,14 @@ if ($forward_active) {
 
// subject
 
$form[] = sprintf('<span class="label">%s<sup>*</sup>:</span>', get_text('subject'));
 
$form[] = (
 
    '<input type="text" name="subject" value="' . $vacation_subject
 
    '<input type="text" name="subject" value="' . htmlspecialchars($vacation_subject, ENT_COMPAT, "UTF-8")
 
    .'" size="49" /><br />');
 

	
 
// message
 
$form[] = sprintf('<span class="label">%s<sup>*</sup>:</span>', get_text('message'));
 
$form[] = (
 
    '<textarea name="body" cols="56" rows="10"'
 
    .' style="vertical-align: top;">' . $vacation_body . '</textarea><br />');
 
    .' style="vertical-align: top;">' . htmlspecialchars($vacation_body, ENT_NOQUOTES, "UTF-8") . '</textarea><br />');
 

	
 
$form[] = '<span class="label">&nbsp;</span>';
 
$form[] = (
 
@@ -355,7 +367,6 @@ if ($forward_active) {
 
// actions
 
$form[] = '<hr class="sep"/>';
 
$form[] = '<span class="label">&nbsp;</span>';
 
$form[] = sprintf('<input type="submit" name="holen" value="%s" />', get_text('refresh'));
 
$form[] = sprintf('<input type="submit" name="setzen" value="%s" /><br />', get_text('save'));
 
$form[] = '<hr class="sep"/>';
 

	
 
@@ -374,7 +385,7 @@ pclose($vacation_ausgabe);
 

	
 
if (!empty ($vacation_list)) {
 
    $form[] = shl(get_text('reply_history'));
 
    $form[] = '<hr class="sep"/>';
 
    // $form[] = '<hr class="sep"/>';
 
    $form[] = '<pre>';
 
    $form[] = $vacation_list;
 
    $form[] = '</pre>';
 
@@ -382,7 +393,7 @@ if (!empty ($vacation_list)) {
 
    $form[] = '<span class="label">&nbsp;</span>';
 
    $form[] = sprintf('<input type="submit" name="loeschen" value="%s" /><br />', get_text('delete'));
 
    if ($is_admin) {
 
        echo ('<hr class="sep"/>');
 
        $form[] = ('<hr class="sep"/>');
 
    }
 
} 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('<a href="%s">%s</a><br />'."\n", get_text('manual_link'), get_text('manual')));
 
}
 

	
lib/language.php
Show inline comments
 
@@ -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:|
lib/util.php
Show inline comments
 
@@ -244,6 +244,71 @@ function error_msg($message)
 
    echo sprintf('<span class="error"><strong>%s</strong></span>'."\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")
0 comments (0 inline, 0 general)