The 'rewrapMessage' method of the AnonymailerTool will rewrap an email
message body text at the number of characters specified by the
value of the tool's reflowWidth field.  The following tests
demonstrate how this works.

    >>> anontool = self.portal.portal_anonymailer
    >>> anontool.setReflowWidth('78')
    >>> rewrapMessage = anontool.rewrapMessage
    >>> str1 = 'A message that needs wrapping because it is over 80 chars wide, and it should have a line break somewhere.'
    >>> print rewrapMessage(str1)
    A message that needs wrapping because it is over 80 chars wide, and it should
    have a line break somewhere.

We need to preserve quotes as well:

    >>> str2 = '> > A message that needs wrapping because it is over 80 chars wide, and it should have a line break somewhere.'
    >>> print rewrapMessage(str2)
    > > A message that needs wrapping because it is over 80 chars wide, and it
    > > should have a line break somewhere.

If we have a single word longer than 80 char we leave it be:

    >>> str3 = 'https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query&string=even'
    >>> print rewrapMessage(str3)
    https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query&string=even

We don't break on the space in the quote chars even:

    >>> str4 = '> > > https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query&string=even'
    >>> print rewrapMessage(str4)
    > > > https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query&string=even

But we need to break a line that starts with a long string and has
whitespace separated strings after it:

    >>> str5 = '> > > https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query&string=even Wow, that was some url'
    >>> print rewrapMessage(str5)
    > > > https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query&string=even
    > > > Wow, that was some url

And we need to break a line that containd a long string and has
whitespace separated strings before and after:

    >>> str6 = '> > > Here it goes, https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query&string=even Wow, that was some url'
    >>> print rewrapMessage(str6)
    > > > Here it goes,
    > > > https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query&string=even
    > > > Wow, that was some url

We also optionally add quotes before reflowing:

    >>> str7 = '> > A quoted string that is a little bit too long when another quote is added'
    >>> rewrapMessage(str7)
    '> > A quoted string that is a little bit too long when another quote is added'
    >>> print rewrapMessage(str7, add_quote=True)
    > > > A quoted string that is a little bit too long when another quote is
    > > > added

And test it with a combination of the above:

    >>> msg = 'A long string that should get split into three lines because it is absurdly long, and has no breaks in it; really, it is far far longer than it should be and someone should consider stopping it as soon as possible.\n> > > A quoted line that needs a break because it is also a bit long, especially when the extra quote is added at the front.\n> > A really long url like: https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query which needs to be split twice.'
    >>> print rewrapMessage(msg, add_quote=True)
    > A long string that should get split into three lines because it is absurdly
    > long, and has no breaks in it; really, it is far far longer than it should
    > be and someone should consider stopping it as soon as possible.
    > > > > A quoted line that needs a break because it is also a bit long,
    > > > > especially when the extra quote is added at the front.
    > > > A really long url like:
    > > > https://areallylongurl.that.has.no.spaces.com/this/is/getting/ridiculous?with_a=query
    > > > which needs to be split twice.

Finally test that it preserves existing newlines:

    >>> msg = '> > > A line that got badly\n> > > broken somehow. But should not be reflowed.\nWith another quote level as\nwell.'
    >>> print rewrapMessage(msg, add_quote=True)
    > > > > A line that got badly
    > > > > broken somehow. But should not be reflowed.
    > With another quote level as
    > well.

But that it reflows broken lines:

    >>> msg = '> > > A line that will break when a quote is added and get flowed to the next\n> > > line. Which will itself be broken and flowed into the following line.\n> > > Which will be broken itself, but not be reflowed because the next line\n> is at a different quote level.'
    >>> print rewrapMessage(msg, add_quote=True)
    > > > > A line that will break when a quote is added and get flowed to the
    > > > > next line. Which will itself be broken and flowed into the following
    > > > > line. Which will be broken itself, but not be reflowed because the
    > > > > next line
    > > is at a different quote level.
