You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2009-07-16 11:43:13

linvinus
Member
Registered: 2009-07-16
Posts: 29

mail charset incorrect in helpdesk tiket body

if body charset different from utf8 for example
Content-Type: text/plain; charset="koi8-r"
then charset in tiket body in helpdesk are broken

email example

Return-Path: Denis@domain.ru
Received: from dc1.domain2.ru (LHLO dc1.domain2.ru) (10.10.1.1) by dc1.domain2.ru
with LMTP; Wed, 15 Jul 2009 17:01:13 +0400 (MSD)
Received: from localhost (localhost [127.0.0.1])
    by dc1.domain2.ru (Postfix) with ESMTP id B911A76AD
    for <help@domain2.ru>; Wed, 15 Jul 2009 17:01:13 +0400 (MSD)
X-Virus-Scanned: amavisd-new at domain2.ru
X-Spam-Flag: NO
X-Spam-Score: -0.222
X-Spam-Level:
X-Spam-Status: No, score=-0.222 tagged_above=-10 required=6.6
    tests=[AWL=0.158, BAYES_00=-2.599, TVD_SPACE_RATIO=2.219]
Received: from dc1.domain2.ru ([127.0.0.1])
    by localhost (dc1.domain2.ru [127.0.0.1]) (amavisd-new, port 10024)
    with ESMTP id tNwL6G-2MaTQ for <help@domain2.ru>;
    Wed, 15 Jul 2009 17:01:09 +0400 (MSD)
Received: from gw.domain.ru (gw.domain.ru [195.28.52.95])
    by dc1.domain2.ru (Postfix) with ESMTP id F2DEA74E7
    for <help@domain2.ru>; Wed, 15 Jul 2009 17:01:08 +0400 (MSD)
X-Virus-Scanner: This message was checked by NOD32 Antivirus system
    NOD32 for Linux Mail Server.
    For more information on NOD32 Antivirus System,
    please, visit our website: http://www.nod32.com/.
Received: from exchub.domain.ru (exchub.domain.ru [192.168.1.25])
    by gw.domain.ru (Postfix) with ESMTP id 826261021E
    for <help@domain2.ru>; Wed, 15 Jul 2009 17:01:08 +0400 (MSD)
Received: from CLMAILBOX.domain.sw ([192.168.1.22]) by exchub.domain.ru
([192.168.1.25]) with mapi; Wed, 15 Jul 2009 17:01:07 +0400
From: =?koi8-r?B?68/O09TBztTJzs/XIOTFzsnT?= <Denis@domain.ru>
To: "help@domain2.ru" <help@domain2.ru>
Date: Wed, 15 Jul 2009 17:01:06 +0400
Subject: =?koi8-r?Q?=D4=C5=D3=D4?=
Thread-Topic: =?koi8-r?Q?=D4=C5=D3=D4?=
Thread-Index: AQHKBUxQFHlJ6tpd5k6D+TBUFef5fQ==
Message-ID: <31620F7EC6955B4F86513B4C0682128BEAAAE5A9AC@CLMAILBOX.domain.ru>
Accept-Language: ru-RU
Content-Language: ru-RU
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
acceptlanguage: ru-RU
Content-Type: text/plain; charset="koi8-r"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
X-SpamTest-Version: SMTP-Filter Version 2.0.0 [0124], KAS/Release
X-Spamtest-Info: Pass through

=C6=D9=D7=C6=D9=D8=C2=CC=C4=D8=C4=CC=

following patch for glpi 0.72 resolve this problem
it also works for Content-Type: multipart/mixed;
(patch change function get_part )

--- ./inc.old/mailgate.class.php        2009-07-15 23:15:00.000000000 +0400
+++ ./inc/mailgate.class.php    2009-07-16 13:05:07.000000000 +0400
@@ -571,13 +571,23 @@
                                        $part_number = "1";
                                }
                                $text = imap_fetchbody($stream, $msg_number, $part_number);
-                               if($structure->encoding == 3) {
-                                       return imap_base64($text);
-                               } else if($structure->encoding == 4) {
-                                       return imap_qprint($text);
-                               } else {
-                                       return $text;
-                               }
+                                if($structure->encoding == 3) {
+                                    $text = imap_base64($text);
+                                } else if($structure->encoding == 4) {
+                                    $text = imap_qprint($text);
+                                } /*else {
+                                return $text;
+                                   } */
+                                //$text .= " this->structure->parameters".$structure->parameters." count=".count($structure->parameters);
+                                if (count($structure->parameters)>0){
+                                foreach ($structure->parameters as $param){
+                                    if ((strtoupper($param->attribute)=='CHARSET')&&function_exists('mb_convert_encoding')){
+                                       $text = mb_convert_encoding($text, 'utf-8',$param->value);
+                                       }
+                                   }
+                                }
+
+                            return $text;
                        }
                        if($structure->type == 1){ /* multipart */
                                $prefix="";

P.S.
i didn't find how to register on https://dev.indepnet.net/glpi/report so i report bug here.
sorry for English

Last edited by linvinus (2009-07-16 11:49:39)


glpi 0.83.2, ocs 2.0.2-2, Ubuntu 8.04.4 LTS

Offline

#2 2009-07-26 14:28:04

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: mail charset incorrect in helpdesk tiket body

bug must be post here.
If you have no answer it is just because we lack of time.

You patch seems to be interesting but we need to do some tests


MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI :    Support     Contribute     References     Freshmeat

Offline

#3 2009-07-27 09:12:32

linvinus
Member
Registered: 2009-07-16
Posts: 29

Re: mail charset incorrect in helpdesk tiket body

ok,  i'm understand.
there is my last patch
+                               if( $structure->subtype && $structure->subtype=="HTML"){
+                                   $text = str_replace("\r","",$text); 
+                                   $text = str_replace("\n","",$text); 
+                               }

it resolve double line spaces in mail if content text/html
because in html end line it is tag <br>, so \n and \r we should ignore.
example:

line 1<br>\r\n
line 2<br>\r\n
result in glpi without patch
line1

line2

after patch
line1
line2

--- ./inc.old/mailgate.class.php        2009-07-15 23:15:00.000000000 +0400
+++ ./inc/mailgate.class.php    2009-07-16 13:05:07.000000000 +0400
                                        $part_number = "1"; 
                                } 
                                $text = imap_fetchbody($stream, $msg_number, $part_number);
-                               if($structure->encoding == 3) { 
-                                       return imap_base64($text); 
-                               } else if($structure->encoding == 4) { 
-                                       return imap_qprint($text); 
-                               } else { 
-                                       return $text; 
-                               } 
+                                if($structure->encoding == 3) {
+                                    $text = imap_base64($text);
+                                } else if($structure->encoding == 4) {
+                                    $text = imap_qprint($text);
+                                } /*else {   
+                                return $text;   
+                                   } */
+                                //$text .= " this->structure->parameters".$structure->parameters." count=".count($structure->parameters);
+                               
+                               if( $structure->subtype && $structure->subtype=="HTML"){
+                                   $text = str_replace("\r","",$text); 
+                                   $text = str_replace("\n","",$text); 
+                               }
+                               
+                                if (count($structure->parameters)>0){
+                                foreach ($structure->parameters as $param){
+                                    if ((strtoupper($param->attribute)=='CHARSET')&&function_exists('mb_convert_encoding')){
+                                       $text = mb_convert_encoding($text, 'utf-8',$param->value);
+                                       }
+                                   }
+                                }
+
+                            return $text;
                        } 
                        if($structure->type == 1){ /* multipart */ 
                                $prefix="";

Last edited by linvinus (2009-07-27 09:20:19)


glpi 0.83.2, ocs 2.0.2-2, Ubuntu 8.04.4 LTS

Offline

#4 2009-09-14 19:32:02

kpcomp
Member
Registered: 2008-07-12
Posts: 57

Re: mail charset incorrect in helpdesk tiket body

This patch work for Outlook 2003 emails in Czech encoding (probably ISO-8859-2), but the one included in 0.72.21 did not (https://forge.indepnet.net/issues/show/1635). It looks like "tisk&#258;&#260;rny" instead of "tiskárny". Looks like untranslated double-byte UTF-8

Difference is line 590:

linvinus original:
if ((strtoupper($param->attribute)=='CHARSET') && function_exists('mb_convert_encoding')){

0.72.21 modified:
if ((strtoupper($param->attribute)=='CHARSET') && function_exists('mb_convert_encoding') && strtoupper($param->value) != 'UTF-8'){

Best, Pavel

Offline

#5 2009-09-15 10:41:58

kpcomp
Member
Registered: 2008-07-12
Posts: 57

Re: mail charset incorrect in helpdesk tiket body

Sorry. Too soon... Still same error.
Started after upgrade 0.72 => 0.72.21.

Pavel

Offline

#6 2009-09-17 21:26:11

MoYo
GLPI - Lead
From: Poitiers
Registered: 2004-09-13
Posts: 14,513
Website

Re: mail charset incorrect in helpdesk tiket body

the patch applied on 0.72.21 is the last version of linvinus patch.
I do not understand what you want to say on your last post.


MoYo - Julien Dombre - Association INDEPNET
Contribute to GLPI :    Support     Contribute     References     Freshmeat

Offline

#7 2009-09-18 11:32:21

kpcomp
Member
Registered: 2008-07-12
Posts: 57

Re: mail charset incorrect in helpdesk tiket body

After upgrade from 0.72 to 0.72.21 it changed behavior and now
body is mess like "tisk&#258;&#260;rny" instead of "tiskárny" or "seps&#258;&#260;n&#258;­"
instead of "sepsání".

Same problem for ISO-8859-2 and for UTF-8. Examples below.

Before upgrade it was different mess with different encoding error
but was "readable".

Subject seems to be OK.

Examaple email ISO-8859-2 Quoted Printable:
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="----_=_NextPart_001_01CA3835.3CE11580"
X-MimeOLE: Produced By Microsoft Exchange V6.5
Subject: =?iso-8859-2?B?Y2h5Ym7pIOy5+L7o7Ln9+Ojsue396L744bn9+L7huej4uej4?=
Date: Fri, 18 Sep 2009 09:54:23 +0200
Message-ID: <7441A17B1572464590F3F529C3F1CE3702B25D@servername>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: =?iso-8859-2?B?Y2h5Ym7pIOy5+L7o7Ln9+Ojsue396L744bn9+L7huej4uej4?=
Thread-Index: Aco4NTzQieZOARfGRtSpG2aKiWOBrA==
From: "Administrator" <administrator@domain.tld>
To: <podpora@domain.tld>
X-Spam-Status: No, hits=1.90 required=3.00 tests=HTML_MESSAGE=0.00,BAYES_00=-0.11,NO_RDNS2=0.01,OTHER=2.0
    version=3.2.5
X-Spam-Level: *
X-Spam-Checker-Version: SpamAssassin 3.2.5 (1.1) on canopus.kpcomp.cz

This is a multi-part message in MIME format.

------_=_NextPart_001_01CA3835.3CE11580
Content-Type: text/plain;
    charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

N=ECjak=E9 divn=E9 kodov=E1n=ED v emailu

=A9=E8=F8=BE=FD=B9=E1=EC=F8=B9=FD=BE=E9=ED=B9=E8=FD=BE=E9=ED=E1=FD=BE

Adsfjaklfhf=F9ladsfj=F9fj=F9laadsf

=CC=B9=E8=F8=BE=FD=E1=ED

=20

K"LJsdf


------_=_NextPart_001_01CA3835.3CE11580
Content-Type: text/html;
    charset="iso-8859-2"
Content-Transfer-Encoding: quoted-printable

<html xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns=3D"http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-2">
<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered medium)">
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
    {margin:0cm;
    margin-bottom:.0001pt;
    font-size:12.0pt;
    font-family:"Times New Roman";}
a:link, span.MsoHyperlink
    {color:blue;
    text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
    {color:purple;
    text-decoration:underline;}
span.StylE-mailovZprvy17
    {mso-style-type:personal-compose;
    font-family:Arial;
    color:windowtext;}
@page Section1
    {size:595.3pt 841.9pt;
    margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.Section1
    {page:Section1;}
-->
</style>

</head>

<body lang=3DCS link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>N=ECjak=E9 divn=E9 kodov=E1n=ED =
v&nbsp;emailu<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>=A9=E8=F8=BE=FD=B9=E1=EC=F8=B9=FD=BE=E9=ED=B9=E8=FD=BE=
=E9=ED=E1=FD=BE<o:p></o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Adsfjaklfhf=F9ladsfj=F9fj=F9laadsf<o:p></o:p></span></=
font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>=CC=B9<b><span =
style=3D'font-weight:bold'>=E8=F8=BE=FD</span></b>=E1=ED<o:p></o:p></span=
></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'><o:p>&nbsp;</o:p></span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>K&#8220;LJsdf<o:p></o:p></span></font></p>

</div>

</body>

</html>

------_=_NextPart_001_01CA3835.3CE11580--





Example mail UTF-8 Base64 encoded:
Content-class: urn:content-classes:message
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="----_=_NextPart_001_01CA3838.7B8E52C8"
X-MimeOLE: Produced By Microsoft Exchange V6.5
Subject: =?utf-8?B?d2XEjcWZxaHEjcW+xZnEjcW+w73FmcW+w73FmcOhw73FvsO9w6FnxI1mxb50dXR6?=
    =?utf-8?B?dcO9?=
Date: Fri, 18 Sep 2009 10:17:37 +0200
Message-ID: <7441A17B1572464590F3F529C3F1CE3702B25F@pe2650.almika.local>
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
Thread-Topic: =?utf-8?B?d2XEjcWZxaHEjcW+xZnEjcW+w73FmcW+w73FmcOhw73FvsO9w6FnxI1mxb50dXR6?=
    =?utf-8?B?dcO9?=
Thread-Index: Aco4OHuJdzWIsCoaTSyZ86ASy55V/g==
From: "Administrator" <administrator@domain.tld>
To: <podpora@domain.tld>
X-Spam-Status: No, hits=1.90 required=3.00 tests=HTML_MESSAGE=0.00,BAYES_00=-0.11,NO_RDNS2=0.01,OTHER=2.0
    version=3.2.5
X-Spam-Level: *
X-Spam-Checker-Version: SpamAssassin 3.2.5 (1.1) on canopus.kpcomp.cz

This is a multi-part message in MIME format.

------_=_NextPart_001_01CA3838.7B8E52C8
Content-Type: text/plain;
    charset="utf-8"
Content-Transfer-Encoding: base64

xaDEm8SNxZnFvsO9w6HDrcOpPWVzw71vYnplw6FvxI3DvXhuemVzcHJnY2RmDQoNCiANCg0KR2Zo
DQoNCkhoZGhqZmhqZ2hqDQoNCkRlcMOtY8Ohxb7FocOpxZnDocW+w71kw6FtdWVpcm9lZ3QNCg0K
IA0KDQo=

------_=_NextPart_001_01CA3838.7B8E52C8
Content-Type: text/html;
    charset="utf-8"
Content-Transfer-Encoding: base64

PGh0bWwgeG1sbnM6bz0id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U9J2ZvbnQtc2l6ZToxMC4wcHQ7DQpmb250LWZh
bWlseTpBcmlhbCc+RGVwPGI+PHNwYW4gc3R5bGU9J2ZvbnQtd2VpZ2h0OmJvbGQnPsOtY8Ohxb7F
ocOpPC9zcGFuPjwvYj7FmcOhxb7DvWTDoW11ZWlyb2VndDxvOnA+PC9vOnA+PC9zcGFuPjwvZm9u
dD48L3A+DQoNCjxwIGNsYXNzPU1zb05vcm1hbD48Zm9udCBzaXplPTIgZmFjZT1BcmlhbD48c3Bh
biBzdHlsZT0nZm9udC1zaXplOjEwLjBwdDsNCmZvbnQtZmFtaWx5OkFyaWFsJz48bzpwPiZuYnNw
OzwvbzpwPjwvc3Bhbj48L2ZvbnQ+PC9wPg0KDQo8L2Rpdj4NCg0KPC9ib2R5Pg0KDQo8L2h0bWw+
DQo=

------_=_NextPart_001_01CA3838.7B8E52C8--

Offline

#8 2009-09-18 13:43:53

kpcomp
Member
Registered: 2008-07-12
Posts: 57

Re: mail charset incorrect in helpdesk tiket body

Those modifications of inc/mailgate.class.php solved some problems with encoding for me:

line 319
if (!empty($this->charset)&&function_exists('mb_convert_encoding'&&strtoupper($this->charset)!='HTML-ENTITIES')){

line 590
if ((strtoupper($param->attribute)=='CHARSET') && function_exists('mb_convert_encoding') && strtoupper($param->value) != 'UTF-8' && strtoupper($param->value) != 'HTML-ENTITIES'){

Still testing.

Best, Pavel

Offline

Board footer

Powered by FluxBB