comp.lang.ada
 help / color / mirror / Atom feed
From: "Thomas Løcke" <tl@ada-dk.org>
Subject: Patch suggestion for a bug in the GNATCOLL-Email-Utils package
Date: Thu, 03 Nov 2011 19:43:24 +0100
Date: 2011-11-03T19:43:24+01:00	[thread overview]
Message-ID: <4eb2e0cc$0$290$14726298@news.sunsite.dk> (raw)

Hey all,

I'm posting this here because I don't know how else to get in touch with
the GNATColl developers. May I suggest a maillist like the one the AWS
developers have? :o)

When using the GNATCOLL-Email-Utils package, you run into an annoying
problem when calling the Encode procedure on a non-header string.

What happens is that the subsequent call to the Quoted_Printable_Encode
procedure dumps its Block_Separator all over the string it is encoding,
which obviously is a bad thing. The Block_Separator is a constant:

     Block_Separator : constant String := " ";

So you end up with an encoded string full of more or less random spaces.

I wrote this small patch to "fix" it:


--- ../../gnatlib/src/gnatcoll-email-utils.adb  2011-10-06 
12:57:50.351259291 +0100
+++ gnatcoll-email-utils.adb    2011-11-03 14:57:07.000904069 +0000
@@ -1163,14 +1163,22 @@
        for S in Str'Range loop
           if Needs_Quoting (Str (S)) then
              if Start /= -1 then
-               Append (Str (Start .. S - 1), Splittable => True);
+               if Header then
+                  Append (Str (Start .. S - 1), Splittable => True);
+               else
+                  Append (Result, Str (Start .. S - 1));
+               end if;
                 Start := -1;
              end if;

              declare
                 Q : constant String := Quote (Str (S));
              begin
-               Append (Q, Splittable => False);
+               if Header then
+                  Append (Q, Splittable => False);
+               else
+                  Append (Result, Q);
+               end if;
                 Start := S + 1;
              end;

@@ -1182,10 +1190,14 @@
        end loop;

        if Start /= -1 then
-         Append (Str (Start .. Str'Last), Splittable => True);
+         if Header then
+            Append (Str (Start .. Str'Last), Splittable => True);
+         else
+            Append (Result, Str (Start .. Str'Last));
+         end if;
        end if;

-      if Current_Len /= 0 then
+      if Current_Len /= 0 and then Header then
           Append (Result, Block_Suffix);
        end if;
     end Quoted_Printable_Encode;


I'm not certain that my solution to the problem is the right one, but it
solves the issue here and now for a working application. I did think
about patching the Append procedure instead, but it seemed mighty
complicated, so I chickened out on that one.

Note that this bug does not show up when encoding very short strings. I
haven't tested how long the string needs to be before it shows up, but I
know for a fact that it happens consistenly with strings that are longer
than 2000 characters, and that I've personally never experienced it with
strings that are shorter than 22 characters.

Please let me know if there's anything else I can do to help solve the
issue.

:o)

-- 
Thomas L�cke

Email: tl at ada-dk.org
Web: http//:ada-dk.org
http://identi.ca/thomaslocke



             reply	other threads:[~2011-11-03 18:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-03 18:43 Thomas Løcke [this message]
2011-11-03 19:52 ` Patch suggestion for a bug in the GNATCOLL-Email-Utils package Jeffrey Carter
2011-11-04 13:50   ` Thomas Løcke
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox