~rjarry/aerc-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
8 4

[PATCH aerc v2] commands/msg: use selected message part for quote-reply and forward

Details
Message ID
<20240109135335.29201-1-s@sbinet.org>
DKIM signature
missing
Download raw message
Patch: +40 -6
use the currently selected message part (if any) as the original message
for quote-reply and forward.
honor viewer::alternatives if no message part was selected.

Signed-off-by: Sebastien Binet <s@sbinet.org>
---
 commands/msg/forward.go | 23 ++++++++++++++++++++++-
 commands/msg/reply.go   | 23 ++++++++++++++++++-----
 2 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/commands/msg/forward.go b/commands/msg/forward.go
index 4147e8c..4b65086 100644
--- a/commands/msg/forward.go
+++ b/commands/msg/forward.go
@@ -143,11 +143,32 @@ func (f forward) Execute(args []string) error {
			f.Template = config.Templates.Forwards
		}

		part := lib.FindPlaintext(msg.BodyStructure, nil)
		part := func() []int {
			provider, ok := app.SelectedTabContent().(app.ProvidesMessage)
			if !ok {
				return nil
			}
			p := provider.SelectedMessagePart()
			if p == nil {
				return nil
			}
			return p.Index
		}()

		if part == nil {
			for _, mime := range config.Viewer.Alternatives {
				part = lib.FindMIMEPart(mime, msg.BodyStructure, nil)
				if part != nil {
					break
				}
			}
		}

		if part == nil {
			part = lib.FindFirstNonMultipart(msg.BodyStructure, nil)
			// if it's still nil here, we don't have a multipart msg, that's fine
		}

		err = addMimeType(msg, part, &original)
		if err != nil {
			return err
diff --git a/commands/msg/reply.go b/commands/msg/reply.go
index 4b3e7c8..3b02ca1 100644
--- a/commands/msg/reply.go
+++ b/commands/msg/reply.go
@@ -222,11 +222,24 @@ func (r reply) Execute(args []string) error {
			return nil
		}

		var part []int
		for _, mime := range config.Viewer.Alternatives {
			part = lib.FindMIMEPart(mime, msg.BodyStructure, nil)
			if part != nil {
				break
		part := func() []int {
			provider, ok := app.SelectedTabContent().(app.ProvidesMessage)
			if !ok {
				return nil
			}
			p := provider.SelectedMessagePart()
			if p == nil {
				return nil
			}
			return p.Index
		}()

		if part == nil {
			for _, mime := range config.Viewer.Alternatives {
				part = lib.FindMIMEPart(mime, msg.BodyStructure, nil)
				if part != nil {
					break
				}
			}
		}

-- 
2.43.0

[aerc/patches] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CYA88ZZZL8XL.1Q7QK59GSEQNQ@cirno2>
In-Reply-To
<20240109135335.29201-1-s@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
aerc/patches: SUCCESS in 4m38s

[commands/msg: use selected message part for quote-reply and forward][0] v2 from [Sebastien Binet][1]

[0]: https://lists.sr.ht/~rjarry/aerc-devel/patches/48443
[1]: s@sbinet.org

✓ #1130071 SUCCESS aerc/patches/openbsd.yml     https://builds.sr.ht/~rjarry/job/1130071
✓ #1130070 SUCCESS aerc/patches/alpine-edge.yml https://builds.sr.ht/~rjarry/job/1130070
Details
Message ID
<CYA9D366PKDI.2VNTHWSXXY98H@gmail.com>
In-Reply-To
<20240109135335.29201-1-s@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
On Tue Jan 9, 2024 at 1:53 PM UTC, Sebastien Binet wrote:
> use the currently selected message part (if any) as the original message
> for quote-reply and forward.
> honor viewer::alternatives if no message part was selected.
>
> Signed-off-by: Sebastien Binet <s@sbinet.org>
> ---

Thanks for v2. Tested both with :reply and :forward and it works well.

>  commands/msg/forward.go | 23 ++++++++++++++++++++++-
>  commands/msg/reply.go   | 23 ++++++++++++++++++-----
>  2 files changed, 40 insertions(+), 6 deletions(-)
>
> diff --git a/commands/msg/forward.go b/commands/msg/forward.go
> index 4147e8c..4b65086 100644
> --- a/commands/msg/forward.go
> +++ b/commands/msg/forward.go
> @@ -143,11 +143,32 @@ func (f forward) Execute(args []string) error {
>  			f.Template = config.Templates.Forwards
>  		}
>  
> -		part := lib.FindPlaintext(msg.BodyStructure, nil)
> +		part := func() []int {
> +			provider, ok := app.SelectedTabContent().(app.ProvidesMessage)
> +			if !ok {
> +				return nil
> +			}
> +			p := provider.SelectedMessagePart()
> +			if p == nil {
> +				return nil
> +			}
> +			return p.Index
> +		}()
> +
> +		if part == nil {
> +			for _, mime := range config.Viewer.Alternatives {
> +				part = lib.FindMIMEPart(mime, msg.BodyStructure, nil)
> +				if part != nil {
> +					break
> +				}
> +			}
> +		}
> +

We could also extract the logic into a function to avoid having
duplicated code in both reply and forward. Something like:

```
func getMessagePart(msg *models.MessageInfo, provider app.ProvidesMessage) []int {
	p := provider.SelectedMessagePart()
	if p != nil {
		return p.Index
	}
	for _, mime := range config.Viewer.Alternatives {
		part := lib.FindMIMEPart(mime, msg.BodyStructure, nil)
		if part != nil {
			return part
		}
	}
	return nil
}
```

which can be called with the `widget` variable that is already cast to
`app.ProvidesMessage` in both reply and forward:

```
part := getMessagePart(msg, widget)
```

What do you think?
Details
Message ID
<CYAAKRX9Y7JW.1D9ZMB3NBCO9@sbinet.org>
In-Reply-To
<CYA9D366PKDI.2VNTHWSXXY98H@gmail.com> (view parent)
DKIM signature
missing
Download raw message
On Tue Jan 9, 2024 at 15:50 CET, Koni Marti wrote:
> On Tue Jan 9, 2024 at 1:53 PM UTC, Sebastien Binet wrote:
> > use the currently selected message part (if any) as the original message
> > for quote-reply and forward.
> > honor viewer::alternatives if no message part was selected.
> >
> > Signed-off-by: Sebastien Binet <s@sbinet.org>
> > ---
>
> Thanks for v2. Tested both with :reply and :forward and it works well.
>
> >  commands/msg/forward.go | 23 ++++++++++++++++++++++-
> >  commands/msg/reply.go   | 23 ++++++++++++++++++-----
> >  2 files changed, 40 insertions(+), 6 deletions(-)
> >
> > diff --git a/commands/msg/forward.go b/commands/msg/forward.go
> > index 4147e8c..4b65086 100644
> > --- a/commands/msg/forward.go
> > +++ b/commands/msg/forward.go
> > @@ -143,11 +143,32 @@ func (f forward) Execute(args []string) error {
> >  			f.Template = config.Templates.Forwards
> >  		}
> >  
> > -		part := lib.FindPlaintext(msg.BodyStructure, nil)
> > +		part := func() []int {
> > +			provider, ok := app.SelectedTabContent().(app.ProvidesMessage)
> > +			if !ok {
> > +				return nil
> > +			}
> > +			p := provider.SelectedMessagePart()
> > +			if p == nil {
> > +				return nil
> > +			}
> > +			return p.Index
> > +		}()
> > +
> > +		if part == nil {
> > +			for _, mime := range config.Viewer.Alternatives {
> > +				part = lib.FindMIMEPart(mime, msg.BodyStructure, nil)
> > +				if part != nil {
> > +					break
> > +				}
> > +			}
> > +		}
> > +
>
> We could also extract the logic into a function to avoid having
> duplicated code in both reply and forward. Something like:
>
> ```
> func getMessagePart(msg *models.MessageInfo, provider
> app.ProvidesMessage) []int {
> p := provider.SelectedMessagePart()
> if p != nil {
> return p.Index
> }
> for _, mime := range config.Viewer.Alternatives {
> part := lib.FindMIMEPart(mime, msg.BodyStructure, nil)
> if part != nil {
> return part
> }
> }
> return nil
> }
> ```
>
> which can be called with the `widget` variable that is already cast to
> `app.ProvidesMessage` in both reply and forward:
>
> ```
> part := getMessagePart(msg, widget)
> ```
>
> What do you think?

sure, why not.
I'll put it under commands/msg/utils.go

-s
Details
Message ID
<CYACRK0UI0HE.15JZ7UWBKN0V9@ferdinandy.com>
In-Reply-To
<20240109135335.29201-1-s@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
On Tue Jan 09, 2024 at 14:53, Sebastien Binet <s@sbinet.org> wrote:
> use the currently selected message part (if any) as the original message
> for quote-reply and forward.
> honor viewer::alternatives if no message part was selected.
>
> Signed-off-by: Sebastien Binet <s@sbinet.org>
> ---

This will be useful! What will happen if I'm on say an image?

Best,
Bence

--
+36305425054
bence.ferdinandy.com
Details
Message ID
<CYB8YI31PQGB.RD2CD9NGLTWT@sbinet.org>
In-Reply-To
<CYACRK0UI0HE.15JZ7UWBKN0V9@ferdinandy.com> (view parent)
DKIM signature
missing
Download raw message
On Tue Jan 9, 2024 at 18:30 CET, Bence Ferdinandy wrote:
>
> On Tue Jan 09, 2024 at 14:53, Sebastien Binet <s@sbinet.org> wrote:
> > use the currently selected message part (if any) as the original message
> > for quote-reply and forward.
> > honor viewer::alternatives if no message part was selected.
> >
> > Signed-off-by: Sebastien Binet <s@sbinet.org>
> > ---
>
> This will be useful! What will happen if I'm on say an image?

it will do what is being asked :}
quote-reply the current part, ie: quote-reply the image content

for an image, aka a binary part, it's not super useful.
but there's a valid use case for, say, an attachment that is a non-binary document (markdown or such).

I guess it would be possible to detect that the current part is binary-like and fallback on either "honoring the 'alternatives' configuration" or on the first text/plain part (as is currently done in the patch when the message is not opened).
but... is it worth the extra code ?

cheers,
-s
Details
Message ID
<CYB97G27VUU4.26791FI293QAF@ferdinandy.com>
In-Reply-To
<CYB8YI31PQGB.RD2CD9NGLTWT@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
On Wed Jan 10, 2024 at 19:44, Sebastien Binet <s@sbinet.org> wrote:
> On Tue Jan 9, 2024 at 18:30 CET, Bence Ferdinandy wrote:
> >
> > This will be useful! What will happen if I'm on say an image?
>
> it will do what is being asked :}
> quote-reply the current part, ie: quote-reply the image content

Isn't there a possibility of breaking the terminal if that happens?

>
> for an image, aka a binary part, it's not super useful.
> but there's a valid use case for, say, an attachment that is a non-binary document (markdown or such).

agreed

>
> I guess it would be possible to detect that the current part is binary-like and fallback on either "honoring the 'alternatives' configuration" or on the first text/plain part (as is currently done in the patch when the message is not opened).
> but... is it worth the extra code ?

As long as it doesn't break stuff I don't think so. But if it's like when you
accidentally cat a binary, then it's likely worth to be on the safe side.

Best,
Bence





--
+36305425054
bence.ferdinandy.com
Details
Message ID
<CYB9VI0DRWF7.3EHJTS5MXMA30@sbinet.org>
In-Reply-To
<CYB97G27VUU4.26791FI293QAF@ferdinandy.com> (view parent)
DKIM signature
missing
Download raw message
On Wed Jan 10, 2024 at 19:56 CET, Bence Ferdinandy wrote:
>
> On Wed Jan 10, 2024 at 19:44, Sebastien Binet <s@sbinet.org> wrote:
> > On Tue Jan 9, 2024 at 18:30 CET, Bence Ferdinandy wrote:
> > >
> > > This will be useful! What will happen if I'm on say an image?
> >
> > it will do what is being asked :}
> > quote-reply the current part, ie: quote-reply the image content
>
> Isn't there a possibility of breaking the terminal if that happens?

I've just tried quote-replying to a mail with a mp4 as attachment (yeah... don't get me started...) and that didn't break my terminal.

in the end, it depends on the editor one is using for composing emails and how it behaves when presented with binary data.
neovim did fine in my case.

hth,
-s
Details
Message ID
<CYBA1NF3FSMI.OCEEDUU76YIM@ferdinandy.com>
In-Reply-To
<CYB9VI0DRWF7.3EHJTS5MXMA30@sbinet.org> (view parent)
DKIM signature
missing
Download raw message
On Wed Jan 10, 2024 at 20:27, Sebastien Binet <s@sbinet.org> wrote:
> On Wed Jan 10, 2024 at 19:56 CET, Bence Ferdinandy wrote:
> >
> > On Wed Jan 10, 2024 at 19:44, Sebastien Binet <s@sbinet.org> wrote:
> > > On Tue Jan 9, 2024 at 18:30 CET, Bence Ferdinandy wrote:
> > > >
> > > > This will be useful! What will happen if I'm on say an image?
> > >
> > > it will do what is being asked :}
> > > quote-reply the current part, ie: quote-reply the image content
> >
> > Isn't there a possibility of breaking the terminal if that happens?
>
> I've just tried quote-replying to a mail with a mp4 as attachment (yeah... don't get me started...) and that didn't break my terminal.
>
> in the end, it depends on the editor one is using for composing emails and how it behaves when presented with binary data.
> neovim did fine in my case.

sounds good to me! thanks for checking.

Best,
Bence





--
+36305425054
bence.ferdinandy.com
Reply to thread Export thread (mbox)