News:

Welcome to our NEW forum! We invite you to sign up today
so it can grow to be a valuable resource to all Toolbox users!

Main Menu

Quoting and requoting email

Started by oblivion, April 30, 2026, 05:38:47 PM

Previous topic - Next topic

oblivion

One of the email clients I use quotes replies by converting 

this is a line I need to reply to

to 

>this is a line I need to reply to.

At an absolute minimum, that should have a space after the chevron. So I built this:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Action: Abort if no clipboard text ""
0002 String: Assign from clipboard text ""
0003 String: Replace text ">=>space$"
0004 Clipboard: Assign text "string$"
(End)

Basic but straightforward.

However, what I'd LIKE to be able to to is take a block of text, strip the quote marks off it, rewrap it to a -- say -- 72 character line width, then put the quotes back -- and bearing in mind that some of the source text might be quoted already so might need doubled chevrons.

I used to use a mail client that could do that -- might have been The Bat! but (for unrelated reasons) I won't use it anymore. :)

So I thought maybe I could make a script that could do something like that -- but I can't find a way to do the rewrap element. I could probably find a way to handle multi-level quoting on a line-by-line basis, with some thought, but the rewrap element is beyond me.

So... any chance of a function that could rewrap plain text to a specified width, while respecting paragraph breaks? :)

Paul (Lead Developer)

Quote from: oblivion on April 30, 2026, 05:38:47 PMany chance of a function that could rewrap plain text to a specified width

Done for the next release. :) But check your email to get it now.


oblivion


oblivion

Hiya -- sorry, the rewrap isn't quite right, I don't think.

It's preserving all line ends, so the rewrap doesn't quite work as intended.

If I rewrap this paragraph in this environment, it'll probably work, because it's a single line being wrapped by the window manager, but in my email client, there'll be a <cr><lf> pair at the end of every line and two between paragraphs.

So what I want to be able to do is
rewrap a paragraph that's only really apparently a
paragraph but is actually a group of lines
of varying lengths
into something that looks like a genuine paragraph.

Like this:

So what I want to be able to do is rewrap a paragraph that's only really apparently a paragraph but is actually a group of lines of varying lengths into something that looks like a genuine paragraph. 

I assume it works this way because the mail client has already rewrapped the original email and put newlines in so the inserted chevrons are always at the start of the line.

Also -- sorry, this is only related in my head -- once I've rewrapped the paragraph, I want to requote it, so I'm using 

String: Replace text "~=~>space$"

to replace a newline with a newline followed by a chevron and a space. It works -- but I only found out tilde was a newline by accident in the help for a different command and thought I'd try it before designing a loop through the rewrapped text line by line.

Saved me lots of work but it should be in the help for the String: Replace text command :)

In case it's helpful, my current action looks like this:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 Action: Comment "Remove quote chevrons, rewrap and put quote marks back with an extra space"
0002 Action: Abort if no clipboard text ""
0003 String: Assign from clipboard text ""
0004 String: Replace text "~>=~"
0005 String: Word wrap at "68"
0006 ;String: Replace text "~=~>space$"
0007 Clipboard: Assign text "string$"
(End)

Paul (Lead Developer)

I think you want the "String: Remove line breaks" step:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 String: Assign "So what I want to be able to do is~rewrap a paragraph that's only really appar¬
ently a~paragraph but is actually a group of lines~of varying lengths~into something that looks lik¬
e a genuine paragraph."
0002 String: Remove line breaks "1"
0003 Alert: Show a message "string$"
(End)

So this:

So what I want to be able to do is
rewrap a paragraph that's only really apparently a
paragraph but is actually a group of lines
of varying lengths
into something that looks like a genuine paragraph.

Becomes this:

So what I want to be able to do is rewrap a paragraph that's only really apparently a paragraph but is actually a group of lines of varying lengths into something that looks like a genuine paragraph.

oblivion

Hi Paul -- I could use that function IF I could tell it only to remove one out of every two consecutive line breaks. If I remove all of them, actual paragraphs delineated by a blank line between them, also get joined together.

So what I want to achieve is:

> I could use that function IF I could tell it only to remove one out
> of every two consecutive line breaks. If I remove all of them,
> actual paragraphs delineated by a blank line between them, also get
> joined together. 

> So what I want to achieve is

and the remove all line breaks would give me


> I could use that function IF I could tell it only to remove one out
> of every two consecutive line breaks. If I remove all of them,
> actual paragraphs delineated by a blank line between them, also get
> joined together. So what I want to achieve is

This -- completely inadequately explained! -- was what I meant initially when I said rewrap should honour paragraphs!


Paul (Lead Developer)

Do you mean you want the red text to become the green text?


> I could use that function IF I could tell it only to remove one out
> of every two consecutive line breaks. If I remove all of them,
> actual paragraphs delineated by a blank line between them, also get
> joined together.

> So what I want to achieve is


> I could use that function IF I could tell it only to remove one out
> of every two consecutive line breaks. If I remove all of them,
> actual paragraphs delineated by a blank line between them, also get
> joined together. So what I want to achieve is


If so, you want this action:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 String: Assign "> I could use that function IF I could tell it only to remove one out~> of eve¬
ry two consecutive line breaks. If I remove all of them,~> actual paragraphs delineated by a blank ¬
line between them, also get~> joined together. ~~> So what I want to achieve is"
0002 String: Replace text "~~> ="
0003 Alert: Show a message "string$"
(End)

Which results in the green text from the red text.

oblivion

Hi Paul,

No. I want 

>I could use that function IF I could tell it only to remove one out of every two consecutive line breaks. If I remove all of them,
>actual paragraphs delineated by a blank line between them, also get joined together.

>This is the next paragraph

to become

> I could use that function IF I could tell it only to remove one out

> of every two consecutive line breaks. If I remove all of them,
> actual paragraphs delineated by a blank line between them, also get
> joined together.

> This is the next paragraph.

So: remove the > symbols, rewrap, put a "> " at the start of the resultant lines.


Paul (Lead Developer)

I don't follow (sorry). Can you put your before/after examples in colors, so I can better visualize what you mean?

I'm also confused by this bit of your post (which I've colored):

Original:

> I could use that function IF I could tell it only to remove one out of every two consecutive line breaks.

Wanted:

> I could use that function IF I could tell it only to remove one out

> of every two consecutive line breaks. If I remove all of them,


Why is there a line break after "one out" in the green wanted text, when there's none in the red original text? Where did that break come from?

oblivion

Quote from: Paul (Lead Developer) on May 03, 2026, 01:14:43 PMWhy is there a line break after "one out" in the green wanted text, when there's none in the red original text? Where did that break come from?
Not sure. Probably a typo. :D

When I asked for a rewrap function that respected paragraph breaks, this is what I meant:

Remove single linefeeds but leave in the second (and any subsequent) linefeeds of a group of consecutive linefeeds, then rewrap each line of the resultant text to the desired length without breaking words.

The other bits -- stripping out chevrons and adding them again -- not a problem, that's not part of the algorithm. That happens before and after the rewrap.


Let's ignore the chevrons. They're not part of this, and I can deal with them through existing functionality.

So. Let's say:

My starting text
is rather like this
with short lines
that nevertheless form
a paragraph.

Then there's another
paragraph of text
separated from the
previous paragraph
by a blank line.

What I want to do
is issue a rewrap
that preserves the
sense of the text
as paragraphs
separated by line
breaks.

Result:

My starting text is rather like this with short lines  that nevertheless form
a paragraph.

Then there's another paragraph of text separated from the previous
paragraph by a blank line.

What I want to do is issue a rewrap that preserves the sense of the text
as paragraphs separated by line breaks.

Alternatively, I'd also want to be able to rewrap

My starting text is rather like this with short lines that nevertheless form a paragraph.

Then there's another paragraph of text separated from the previous paragraph by a
blank line.

What I want to do is issue a rewrap that preserves the sense of the text as paragraphs
separated by line breaks.

To

My starting text is rather like this with short lines  that nevertheless form
a paragraph.

Then there's another paragraph of text separated from the previous
paragraph by a blank line.

What I want to do is issue a rewrap that preserves the sense of the text
as paragraphs separated by line breaks.

The requoting element (which existing functionality can deliver) can then look for ~ and replace with ~>space$ and I'll get

> My starting text is rather like this with short lines  that nevertheless form
> a paragraph.
>
> Then there's another paragraph of text separated from the previous
> paragraph by a blank line.
>
> What I want to do is issue a rewrap that preserves the sense of the text
> as paragraphs separated by line breaks.

Does that help? In my head, I'm repeating myself but I've definitely made some assumptions that I realise I shouldn't have made.

Paul (Lead Developer)

Okay, I think you want this action:

(Start)
HOW TO USE: Copy from Start to End, and then paste into an action.
REFERENCE : See an example of pasting at alomware.com/paste.png
0001 String: Assign "My starting text~is rather like this~with short lines~that nevertheless form~a¬
 paragraph.~~Then there's another~paragraph of text~separated from the~previous paragraph~by a blan¬
k line.~~What I want to do~is issue a rewrap~that preserves the~sense of the text~as paragraphs~sep¬
arated by line~breaks."
0002 String: Replace text "~~=[para]"
0003 String: Replace text "~= "
0004 String: Replace text "[para]=~~"
0005 String: Word wrap at "72"
0006 Alert: Show a message "string$"
(End)

Which turns this:

My starting text
is rather like this
with short lines
that nevertheless form
a paragraph.

Then there's another
paragraph of text
separated from the
previous paragraph
by a blank line.

What I want to do
is issue a rewrap
that preserves the
sense of the text
as paragraphs
separated by line
breaks.

Into this:

My starting text is rather like this with short lines that nevertheless
form a paragraph.

Then there's another paragraph of text separated from the previous
paragraph by a blank line.

What I want to do is issue a rewrap that preserves the sense of the
text as paragraphs separated by line breaks.

Am I right?

GCRedditor136

Quote from: oblivion on May 01, 2026, 09:20:45 PMI only found out tilde was a newline by accident in the help for a different command
Can this be changed, actually? The tilde character isn't exactly unique and can be used in normal text a lot. I think it should be changed to something less common. It doesn't really look like a newline character either.

oblivion

Quote from: Paul (Lead Developer) on May 04, 2026, 02:47:46 PMAm I right?

That looks like it'll do it. :) Thanks, Paul, I'll build that logic into my email requoter and see if I can break it. :D

Paul (Lead Developer)

@GCRedditor136: I agree that it should be changed. I'll look into the best way to do it that doesn't break existing actions.

@oblivion: I hope it works for your needs. :)