Commit Graph

360 Commits

Author SHA1 Message Date
Tim Culverhouse 6057d156e6 delete: revert deleted messages if Delete is unsupported
Delete operations are not supported by the notmuch backend. Revert
deleted messages when the operation is not supported, and reselect the
original selection.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-05 21:57:12 +02:00
Moritz Poldrack 70bfcfef42 lint: work nicely with wrapped errors (errorlint)
Error wrapping as introduced in Go 1.13 adds some additional logic to
use for comparing errors and adding information to it.

Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:58:04 +02:00
Moritz Poldrack 978d35d356 lint: homogenize operations and minor fixes (gocritic)
Apply GoDoc comment policy (comments for humans should have a space
after the //; machine-readable comments shouldn't)

Use strings.ReplaceAll instead of strings.Replace when appropriate

Remove if/else chains by replacing them with switches

Use short assignment/increment notation

Replace single case switches with if statements

Combine else and if when appropriate

Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:58:01 +02:00
Moritz Poldrack 5ca6022d00 lint: ensure errors are at least logged (errcheck)
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:57:57 +02:00
Moritz Poldrack ef599aa8fc lint: simplify code (gosimple)
Replaces infinite for loops containing a select on a channel with a
single case with a range over the channel.

Removes redundant assignments to blank identifiers.

Remove unnecessary guard clause around delete().

Remove `if condition { return true } return false` with return condition

Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:57:52 +02:00
Moritz Poldrack 77a00de741 lint: remove redundant returns (S1023)
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:57:45 +02:00
Moritz Poldrack ea2ac83a4d lint: fix function parameters being overwritten before they are used (SA4009)
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:57:43 +02:00
Moritz Poldrack b92e9dab19 lint: formatted code
Signed-off-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-04 21:56:33 +02:00
Moritz Poldrack aaf0a0c656 lint: apply new formatting rules
Run `make fmt`.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-01 10:44:52 +02:00
Tim Culverhouse 0c85b5a6cf msglist: remove invalidate from commands which remove messages
Archive, delete, and move all remove messages from the message store.
The commands themselves invalidated the message list. The message list
was also invalidated for every MessagesDeleted message received. Remove
the call in the command logic to reduce redraws of the message list

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-01 10:37:44 +02:00
Tim Culverhouse 894668aec2 archive,move: fix reselect next message
Move and Archive used store.Next to select the next message. When moving
or archiving multiple messages with an upward movement, this would
result in a to-be-removed message being selected. Use findNextNonDeleted
function to select the correct next message for these commands.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-01 10:37:42 +02:00
Tim Culverhouse 56dabb5c9c msgstore: leave visual-mark mode after certain commands
Commit "4753cfd visual-mode: deselect messages after performing command"
introduced the behavior of leaving visual mark mode after performing
certain commands. Add this behavior to additional commands:

- Delete
- Archive
- Move

Remark the selected mail files if an error occurred during the
operation.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-01 10:37:35 +02:00
Tim Culverhouse db195bebf0 commands: add check-mail command
Add :check-mail command for ad-hoc checking of mail. Reset timer for
automatic checking if it is enabled.

Suggested-by: staceee
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-01 10:37:28 +02:00
Robin Jarry c816103a24 pipe: fix ordering by message id for long patch series
Git send-email Message-Id headers have the following format:

   DATETIME.PID-NUM-COMMITTER

Unfortunately, when there are more than 9 patches, the patch number
(NUM) is not zero-padded which makes ascii sorting invalid, e.g.:

   1 10 11 12 2 3 4 5 6 7 8 9

Instead of:

   1 2 3 4 5 6 7 8 9 10 11 12

We need the patches to be ordered correctly to pipe them to git am.

Make sure to pad the patch number with zero characters to allow series
of up to 999 patches.

Only re-order messages before piping them if all the Message-Id headers
look like git-send-email headers.

Link: https://github.com/git/git/blob/v2.36.0/git-send-email.perl#L1197
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Koni Marti <koni.marti@gmail.com>
2022-08-01 09:38:15 +02:00
Stas Rudakou ca90343850 outgoing-cred-cmd: delay execution until an email needs to be sent
This can be useful in cases when:

1. outgoing-cred-cmd requires a user action or confirmation (e.g. when
   using pass with a Yubikey or similar smart card that requires a user
   to enter a pin or touch the device when decrypting the password)

2. A user starts aerc frequently, but not all the sessions end up with
   sending emails

3. So the user only wants to execute outgoing-cred-cmd when the password
   is really used, so the user doesn't have to enter pin or touch their
   Yubikey each time aerc starts

Signed-off-by: Stas Rudakou <stas@garage22.net>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-31 19:53:13 +02:00
Tim Culverhouse 6db766260b sort: clear sort criteria when called without arguments
Fix a regression introduced by commit c2f4404fca ("threading: enable
filtering of server-side threads"). Prior to this commit, a :sort
command (no args) would clear out the current sort criteria (or rather,
apply the value from the config). Restore this functionality.

Fixes: c2f4404fca ("threading: enable filtering of server-side threads")
Reported-by: akspecs <akspecs@gmail.com>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-26 22:24:01 +02:00
Koni Marti 26b9c3d966 sort: show warning when sort is not supported
Use the capabilities returned by the backend to check whether sort is
implemented when the user tries to use the sort command. Print a warning
to the log when a sort request is silently dropped by the backend.

Suggested-by: |cos|
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-26 22:22:58 +02:00
Koni Marti d941960fe1 delete: improve find next function
Improve the function to find the next valid message after the delete
operation. This ensures that messages at the end or when marked in the
visual mode are properly dealt with.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-26 11:34:31 +02:00
Koni Marti 8f7695fde5 msgstore: implement a uid-based architecture
Change the message store architecture from an index-based to a uid-based
one. Key advantage of this design approach is that no reselect mechanism
is required anymore since it comes with the design for free.

Fixes: https://todo.sr.ht/~rjarry/aerc/43
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-26 11:34:19 +02:00
Tim Culverhouse 9bfcec5660 delete: select new last message if last message was deleted
If the last message is deleted, the new selection should be the last
message instead of the first message.

Fixes: https://todo.sr.ht/~rjarry/aerc/59
Reported-by: Sebastien Binet <s@sbinet.org>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-24 23:05:53 +02:00
Tim Culverhouse 80f8bab6cf delete: move tab replace logic into Done callback
Move tab replacement logic for next-message-on-delete into the
callback. This also moves the Invalidate() call into the callback, and
should make imap deletion UI work more reliably - there is a race
condition between the worker and the UI in displaying deleted messages.
This should resolve the race condition, and also only remove the MsgView
tab if the message is actually deleted.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-24 23:05:11 +02:00
Robin Jarry cd19995557 logging: use level-based logger functions
Do not pass logger objects around anymore. Shuffle some messages to make
them consistent with the new logging API. Avoid using %v when a more
specific verb exists for the argument types.

The loggers are completely disabled (i.e. Sprintf is not even called)
by default. They are only enabled when redirecting stdout to a file.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
2022-07-23 22:52:15 +02:00
Robin Jarry 171fefd209 tabs: make fields private
The Tabs object exposes an array of Tab objects and the current selected
index in that array. The these two fields are sometimes modified in
goroutines, which can lead to data races causing fatal out of bounds
accesses on the tab array.

Hide these fields as private API. Expose only what needs to be seen from
the outside. This will prepare for protecting concurrent access with
a lock in the next commit.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Koni Marti <koni.marti@gmail.com>
2022-07-23 22:00:25 +02:00
Robin Jarry c841f36513 tabs: rename SelectedTab to SelectedTabContent
This function returns an ui.Drawable. Use a more explicit name. This
prepares for adding a new SelectedTab function which will return
an ui.Tab.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Koni Marti <koni.marti@gmail.com>
2022-07-23 22:00:21 +02:00
Koni Marti 76b39311dc send: enter no-quit mode until message is sent
Protect the sending of a message by entering the no-quit mode. This
prevents aerc from exiting with the :quit command until the operation is
done or the exit is forced.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-14 23:15:13 +02:00
Koni Marti e200cd56bf commands: implement a no-quit mode
Add a mode that prevents aerc from quitting normally when an important
task is performed, i.e. when sending a message. The no-quit mode will be
ignored when quit is used with the -f option to force an exit.

Suggested-by: ph14nix[m]
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-14 23:15:02 +02:00
Koni Marti 5102d32cea pipe: use go-mbox for writing multiple messages
Use go-mbox for piping out multiple messages in the mbox format.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-14 23:14:59 +02:00
Koni Marti e572087e58 account: import mbox file to a folder
Append all messages from an mbox file to the selected folder with the
import-mbox command.

User confirmation is required when the folder already contains messages.

A failed append will be retried a few times. If a backend timeout
occurs, the entire import is stopped to prevent a hang.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-14 23:14:56 +02:00
Koni Marti 845763cb1f account: export folder to mbox file
Export all message in the current folder to an mbox file. If an error
occurs during the export, aerc retries a few times before giving up to
prevent a hang.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-14 23:14:54 +02:00
Tim Culverhouse a953e4dbe9 threading: refactor reselect logic
This patch refactors reselection of a message during certain operations
(searching, filtering, clearing, deleting, moving, new message arrival).
The addition of server-side filtering for threaded views broke the
existing reselection logic.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 21:15:12 +02:00
Tim Culverhouse c2f4404fca threading: enable filtering of server-side threads
This patch enables the filtering of a threaded view which uses
server-built threads. Filtering is done server-side, in order to
preserve the use of server-built threads.

In adding this feature, the filtering of notmuch folders was brought up
to feature parity with the other workers. The filters function the same
(ie: they can be stacked). The notmuch filters, however, still use
notmuch syntax for the filtering.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 21:15:12 +02:00
Tim Culverhouse 3a614e45fc threading: enable toggle-threads for server-side threads
Enable the :toggle-threads command to work for workers which have Thread
capability. The implementation of that feature has the side effect that
the threading-enabled config option now sets the default view (threaded
or not threaded) for any worker, not just IMAP or notmuch.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 21:15:12 +02:00
Koni Marti e19b411e52 recall: support pgp/mime messages
PGP/MIME messages are stored encrypted and/or signed in the draft folder
for security reasons. Recall will open them through the lib.MessageView
interface in order to display the message content properly in the
composer tab. If the stored message was encrypted or signed, the
recalled message in the composer will also be encrypted or signed.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 20:39:53 +02:00
Koni Marti a293a39454 recall: append attachments
Append attachments to the composer when a message with attachments is
recalled. Before the attachement refactoring in the composer, the
recalled attachments were ignored.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 20:39:46 +02:00
Koni Marti 4335eeceb3 recall: confirm deleting message when not sent
Ask for user confirmation when a recalled message is deleted after the
composer is closed but the message has not been sent yet. The message
will only be deleted automatically when the message is sent. This might
prevent data loss since the recalled message is currently deleted either
way.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 20:39:42 +02:00
Koni Marti 99b74dbcc9 postpone: avoid calling WriteMessage twice
Postpone will currently call composer.WriteMessage twice: once for
counting the bytes and another time for appending the message.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 20:36:24 +02:00
Sergey Smirnykh 12e8217d1f commands: implement prompt completion
This patch implements :prompt completion.
The completion mechanism only provides completions when there is at least
one argument specified (prompt text).
The mechanism is based on other commands' completions and works as follows:

   1. Attempts to look up a command by the name specified in args[1].

   2.a On success it uses command.Complete.

   2.b Otherwise, if total arguments count is lesser or equals than 2
       (i.e. no command arguments specified), it attempts to complete
       the command's name.

Additional effort is made to preserve prompt text, which often contains
spaces and formatting.

Signed-off-by: Sergey Smirnykh <sergey.smirnykh@siborgium.xyz>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-02 18:36:40 +02:00
Koni Marti c04446327e forward: remove crlf in text body
Remove crlf from the text body when forwarding a message.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2022-07-02 17:53:11 +02:00
Koni Marti 60052c6070 forward: provide option to append all attachments
Append all non-multipart attachments with the -A flag. Rename the flag
for forwarding a full message as an RFC2822 attachments to -F.

Suggested-by: psykose
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2022-07-02 17:53:06 +02:00
Koni Marti 9d90b70b4e compose: refactor attachment handling
Refactor the attachment handling process in the composer. The composer
can currently only handle attachments that are stored as files (or pgp
keys). This patch removes this limitation so that any message part can
be handled as an attachment. With this we can treat files, pgp keys and
message parts on an equal footing and it will enable us also to easily
forward attachments.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2022-07-02 17:52:49 +02:00
Tim Culverhouse 96db50c4f0 open: fix mimetype discovery for encrypted or signed messages
Mimetype discovery for the :open command is based on the BodyStructure
of the message. This patch fixes the method which got the BodyStructure
of the message to a more generalized one, which is set post-encryption
and post-validation. This allows encrypted or signed message parts to
have their proper mimetype discovered.

Fixes: https://todo.sr.ht/~rjarry/aerc/50
Reported-by: ~ph14nix
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Koni Marti <koni.marti@gmail.com>
2022-06-26 12:07:44 +02:00
Tim Culverhouse 8f9bb2b289 pgp: fix pipe|open|save command behavior
Signed and/or encrypted PGP messages did not behave properly for pipe,
open, and save commands. Specifically, the proper Message Part would not
be passed to the command in the MessageViewer. This is due to the
encapsulation of the body structure. This patch fixes the behavior for
piping|opening|saving of message parts.

Fixes: https://todo.sr.ht/~rjarry/aerc/47
Reported-by: ~ph14nix
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-24 21:08:21 +02:00
Koni Marti e1d8bc4d17 msgviewer: open http links from messages
Parse http links from a message and display them as completions in the
:open-link command.

Add the following binds to the [view] section in your binds.conf:
<C-l> = :open-link <space>

Parsing can be disabled in aerc.conf by setting parse-http-links to
false in the viewer section.

Thanks to Moritz for the help with the regular expression.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Reviewed-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-14 22:12:48 +02:00
Tim Culverhouse 4753cfd3e3 visual-mode: deselect messages after performing command
In order to better align to vim functionality: deselect visual mode
selections after performing a command on the selection. This patch also
introduces a new command to allow for re-selecting (remarking) the
previous selection set so that commands can be chained together. The
deselection only applies to msg commands that *do not* move the message
from the store (those types of commands already deselect):
- read/unread
- flag/unflag
- modify-labels
- copy
- pipe

Previous usage to mark several messages as read and deselect all:
Vjjj:read<Enter>:unmark -a<Enter>

New usage, similar to vim:
Vjjj:read<Enter>

To chain a command together:
Vjjj:read<Enter>:remark<Enter>{next command}<Enter>

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-14 22:12:42 +02:00
Koni Marti 461726802e unsubscribe: select method with the selector dialog
Provide a choice to the user with the selector dialog to select the
desired unsubscribe method. Before, the first method that appeared in
the list-unsubscribe header was used.

For the http method, the user can now also confirm whether he wants to
open the provided link in the browser or not.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-31 14:32:33 +02:00
Koni Marti 62982a9a67 invites: reply with accept, accept-tentative or decline
Reply to iCalendar invitations with three commands: :accept,
:accept-tentative or :decline. Parse a text/calendar request, create a
reply and append it to the composer.

Suggested-by: Ondřej Synáček <ondrej@synacek.org>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-31 14:32:24 +02:00
Tim Culverhouse f4d4e2b4e1 help: add completions
Add :help completion arguments (config, imap, etc). The option "aerc"
brings up the general manpage

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Koni Marti <koni.marti@gmail.com>
2022-05-23 20:59:10 +02:00
Tim Culverhouse b57fceaad4 pgp: add attach key command
Add compose command ("attach-key") to attach the public key associated
with the sending account. Public key is attached in ascii armor format,
with the mimetype set according to RFC 3156 ("application/pgp-keys").

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
2022-05-06 11:02:55 +02:00
Tim Culverhouse 32a16dcd8d pgp: check encryption keys before sending message
Add check for public keys of all message recipients (to, cc, and bcc)
before sending the message. Adds an OnFocusLost callback to header
editors to facilitate a callback for checking keys whenever a new
recipient is added (OnChange results in too many keyring checks).

Once encryption is initially set, the callbacks are registered. If a
public key is not available for any recipient, encryption is turned off.
However, notably, the callbacks are still registered meaning as s soon
as the user removes the recipients with missing keys, encryption is
turned back on.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
2022-05-06 11:02:50 +02:00
Tim Culverhouse dbf52bb4b4 pgp: check for signing key before signing time
Check that the signing key exists when the user issues the :sign
command. The signing key ID will be displayed in the security status
also, allowing the user to see what key will be used to sign the
message.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Jens Grassel <jens@wegtam.com>
2022-05-04 14:07:15 +02:00