[Bug 939] New: CreateMailMessage sometimes creates incorrect mime data - patch included

[email protected] Tue, 19 Oct 2010 06:55:34 -0400
Newsgroups gmane.comp.telephony.fax.hylafax.devel
Message-ID <[email protected]/>
http://bugs.hylafax.org/show_bug.cgi?id=939

           Summary: CreateMailMessage sometimes creates incorrect mime data
                    - patch included
           Product: HylaFAX
           Version: latest
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: faxrcvd
        AssignedTo: [email protected]
        ReportedBy: [email protected]


Hello,

the function CreateMailMessage in bin/common-functions creates an incorrect
mime structure under some circumstances when using base64 encoding.

When using base64 encoding and $BASE64ENCODE is used instead of the awk code,
it is not guaranteed that the output ends with a line break.
At least the encoder "base64-encode" on Debian 5 from the package "mime-codecs"
version 7.19-4 sometimes creates base64 encoded output without a trailing line
break.

Without that trailing line break the mime boundary (e.g. "--NextPart12348")
will be written to the end of the last base64 encoded line, e.g.:
"VGVzdApUZXN0ClRlc3QK--NextPart12348"
This violates RFC1341.

To reproduce the problem with  "base64-encode" from "mime-codecs" version
7.19-4 (Debian 5):
Create a file:
$ echo "Test" > test.txt
$ echo "Test" >> test.txt
$ echo "Test" >> test.txt

In hex the file content should be this:
"54 65 73 74 0A 54 65 73 74 0A 54 65 73 74 0A"

Now execute:
$ base64-encode < test.txt

The result is:
"VGVzdApUZXN0ClRlc3QK"
without a line break at the end.

If you create a file with only one "Test" line:
$ echo "Test" > test2.txt
And execute
$ base64-encode < test2.txt
the output is:
"VGVzdAo="
with a line break at the end.


A simple solution would be to always write a line break after executing
$BASE64ENCODE - an additional empty line after the Base64 encoded data does no
harm.

Here is a diff which solved the problem for me:

*** common-functions.sh.in      Tue Oct 19 11:20:06 2010
--- common-functions.sh.in.patched      Tue Oct 19 11:26:21 2010
***************
*** 189,194 ****
--- 189,196 ----
                cmd=`programOfCommand $BASE64ENCODE`
                if [ -x "$cmd" ]; then
                    (eval $BASE64ENCODE) < $1 2>$ERRORSTO
+                   # some encoders don't write a trailing line break, but we
need one
+                   echo ""
                else
                    c $AWK -f bin/b64-encode.awk < $1 2>$ERRORSTO
                fi



Kind regards
Andreas Taegener


-- 
Configure bugmail: http://bugs.hylafax.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


____________________ HylaFAX(tm) Developers Mailing List ____________________
  To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi
On UNIX: mail -s unsubscribe [email protected] < /dev/null