Dirk, I've left this so long because I've wanted someone who knows more
about encodings, etc to take a look at it. But no one has so I read up
on the RFC myself and took a look.
My first comment is that the RFC seems to indicate that no encoded token
can be longer than 75 characters including the charset name, the opening
and closing marks, etc.
Secondly, I don't understand why you're only returning the encoded
string if the string already contains '=?'. That seems like one case
where you might want to encode it, but even then, the =? is only a
problem if it is preceded by whitespace, and there's a ?= followed by
whitespace within the next 75 chars (plus two question marks between
those tokens).
Thirdly, I don't like that you encode the whole string and then decide
whether to use the encoded version or not. If you're not going to
encode it, return the original string right away so we don't waste our
time doing the encoding for no reason.
Fourthly, the function should have an email_ prefix now (maybe
email_encode_rfc_1522() or something?) and perhaps you could make sure
your patch applies against the CVS version of the code - I'm not really
able to take patches against 0.17.x anymore because the codebase is so
different.
Do you have time to work on a second iteration of this patch? I found
an implementation for PERL that might give some ideas and I'm attaching
it so I don't have to find it again. I think using a regular expression
- instead of looping over the string manually - should be faster. If
you don't have time to rework this, let me know and I'll put it in my
own queue to do.
Cheers,
Julian
Dirk Datzert wrote:
> Hi,
>
> I had in mantis 0.17.3 the problem that german umlauts not displayed
> correctly in ISO-8859-1 notation.
>
> I mad a patch from my changes. Probably you want to integrated it into
> the next release with:
>
> cd mantis-0.17.5
> patch -p1 -R < email_API.patch
>
> I mad a reverse patch, sorry my mistake.
> I took the functions out of squirrelmail and adapted them for mantis.
>
> Regards,
> Dirk
>
>
> ------------------------------------------------------------------------
>
> diff -uNr mantis-0.17.3/core_email_API.php mantis-0.17.5/core_email_API.php
> --- mantis-0.17.3/core_email_API.php Mon Aug 12 19:11:36 2002
> +++ mantis-0.17.5/core_email_API.php Mon May 20 03:34:20 2002
> @@ -621,50 +620,6 @@
> $result = db_query( $query );
> return db_result( $result, 0, 0 );
> }
> -
> -/*
> - * Encode a string according to RFC 1522 for use in headers if it
> - * contains 8-bit characters or anything that looks like it should
> - * be encoded.
> - */
> -function encodeHeader ($string) {
> - $default_charset = "iso-8859-1";
> -
> - // Encode only if the string contains 8-bit characters or =?
> - $j = strlen( $string );
> - $l = strstr($string, '=?'); // Must be encoded ?
> - $ret = '';
> - for( $i=0; $i < $j; ++$i) {
> - switch( $string{$i} ) {
> - case '=':
> - $ret .= '=3D';
> - break;
> - case '?':
> - $ret .= '=3F';
> - break;
> - case '_':
> - $ret .= '=5F';
> - break;
> - case ' ':
> - $ret .= '_';
> - break;
> - default:
> - $k = ord( $string{$i} );
> - if ( $k > 126 ) {
> - $ret .= sprintf("=%02X", $k);
> - $l = TRUE;
> - } else
> - $ret .= $string{$i};
> - }
> - }
> -
> - if ( $l ) {
> - $string = "=?$default_charset?Q?$ret?=";
> - }
> -
> - return( $string );
> -}
> -
> # --------------------
> # formats the subject correctly
> # we include the project name, bug id, and summary.
> @@ -675,7 +630,7 @@
> $p_project_name = get_project_field( $g_project_cookie_val, "name" );
>
> # grab the subject (summary)
> - $p_subject = encodeHeader(string_email( get_bug_summary( $p_bug_id ) ));
> + $p_subject = string_email( get_bug_summary( $p_bug_id ) );
>
> # padd the bug id with zeros
> $p_bug_id = str_pd( $p_bug_id, "0", 7, STR_PAD_LEFT );
--
julian@...
Beta4 Productions (http://www.beta4.com)
|