Online encoding incoming email in OTRS

Hello Developers! I've made some changes in Kernel/System/PostMaster.pm for online encoding of incoming email messages into default charset. I also added parameter $Self->{"EmailForceCharsetEncoding"} = 1; in Config.pm . If EmailForceCharsetEncoding=0 the online encoding switches off. Here is diff (with otrs-2.1.4) diff -Naur PostMaster.pm.orig PostMaster.pm --- PostMaster.pm.orig 2006-12-20 11:57:27.000000000 +0200 +++ PostMaster.pm 2006-12-22 15:57:06.000000000 +0200 @@ -98,7 +98,6 @@ my %Param = @_; # ConfigObject section / get params my $GetParam = $Self->GetEmailParams(); - # check if follow up my ($Tn, $TicketID) = $Self->CheckFollowUp(%{$GetParam}); @@ -140,6 +139,8 @@ ); return 1; } + + # ---------------------- # ticket section # ---------------------- @@ -442,9 +443,55 @@ } # get body $GetParam{'Body'} = $Self->{ParseObject}->GetMessageBody(); + +####################################################### +# WITHOUT EMAIL ENCODING + + # get content type + #$GetParam{'Content-Type'} = $Self->{ParseObject}->GetReturnContentType(); + #$GetParam{'Charset'} = $Self->{ParseObject}->GetReturnCharset(); + +####################################################### +# DO EMAIL ENCODING INTO DefaultCharset (in Config.pm) + # get content type - $GetParam{'Content-Type'} = $Self->{ParseObject}->GetReturnContentType(); - $GetParam{'Charset'} = $Self->{ParseObject}->GetReturnCharset(); + my $SrcContentType = $Self->{ParseObject}->GetReturnContentType(); + my $SrcCharSet = $Self->{ParseObject}->GetReturnCharset(); + + if ( $SrcCharSet =~ /.*/ && $Self->{ConfigObject}->Get('EmailForceCharsetEncoding') ) { + my $DstCharSet = $Self->{ConfigObject}->Get('DefaultCharset'); + + if ($Self->{Debug} > 0) { + print "Old CharSet: ".$SrcCharSet."\n"."New CharSet: ".$DstCharSet." \n"; + # get Content-Transfer-Encoding + my $CTEncoding = $Self->{ParseObject}->GetParam(WHAT => 'Content-Transfer-Encoding'); + print "Content-Transfer-Encoding: ".$CTEncoding." \n"; + } + + if ( $SrcCharSet ne /$DstCharSet/i ) { + # Encode Body, Subject, From, To + Encode::from_to( $GetParam{'Body'}, $SrcCharSet, $DstCharSet ); + Encode::from_to( $GetParam{'Subject'}, $SrcCharSet, $DstCharSet ); + Encode::from_to( $GetParam{'From'}, $SrcCharSet, $DstCharSet ); + Encode::from_to( $GetParam{'To'}, $SrcCharSet, $DstCharSet ); + + my $DstContentType = $SrcContentType; + $DstContentType =~ s/$SrcCharSet/$DstCharSet/ ; + + if ($Self->{Debug} > 0) { print "New ContentType: ".$DstContentType." \n"; } + + # change ContentType + $GetParam{'Content-Type'} = $DstContentType; + + } + } + else { + $GetParam{'Content-Type'} = $SrcContentType; + $GetParam{'Charset'} = $SrcCharSet; + } + +####################################################### + return \%GetParam; } I think this feature could be usefull for other OTRS users. Best Regards, Robert Oliynichenko OS Consulting tel.+38 (044) 426-10-20
participants (1)
-
Robert Oliynichenko