At 4/22/04 3:00 AM, [EMAIL PROTECTED] wrote:

>I'm going to test your patch on our production system.

I've actually done some more refinements since, after looking at the 
behavior of a number of "real" mail programs.

For example, quoted lines beginning with ">" should not be rewrapped even 
if they exceed 80 characters. Rewrapping quoted lines almost always 
messes them up, and should be avoided.

Also, a minimum line length of 4 characters before a wrap occurs should 
be enforced to prevent the problem where a line beginning with several 
spaces (for indenting) followed by a URL that exceeds 80 characters leads 
to two wrapped lines, the first containing three spaces and the second 
containing the URL.


>Two questions anyway:
>
>1. Did you fix the issue with original messages being wrapped at more 
>   than $NewLine characters? If I'm not wrong, Outlook's default is 80 
>   characters.

I did some tests, and Outlook wraps at 76 characters or less, and no 
(non-broken) mail I could find exceeds 78. That leads to this regexp for 
quoting replies (the "78" should come from the config file, but you get 
the idea):

    $Data{Body} =~ s/(^>.+|.{4,78})(?:\s|\z)/$1\n/gm;

That is, if the line is already quoted, don't wrap it at all. Otherwise, 
allow 4-78 characters before a space or newline; replace the last space 
or newline before 78 characters with a newline. The end result is that 
messages with a newline before 79 characters don't appear to get 
rewrapped (so they aren't altered if the user sent from a mail program 
that [correctly] did hard wrapping), but if they exceed 78 characters, 
they're rewrapped.

(The above algorithm does not lead to perfect wrapping for some types of 
less common mail formatting that doesn't use hard returns, such as that 
described in RFC 2646, but it is better than what's there now.)

(The "\z" makes sure that the last line is not broken at the final space 
in the string if there is no trailing newline.)

The regexp for wrapping our own outgoing text (not quoting someone a 
user's message) is the same, but should use a different maximum length 
(again, the "72" should be adjustable from the config file):

    $Self->{Body} =~ s/(^>.+|.{4,72})(?:\s|\z)/$1\n/gm;

I prefer 72 characters max to 75, because it gives you more room to have 
several levels of quoted replies, which are common in support 
environments. You certainly don't want to use 78, because Outlook would 
then rewrap it at 76 when the user replied, leading to a mess.

So, in a nutshell:

1. Don't rewrap quoted text at all. It almost never makes it better.

2. When quoting and rewrapping text from someone else, don't wrap at
   less than 78 characters, because the user's mail program may have
   used lines that long, and rewrapping them at less than 78 characters
   leads to the problem where each line is converted to two lines, with
   the last word of each sentence on a line by itself.

3. When rewrapping text you created that isn't already hard-wrapped,
   make sure the lines don't exceed 76 characters. Otherwise, people
   replying to you will rewrap your message in the same way described
   above.


>2. How do your regexp'es handle long URLs? They shouldn't wrap lines 
>   containing a single word (actually, they shouldn't wrap words at 
>   all).

They never break words -- they only break on whitespace. If you have a 
long URL, it won't be broken at all.


>Anyway, I think that good message wrapping should be integrated in OTRS
>as soon as possible.

If Martin gives the go-ahead to indicate that a patch would be accepted, 
I'll work up a proper patch that removes all the hard-wrapping stuff and 
properly wraps all the OTRS textareas (I'm currently just doing 
AgentCompose).

-- 
Robert L Mathews, Tiger Technologies      http://www.tigertech.net/

 "Ignorance more frequently begets confidence than does knowledge."
                                                           -- Darwin

_______________________________________________
OTRS mailing list: dev - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/dev
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/dev

Reply via email to