nntp charset problems [message #158908] |
Tue, 14 April 2009 09:33 |
webmaster_at_naszojciec
Messages: 4 Registered: April 2009
Karma: 0
|
Junior Member |
|
|
Changed handle of multi-line headers,
Changed regexp for charset detect
Added check for header 'content-transfer-encoding' == 'base64'
Convert send subject with iconv_mime_encode() but PHP5 only
Added charset convert in decode_header_value()
scripts_common.inc.orig 1.36
nntp.inc.orig 1.77
<?php --- nntp.inc.orig 2009-04-14 10:46:11.000000000 +0200
+++ nntp.inc 2009-04-14 11:19:08.000000000 +0200
@@ -162,7 +162,8 @@
function format_headers()
{
/* convert to unix line endings and handle multi-line headers */
- $this->headers = str_replace(array("\r\n", "\n "), array("\n",""), $this->headers);
+ $this->headers = str_replace("\r\n","\n", $this->headers);
+ $this->headers = preg_replace("/\n(\t| )+/", ' ', $this->headers);
$hdr = explode("\n", trim($this->headers));
$this->headers = array();
@@ -402,12 +403,15 @@
}
}
- if (isset($this->headers['content-type']) && preg_match('!charset="([^"]+)"!', $this->headers['content-type'], $m)) {
+ if (isset($this->headers['content-type']) && preg_match('!charset="?([^"]+?)"?(;|\s|$)!', $this->headers['content-type'], $m)) {
$charset = $m[1];
} else {
$charset = $GLOBALS['CHARSET'];
}
- if (isset($this->headers['content-transfer-encoding']) && $this->headers['content-transfer-encoding'] == 'quoted-printable') {
+ if (isset($this->headers['content-transfer-encoding']) &&
+ ($this->headers['content-transfer-encoding'] == 'quoted-printable'
+ || $this->headers['content-transfer-encoding'] == 'base64')
+ ) {
$enc = $this->headers['content-transfer-encoding'];
} else {
$enc = '';
@@ -420,6 +424,9 @@
}
$msg_post->subject = apply_custom_replace($this->subject);
+ if ( !preg_match('!(.*?)(=\?([^?]+)\?(Q|B)\?([^?]*)\?=)[[:space:]]*([^=]*)!i', $msg_post->subject)) {
+ $msg_post->subject = decode_string($msg_post->subject,"",$charset);
+ }
$msg_post->body = decode_string($this->body, $enc, $charset);
if ( !strlen($msg_post->subject) ) {
$msg_post->subject = "(no subject)";
@@ -546,7 +553,9 @@
fputs($this->fs, "From: $from\r\n");
fputs($this->fs, "Newsgroups: $this->newsgroup\r\n");
- fputs($this->fs, "Subject: $subject\r\n");
+ fputs($this->fs, iconv_mime_encode("Subject:", $subject,
+ array('scheme'=>'Q', "input-charset"=>$GLOBALS['CHARSET'],"output-charset"=>$GLOBALS['CHARSET']))
+ ."\r\n");
if ($GLOBALS['FORUM_TITLE']) {
fputs($this->fs, "Organization: ".$GLOBALS['FORUM_TITLE']."\r\n"); ?>
<?php --- scripts_common.inc.orig 2009-04-14 11:24:09.000000000 +0200
+++ scripts_common.inc 2009-04-14 11:27:26.000000000 +0200
@@ -147,9 +147,9 @@
$ec_type = strtolower($m[4][$i]);
if ($ec_type == 'q') {
- $newval .= decode_string(str_replace('_', ' ', $m[5][$i]), 'quoted-printable');
+ $newval .= decode_string(str_replace('_', ' ', $m[5][$i]), 'quoted-printable',$m[3][$i]);
} else if ($ec_type == 'b') {
- $newval .= decode_string($m[5][$i], 'base64');
+ $newval .= decode_string($m[5][$i], 'base64',$m[3][$i]);
}
if (!empty($m[5][$i])) { ?>
|
|
|
|
|
|
Re: nntp charset problems [message #158969 is a reply to message #158929] |
Mon, 20 April 2009 08:59 |
webmaster_at_naszojciec
Messages: 4 Registered: April 2009
Karma: 0
|
Junior Member |
|
|
Here it is, nntp.inc only:
<?php --- nntp.inc.1.79 2009-04-20 10:49:14.000000000 +0200
+++ nntp.inc 2009-04-20 10:56:27.000000000 +0200
@@ -162,7 +162,8 @@
function format_headers()
{
/* convert to unix line endings and handle multi-line headers */
- $this->headers = str_replace(array("\r\n", "\n "), array("\n",""), $this->headers);
+ $this->headers = str_replace("\r\n","\n", $this->headers);
+ $this->headers = preg_replace("/\n(\t| )+/", ' ', $this->headers);
$hdr = explode("\n", trim($this->headers));
$this->headers = array();
@@ -402,12 +403,15 @@
}
}
- if (isset($this->headers['content-type']) && preg_match('!charset="([^"]+)"!', $this->headers['content-type'], $m)) {
+ if (isset($this->headers['content-type']) && preg_match('!charset="?([^"]+?)"?(;|\s|$)!', $this->headers['content-type'], $m)) {
$charset = $m[1];
} else {
$charset = $GLOBALS['CHARSET'];
}
- if (isset($this->headers['content-transfer-encoding']) && $this->headers['content-transfer-encoding'] == 'quoted-printable') {
+ if (isset($this->headers['content-transfer-encoding']) &&
+ ($this->headers['content-transfer-encoding'] == 'quoted-printable'
+ || $this->headers['content-transfer-encoding'] == 'base64')
+ ) {
$enc = $this->headers['content-transfer-encoding'];
} else {
$enc = '';
@@ -546,7 +550,9 @@
fputs($this->fs, "From: $from\r\n");
fputs($this->fs, "Newsgroups: $this->newsgroup\r\n");
- fputs($this->fs, "Subject: $subject\r\n");
+ fputs($this->fs, iconv_mime_encode("Subject", $subject,
+ array('scheme'=>'Q', "input-charset"=>$GLOBALS['CHARSET'],"output-charset"=>$GLOBALS['CHARSET']))
+ ."\r\n");
if ($GLOBALS['FORUM_TITLE']) {
fputs($this->fs, "Organization: ".$GLOBALS['FORUM_TITLE']."\r\n"); ?>
[Updated on: Mon, 20 April 2009 08:59] Report message to a moderator
|
|
|
|
Re: nntp charset problems [message #159095 is a reply to message #159087] |
Mon, 04 May 2009 08:42 |
webmaster_at_naszojciec
Messages: 4 Registered: April 2009
Karma: 0
|
Junior Member |
|
|
Unfortunetly, in commited version is my first diff which is buggy.
There is posbility of double decode for subject.
Subject is decoded by decode_header_value.
Here is small patch for version 1.80 of nntp.inc.
<?php --- nntp.inc.1.80 2009-05-04 10:36:19.000000000 +0200
+++ nntp.inc 2009-05-04 10:40:38.000000000 +0200
@@ -424,9 +424,6 @@
}
$msg_post->subject = apply_custom_replace($this->subject);
- if ( !preg_match('!(.*?)(=\?([^?]+)\?(Q|B)\?([^?]*)\?=)([^=]*)!i', $msg_post->subject)) {
- $msg_post->subject = decode_string($msg_post->subject, '', $charset);
- }
$msg_post->body = decode_string($this->body, $enc, $charset);
if ( !strlen($msg_post->subject) ) {
$msg_post->subject = "(no subject)"; ?>
[Updated on: Mon, 04 May 2009 08:42] Report message to a moderator
|
|
|
|
|
|
|