Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another attempt at handling text/calendar sensibly #1607

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MacGyverNL
Copy link
Contributor

@MacGyverNL MacGyverNL commented Sep 14, 2022

This is an attempt at fixing the following combination of long-standing issues:

  1. Outlook sends calendar invites as text/calendar without a content disposition, so it doesn't show up as an attachment.

  2. alot doesn't handle text/calendar as a mimepart without explicitly navigating to it via the mimetree.

  3. If a user sets their mailcap to text/calendar; cat '%s'; copiousoutput, the calendar contents get displayed as expected, and may be processed using a pipeto command.

The combination of 1 and 2 make it so that text/calendar invites from outlook are effectively hidden by default in alot.

The existence of 3 makes it so that we can't simply turn text/calendar into attachments.

An early attempt at fixing this by allowing text/calendar to be a preferred mimetype was made in #640 but that seems to have been lost. However, we have to assume that the demonstrated workflow based on decoding with mailcap and using pipeto is in use.

#752 handles this situation by having multiple mailcap lines with different flags. This was merged but then removed in 7a88310

Another idea, handling all unrendered parts as attachments, was proposed in #777. Since we now have a mimetree, this is not strictly necessary, but it would be nice to be able to save the inline text/calendar as a .ics-file.

Combining these ideas, this proposal does three things (EDIT: the current state of the PR has slightly modified the approach but the underlying principles are the same. See #1607 (comment).):

  1. Introduce an alot-specific x-alot-openattachment field for mailcap, that alot prefers when opening an attachment. If it is not present, alot will fall back to the standard ('view') field for opening the attachment.

  2. Every text/calendar part without a content-disposition gets one forced on it, effectively turning it into an attachment. The resulting attachment is visible in the attachments list and can be handled as any other attachment: saved, and handled by mailcap. However, opening such an attachment via the attachment widget will not display it in the current proposal. Since these weren't attachments before, there's no need to handle them backwards-compatible with issue 3 above.

  3. When a part gets selected via the mimetree, alot checks whether there is a separate x-alot-openattachment field defined in the mailcap. If there is, alot will first attempt to display the attachment as mimepart, and then open the attachment as per 2. I expect this to be the most controversial change.

Example mailcap entry:
text/calendar; cat '%s'; x-alot-openattachment=tmux-horizontal-split-blocking.sh khal import '%s'; copiousoutput

I should note I'm not too attached (hah) to this approach; I coded it up in an afternoon based on what I thought would sensibly fix it for my own usecase. This PR is mostly intended to discuss how to finally deal with this issue sensibly; if we arrive on the solution in this PR itself, all the better.

This is an attempt at fixing the following combination of long-standing
issues:

1. Outlook sends calendar invites as `text/calendar` without a content
   disposition, so it doesn't show up as an attachment.

2. alot doesn't handle `text/calendar` as a mimepart without explicitly
   navigating to it via the mimetree.

3. *If* a user sets their mailcap to
   `text/calendar; cat '%s'; copiousoutput`, the calendar contents get
   displayed as expected, and may be processed using a pipeto command.

The combination of 1 and 2 make it so that `text/calendar` invites from
outlook are effectively hidden by default in alot.

The existence of 3 makes it so that we can't simply turn `text/calendar`
into attachments.

An early attempt at fixing this by allowing `text/calendar` to be a
preferred mimetype was made in <pazz#640>
but that seems to have been lost. However, we have to assume that the
demonstrated workflow based on decoding with mailcap and using `pipeto`
is in use.

<pazz#752> handles this situation by having
multiple mailcap lines with different flags. This was merged but then
removed in 7a88310

Another idea, handling all unrendered parts as attachments, was proposed
in <pazz#777>. Since we now have a
mimetree, this is not *strictly* necessary, but it *would* be nice to be
able to save the inline text/calendar as a .ics-file.

Combining these ideas, this proposal does three things:

1. Introduce an alot-specific x-alot-openattachment field for mailcap,
   that alot prefers when *opening* an attachment. If it is not present,
   alot will fall back to the standard ('view') field for opening the
   attachment.

2. Every `text/calendar` part without a content-disposition gets one
   forced on it, effectively turning it into an attachment. The
   resulting attachment is visible in the attachments list and can be
   handled as any other attachment: saved, and handled by mailcap.
   However, *opening* such an attachment via the attachment widget *will
   not display it* in the current proposal. Since these weren't
   attachments before, there's no need to handle them
   backwards-compatible with issue 3 above.

3. When a part gets selected via the mimetree, alot checks whether there
   is a separate `x-alot-openattachment` field defined in the mailcap.
   If there is, alot will first attempt to display the attachment as
   mimepart, and then open the attachment as per 2. I expect this to be
   the most controversial change.

Example mailcap entry:
```text/calendar; cat '%s'; x-alot-openattachment=tmux-horizontal-split-blocking.sh khal import '%s'; copiousoutput```
@MacGyverNL
Copy link
Contributor Author

Having thought about this some more, the more sensible solution is probably to define an x-alot-attachmenttotext for mailcap and changing the mime-display codepath, so that mailcap's default handler is the "proper" system handler. I'll rewrite this to take that approach.

@MacGyverNL MacGyverNL marked this pull request as draft September 14, 2022 11:38
Rather than use x-alot-openattachment, and rely on the default ('view')
mailcap entry to dump the attachment to text, assume that the default
entry is set up to handle attachments *as attachments*, i.e. open them
in whatever application is supposed to handle them.

Instead, define x-alot-attachmenttotext that provides a way to render
the attachment as text. If defined, opening the attachment through the
mime tree will both show it as text *and* open it. If not defined,
opening the attachment through the mime tree will only open it.

When opening the attachment through the attachment widget, it's still
only opened even if an x-alot-attachmenttotext handler is defined.
@MacGyverNL
Copy link
Contributor Author

MacGyverNL commented Sep 14, 2022

So the current proposal is as follows:

  • Assume that the default entry is set up to handle attachments as attachments,
    i.e. open them in whatever application is supposed to handle them.

  • Define x-alot-attachmenttotext that provides a way to render
    the attachment as text. If defined, opening the attachment through the
    mime tree will both show it as text and open it. If not defined,
    opening the attachment through the mime tree will only open it.

  • When opening the attachment through the attachment widget, it's still
    only opened even if an x-alot-attachmenttotext handler is defined.

There is no way to only render the attachment (at the moment). I
don't really have a usecase for this myself, but perhaps we could gate
the mimetree "open attachment" action behind a prompt if the attachment
is rendered using an x-alot-attachmenttotext handler?

Example mailcap entry:
text/calendar; tmux-horizontal-split-blocking.sh khal import '%s'; x-alot-attachmenttotext=cat '%s'; copiousoutput

@pazz
Copy link
Owner

pazz commented Jul 26, 2023

Sorry if this is an inappropriately simple suggestion but why don't we simply hard-code an exception to consider a MIME part an attachment if it is text/calendar even if it is lacking a content-disposition?

@MacGyverNL
Copy link
Contributor Author

At the time I didn't feel up to messing with that part of the code, iirc.

I'm afraid that work circumstances have steered me back to using Thunderbird and plain Maildir for my mail, so I no longer daily-drive alot. For me it's therefore become a non-issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants