Commit Graph

1192 Commits

Author SHA1 Message Date
Koni Marti 4a4050ee0f ui: fix panic in selector when resizing terminal
Fix panic when resizing the terminal by dynamically adjusting the width
of the option selector. The selector does not check the width of the
terminal before printing. This can lead to a panic in the account wizard
when reducing the terminal width.

If the terminal width is not large enough, the space between the options
is reduced. If this is still not enough, then the selector will only
show the focused option and arrows indicating the alternatives.

Fixes: https://todo.sr.ht/~rjarry/aerc/41
Reported-by: Omar Polo <op@omarpolo.com>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-08 18:36:49 +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 bb400c7d88 pgp: add options auto-sign & opportunistic-encrypt
Add account level config options for auto-sign and opportunistic
encryption.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
2022-05-06 11:02:43 +02:00
Koni Marti 5c5158b3c1 store: remove callbacks on error
Unmark deleted messages and remove pending headers in the callback
function when an error in the backend occurs (e.g. due to connection
issues).

The message store marks messages that should be deleted. If the delete
operation in the backend fails, messages are never unmarked and will
remain rendered as empty lines in the message list. This also affects
the move and archive commands that rely on a copy and delete operation.

A similar issue occurs with the pending headers when the operation to
fetch them fails. In this case, messages will appear as loading
indefinitely in the message list and are never re-fetched because the
corresponding pending headers from the failed operations are still
present.

Fixes: https://todo.sr.ht/~rjarry/aerc/28
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-06 11:02:33 +02:00
Robin Jarry ad51cb3611 compose: use selected account ui config for security header
Do not use the default ui config.

Fixes: 78b7e4e993 ("compose: add sign/encrypt persistent display")
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-05-04 14:10:34 +02:00
Tim Culverhouse 21fca56292 pgp: fix crash on gpg decrypt fail
The gpg decrypt function was catching errors but not returning them.
This patch returns errors that are caught instead of aerc panicking.

Reported-by: ReK2 <rek2@hispagatos.org>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: ReK2 <rek2@hispagatos.org>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-04 14:10:32 +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
Koni Marti b29293d7b5 imap: add timeout to tcp connect functions
Extract the tcp connection details and timeout the tcp connect functions
(net.ResolveTCPAddr and net.DialTCP). If timed out, ensure that the
connection is properly closed.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-04 14:07:15 +02:00
Koni Marti b92efe4cd9 imap: add debouncer to the idler
Add a debouncer to the idle mode. Avoid unnecessary idling when another
job arrives within a certain time frame.

For example, the ui sends three messages to the worker at the same time
when we open a message (FlagMessage, FetchMessageBodyPart, and the
FetchMessageHeaders). The debouncer prevents the unnecessary entering
and leaving of the idle mode between those messages.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-04 14:07:15 +02:00
Koni Marti e5b339702a imap: monitor the logout channel with an observer
Untangle the observer functionality from the message handling routine.
Observe the imap client's logout channel and trigger a connection error
when necessary to start the reconnect cycle.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-04 14:07:15 +02:00
Koni Marti 397a6f267f imap: manage idle mode with an idler
Untangle the idle functionality from the message handling routine. Wait
for the idle mode to properly exit every time to ensure a consistent
imap state. Timeout when hanging in idle mode and inform the ui.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-04 14:07:15 +02:00
Koni Marti 4d75137b20 imap: extract imap config and configure handling
Extract the imap config and move the configure part out of the message
handler.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-04 14:07:15 +02:00
inwit a1b75a99bd recall: mention the -f option in the error message
Commit bc593ac7cd ("recall: allow recalling messages from any folder")
added the possibility to recall any message by providing the -f flag.
Mention the flag in the error message.

Signed-off-by: inwit <inwit@sindominio.net>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-29 15:02:28 +02:00
Tim Culverhouse 78b7e4e993 compose: add sign/encrypt persistent display
Add a text row below the header editors to (persistently) display if the
current message will be signed, encrypted, or both. The display will
disappear if the message will not be signed or encrypted. The display
is visible on the reviewMessage screen as well

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
2022-04-29 15:00:17 +02:00
Koni Marti e1ae7b80cc dirlist: add format specifier to compact folder name
Add the format specifier %N to the dirlist-format to display compacted
folder names.

A folder such as INBOX/WORK/PROJECT will be compacted to I/W/PROJECT in
the directoy list.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2022-04-29 13:41:38 +02:00
Koni Marti 8f976af17b imap: fix out-of-range panic for imap updates
Check slice bounds before using it for the message and expunge updates.
Log the error but ignore the affected updates.

Link: https://lists.sr.ht/~rjarry/aerc-devel/%3CCJEHBFFUI11T.1AYGOMVGZ87ZS%40rek2system%3E
Reported-by: ReK2 <rek2@hispagatos.org>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-29 13:41:35 +02:00
Robin Jarry 2f2a520ab0 compose: use account ui config where missing
The composer widget already has a reference to the AccountView object.
Get the UI config from it directly.

This completes commit 6edfbfa8ce ("aerc: use contextual ui styleset
for tabs/compose").

Fixes: https://todo.sr.ht/~rjarry/aerc/3
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Koni Marti <koni.marti@gmail.com>
2022-04-28 17:56:42 +02:00
Connor Kuehl 01528ae1e2 grid: don't draw at a negative offset
aerc panics when using macOS's default terminal emulator, Terminal.app,
when closing all but aerc's tab:

This error was also written to: /tmp/aerc-crash-20220427-194134.log
panic: Attempted to create context with negative offset [recovered]
	panic: Attempted to create context with negative offset

goroutine 1 [running]:
git.sr.ht/~rjarry/aerc/logging.PanicHandler()
	/Users/ckuehl/src/aerc/logging/panic-logger.go:47 +0x58c
panic({0x100d077a0, 0x14000032700})
	/opt/homebrew/Cellar/go/1.18.1/libexec/src/runtime/panic.go:844 +0x258
git.sr.ht/~rjarry/aerc/lib/ui.(*Context).Subcontext(0x1400013e420?, 0x14000202360?, 0x140000ffc48?, 0x1009a10e4?, 0x100da9440?)
	/Users/ckuehl/src/aerc/lib/ui/context.go:47 +0x160
git.sr.ht/~rjarry/aerc/lib/ui.(*Grid).Draw(0x1400013e420, 0x14000202360)
	/Users/ckuehl/src/aerc/lib/ui/grid.go:143 +0x2bc
git.sr.ht/~rjarry/aerc/widgets.(*Aerc).Draw(0x1400013e4d0, 0x14000202360)
	/Users/ckuehl/src/aerc/widgets/aerc.go:178 +0x30
git.sr.ht/~rjarry/aerc/lib/ui.(*UI).Tick(0x1400022bcc0)
	/Users/ckuehl/src/aerc/lib/ui/ui.go:116 +0x248
main.main()
	/Users/ckuehl/src/aerc/aerc.go:226 +0x9e8

I'm not entirely sure what the interactions are between the terminal
emulator, aerc's grid, and the space that moves around when the tab bar
disappears because there are no more tabs, but this fixes the issue 100%
of the time and I haven't noticed any issues.

Signed-off-by: Connor Kuehl <cipkuehl@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-28 17:56:37 +02:00
Robin Jarry 8ed95b0d2a imap: avoid crash when replying to unread message
When running `:reply -q` on an unread message, aerc crashes after
opening the editor:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x5d1019]

goroutine 63 [running]:
bufio.(*Reader).fill(0xc000086ef8)
	/usr/lib/golang/src/bufio/bufio.go:106 +0xd9
bufio.(*Reader).Peek(0xc00020bef8, 0x1)
	/usr/lib/golang/src/bufio/bufio.go:144 +0x5d
github.com/emersion/go-message/textproto.ReadHeader(0xc00004a700?)
	emersion/go-message@v0.15.0/textproto/header.go:525 +0x5f
git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleFetchMessageBodyPart.func1(0xc00056e280)
	worker/imap/fetch.go:99 +0x1ab
git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleFetchMessages.func1()
	worker/imap/fetch.go:178 +0xd7
created by git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleFetchMessages
	worker/imap/fetch.go:172 +0x12b

This happens because the flags are updated in the callback that receives
the message itself. It causes the flag update to arrive in the same
channel/request. Ignore the messages that have an empty body (i.e. only
containing flag updates). This is inherently racy but there seems no way
to get rid of these extra messages.

Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Connor Kuehl <cipkuehl@gmail.com>
2022-04-28 17:55:57 +02:00
Tim Culverhouse 57699b1fa6 feat: add gpg integration
This commit adds gpg system integration. This is done through two new
packages: gpgbin, which handles the system calls and parsing; and gpg
which is mostly a copy of emersion/go-pgpmail with modifications to
interface with package gpgbin. gpg includes tests for many cases, and
by it's nature also tests package gpgbin. I separated these in case an
external dependency is ever used for the gpg sys-calls/parsing (IE we
mirror how go-pgpmail+openpgp currently are dependencies)

Two new config options are introduced:
* pgp-provider. If it is not explicitly set to "gpg", aerc will default to
it's internal pgp provider
* pgp-key-id: (Optionally) specify a key by short or long keyId

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-27 09:46:25 +02:00
Tim Culverhouse d09636ee0b refactor: refactor pgp implementation
This commit refactors the internal PGP implementation to make way for
GPG integration.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-27 09:46:11 +02:00
Tim Culverhouse afe35839ed style: add style config options for dirlist_unread and dirlist_recent
Adds two style options: dirlist_unread and dirlist_recent. These options
apply in layers, in the same way as msglist_* styles do.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-27 09:46:06 +02:00
Koni Marti 698c0957d7 pgp: ensure CRLF line endings in pgpmail reader
Ensure CRLF line endings in the pgpmail reader. Fix the pgp signature
verification for maildir and notmuch.

These backends do not return the full message body with CRLF
line endings. But the accepted OpenPGP convention is for signed data to
end with a <CR><LF> sequence (see RFC3156).

If this is not the case the signed and transmitted data are considered
not the same and thus signature verification fails.

Link: https://datatracker.ietf.org/doc/html/rfc3156

Reported-by: Tim Culverhouse <tim@timculverhouse.com>
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Tim Culverhouse <tim@timculverhouse.com>
2022-04-25 12:31:33 +02:00
kt programs 5e5d5a0d1f msgviewer: show available bindings when filter not configured
Show what command can be used to achieve the described effect so users
can add it as a binding.

Fixes: https://todo.sr.ht/~rjarry/aerc/40
Signed-off-by: kt programs <ktprograms@gmail.com>
Tested-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-25 12:31:13 +02:00
Victor Freire 8db09d2c73 config: add unsafe-accounts-conf option
This adds the option "unsafe-accounts-conf" under the section [general]
of aerc.conf. This allows an user to specify if the accounts.conf file
must be restrict to be read by the file owner (0600).

By default it is set to "false".

Signed-off-by: Victor Freire <victor@freire.dev.br>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-25 12:06:09 +02:00
Ivan Oleynikov f21916ce0a binds: fix incorrect key names for c-] and c-[
The left and right square brackets are inverted. Fix that.

Signed-off-by: Ivan Oleynikov <ivan.oleynikov95@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-25 11:22:12 +02:00
Koni Marti 25a8a00c55 filter: clear filter when called with no args
Clear filter when called with no arguments.

Fixes: https://todo.sr.ht/~rjarry/aerc/35
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-25 11:22:04 +02:00
Koni Marti ce18e92881 statusline: refactor to make it more customizable
Refactor statusline by clearly separating the rendering part from the
text display. Use printf-like format string for statusline
customization.

Document printf-like format string to customize the statusline.

Allow to completely mute the statusline (except for push notifications)
with a format specifier.

Provide a display mode with unicode icons for the status elements.

Implements: https://todo.sr.ht/~rjarry/aerc/34
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-25 11:21:07 +02:00
Kenneth Flak eb7e45d43b config: clarify threading-enabled option
This is only supported with notmuch and specific imap servers.

Signed-off-by: Kenneth Flak <kennethflak@protonmail.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-04-19 09:34:32 +02:00
Koni Marti cb887a2d9d store: keep current message selected
Keep current message selected when clearing or changing filters and when
toggling threads.

Add -s flag to the clear command to also clear the selected message and
set cursor to the top of the message list.

Implements: https://todo.sr.ht/~rjarry/aerc/36
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-17 12:18:33 +02:00
Koni Marti a34be9eb36 status: use contextual ui styleset for statusline
Use contextual ui styleset for statusline widget.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-17 12:18:29 +02:00
Koni Marti 6edfbfa8ce aerc: use contextual ui styleset for tabs/compose
Use contextual ui styleset for tabs and compose widgets. If no account
is selected, use default styleset as fallback.

Fixes: https://todo.sr.ht/~rjarry/aerc/3
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-17 12:18:22 +02:00
Jens Grassel 1ecee8efa5 Add html "unsafe" filter to work also without dante
If socksify (from dante) is not installed then the filter uses w3m
without it to render an html message part.

Signed-off-by: Jens Grassel <jens@wegtam.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-17 12:17:43 +02:00
Koni Marti 029ff63929 binds: allow to bind a command to < and >
Allow to bind to < and > by using \< and \> in binds.conf. Ensure that
the single \ can still be properly used to bind to other commands.

For example, the following binds would work now:
\< = :prev-tab<Enter>
\> = :next-tab<Enter>
\ = :filter<space>

Fixes: https://todo.sr.ht/~rjarry/aerc/37
Signed-off-by: Koni Marti <koni.marti@gmail.com>
Tested-by: Sebastian LaVine <mail@smlavine.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-17 12:16:38 +02:00
kt programs 7a7b9df763 review: show command that will be executed by binding
Also show commands that don't have a binding.
This allows users to see what's available to bind.

Signed-off-by: kt programs <ktprograms@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-14 23:59:28 +02:00
Connor Kuehl c6dae02925 main: remove unnecessary pointer dereference
Calling a method on a pointer will dereference it automatically.

Signed-off-by: Connor Kuehl <cipkuehl@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-14 23:48:28 +02:00
kt programs dc271b4da2 binds: add binding for :open by default in viewer
Also move binding for :delete such that the :open, :save, :pipe command
bindings are grouped together.

Signed-off-by: kt programs <ktprograms@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-14 23:48:26 +02:00
Tim Culverhouse 6a87d8be72 forward: allow ':forward -A' with no address
Allow using the command ':forward -A' without specifying an email
address inline.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-14 23:48:25 +02:00
Connor Kuehl fb0e9e3e41 config: don't swallow error in checkConfigPerms
os.Stat might return other errors aside from one stating that the file
does not exist. If it does, propagate the error down. As before, if the
file does not exist, just do nothing.

Signed-off-by: Connor Kuehl <cipkuehl@gmail.com>
Reviewed-by: Moritz Poldrack <moritz@poldrack.dev>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
2022-04-14 23:48:24 +02:00
Aivars Vaivods d3a10b4983 Initialization fix for dynamic folders
There is an issue with backends, that provide dynamic folders, namely
when opening folder, that isn't defined in config file, you get empty
folder. To actually get messages listed, you need to open that folder
twice.

At first attempt only DirectoryInfo is fetched and new
MessageStore created. Second attempt populates previously created
MessageStore with list of messages.

For pre-configured folders, DirectoryInfos are fetched upon connection
to backend and, when folder is opened, MessageStore is updated with list
of messages.

Fixes: https://todo.sr.ht/~rjarry/aerc/30
Signed-off-by: Aivars Vaivods <aivars@vaivods.lv>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-14 23:48:21 +02:00
Robin Jarry 02b7f74016 mk: do not depend on cmp being available
cmp is part of gnu diffutils which may not be available. Use grep which
is more widespread.

Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-04-14 21:51:09 +02:00
Robin Jarry ba892d7769 builds: add gnupg in preparation of gpg integration
This is required for future gpg unit tests to run.

Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-04-14 21:51:09 +02:00
Robin Jarry 45a7d29b06 builds: test with notmuch
This is never tested. Let's check that it compiles at least.

Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-04-14 21:28:56 +02:00
Robin Jarry 7f4069f0c5 builds: reformat yaml
Use two spaces for indentation consistently.

Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-04-14 21:28:38 +02:00
Koni Marti f6e34e4cf1 imap: fix no-envelope-for-message error
Fix the "no envelope available for this message" error that can occur
when using the same imap mailbox in another mailclient (e.g.
through a webmail interface) at the same time.

Complements the fixes in commit 7fe7fe4 ("ui: fix panic in header
formatter") and commit 074b0a1 ("view,list: fix crash when viewing
incomplete imap messages").

The error is caused when a message attribute update is received by the
message store before the message list had a chance to fetch the proper
header first. In this case, an (incomplete) message info is stored in
the message store and the message list will never fetch the correct
header. To prevent this, add only messages to the store with a non-nil
envelope but make sure that message attribute updates are properly
merged.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-11 12:06:53 +02:00
Tobias Wölfel e810ae12d7 stylesets: allow specifying color by number
Make it possible to specify the color in the style sets by number in
addition to the color name. This allows using colors defined by the
terminal.

Signed-off-by: Tobias Wölfel <tobias.woelfel@mailbox.org>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-07 12:51:09 +02:00
Moritz Poldrack 4dbdf58688 fix: out-of-bounds error in command header
This commit fixes an out-of-bound error that happened while parsing
commands.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-06 15:37:13 +02:00
Moritz Poldrack 3c08b8e6a9 header: remove trailing colon in header field
With this commit trailing colons in the :header command's field are
removed to prevent double-colon-headers from being sent.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-06 15:37:13 +02:00
Moritz Poldrack 7fe7fe4ea8 ui: fix panic in header formatter
Reported-by: noex
Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-04-06 15:37:13 +02:00