commit 7eff576fd67d5c522cfa64afba2f9d7bdb5409fa
parent 0830c1baa479e3368fa37025da918a71d4d71cbf
Author: dankert <devnull@localhost>
Date: Wed, 11 Apr 2007 23:43:52 +0200
Vermeiden von Nicht-7-Bit-Zeichen in Header-Anweisungen.
Diffstat:
1 file changed, 69 insertions(+), 8 deletions(-)
diff --git a/serviceClasses/Mail.class.php b/serviceClasses/Mail.class.php
@@ -1,7 +1,9 @@
<?php
/**
- * Erzeugen einer E-Mail.
+ * Erzeugen und Versender einer E-Mail gemaess RFC 822.<br>
+ *
+ * @author Jan Dankert
*/
class Mail
{
@@ -12,7 +14,7 @@ class Mail
var $subject = '';
var $text = '';
var $header = array();
- var $nl = "\n";
+ var $nl = '';
@@ -22,17 +24,20 @@ class Mail
function Mail( $to='',$text='common',$xy='' )
{
global $conf;
+
+ $this->nl = chr(13).chr(10);
+
if ( !empty($conf['mail']['from']) )
- $this->from = $conf['mail']['from'];
+ $this->from = $this->header_encode($conf['mail']['from']);
// Priorität definieren (sofern konfiguriert)
if ( !empty($conf['mail']['priority']) )
$this->header[] = 'X-Priority: '.$conf['mail']['priority'];
- $this->header[] = 'X-Mailer: '.OR_TITLE.' '.OR_VERSION;
+ $this->header[] = 'X-Mailer: '.$this->header_encode(OR_TITLE.' '.OR_VERSION);
$this->header[] = 'Content-Type: text/plain; charset='.lang( 'CHARSET' );
- $this->subject = lang( 'mail_subject_'.$text );
- $this->to = $to;
+ $this->subject = $this->header_encode(lang( 'mail_subject_'.$text ));
+ $this->to = $this->header_encode($to);
$this->text = $this->nl.wordwrap(str_replace(';',$this->nl,lang('mail_text_'.$text)),70,$this->nl).$this->nl;
@@ -46,14 +51,33 @@ class Mail
// Kopie-Empfänger
if ( !empty($conf['mail']['cc']) )
- $this->cc = $conf['mail']['cc'];
+ $this->cc = $this->header_encode($conf['mail']['cc']);
// Blindkopie-Empfänger
if ( !empty($conf['mail']['bcc']) )
- $this->bcc = $conf['mail']['bcc'];
+ $this->bcc = $this->header_encode($conf['mail']['bcc']);
}
+
+ /**
+ * Kodiert einen Text in das Format "Quoted-printable".<br>
+ * See RFC 2045.
+ */
+ function quoted_printable_encode( $text )
+ {
+ $text = str_replace(' ','=20',$text);
+
+ for( $i=128; $i<=255; $i++ )
+ {
+ $text = str_replace( chr($i),'='.dechex($i),$text );
+ }
+
+ return $text;
+ }
+
+
+
/**
* Setzen einer Variablen in den Mail-Inhalt.
*/
@@ -84,6 +108,43 @@ class Mail
$this->text, // Inhalt
implode($this->nl,$this->header) );
}
+
+
+ /**
+ * Umwandlung von 8-bit-Zeichen in MIME-Header gemaess RFC 2047.<br>
+ * Header dürfen nur 7-bit-Zeichen enthalten. 8-bit-Zeichen müssen kodiert werden.
+ */
+ function header_encode( $text )
+ {
+ global $conf;
+
+ if ( empty($conf['mail']['header_encoding']) )
+ return $text;
+
+ $woerter = explode(' ',$text);
+ $neu = array();
+
+
+ foreach( $woerter as $wort )
+ {
+ $type = strtolower(substr($conf['mail']['header_encoding'],0,1));
+ $neu_wort = '';
+
+ if ( $type == 'b' )
+ $neu_wort = base64_encode($wort);
+ elseif ( $type == 'q' )
+ $neu_wort = $this->quoted_printable_encode($wort);
+ else
+ Logger::error( 'Mail-Configuratin broken: UNKNOWN Header-Encoding type: '.$type);
+
+ if ( strlen($wort)==strlen($neu_wort) )
+ $neu[] = $wort;
+ else
+ $neu[] = '=?'.lang('CHARSET').'?'.$type.'?'.$neu_wort.'?=';
+ }
+
+ return implode(' ',$neu);
+ }
}