Commit Graph

43 Commits

Author SHA1 Message Date
Moritz Poldrack 9cffc45f03 go: removed io/ioutil
Since the minimum required version of Go has been bumped to 1.16, the
deprecation of io/ioutil can now be acted upon. This Commit removes the
remaining dependencies on ioutil and replaces them with their io or os
counterparts.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-22 09:30:19 +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 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 44651b43b3 checkmail: error if check-mail-cmd is not set
Send error message to UI if check-mail-cmd is required but not set.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-08-01 10:31:59 +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
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 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 f0c76fad72 threading: add backend capabilities to workers
This patch provides a method to report backend capabilities to the UI.
The intial capabilities included in the report are Sort and Thread.
Having these available to the UI enables the client to better handle
server side threading.

Signed-off-by: Koni Marti <koni.marti@gmail.com>
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-07-10 21:15:12 +02:00
Adnan Maolood c5daf43460 worker/maildir: implement Maildir++ support
See https://www.courier-mta.org/maildir.html#maildircontents

Signed-off-by: Adnan Maolood <me@adnano.co>
Acked-by: Koni Marti <koni.marti@gmail.com>
2022-07-10 20:34:47 +02:00
Tim Culverhouse af0e587976 maildir: fix dirinfo.Unseen and Exists counting
The maildir worker was adding Recent messages to the counts of Unseen
and Exists, however these messages were already included in those counts.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-14 22:12:37 +02:00
Tim Culverhouse 8b6f9719a8 dirlist: update RUE counts for imap/maildir on move|copy|delete|archive
When moving/copying/deleting/archiving a message in imap, the RUE counts
displayed in the dirlist would not update properly. Maildir has (had) an
implementation that recounts the entire directory and updates the
DirectoryInfo after one of these actions.

This patch implements a more efficient method of updating, and also
enables it to apply to IMAP without any additional requests. Upon
completion of the action, the counts are manually updated with the count
of messages in the action and recent and/or unseen states of those
messages. This is more efficient for maildir, because we aren't counting
everything in the store. For IMAP, we get the updates for free because
we are only performing the update after confirmation from the server
that the action has happened.

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-06-07 16:19:23 +02:00
Tim Culverhouse 2551dd1bfa feat: add background mail polling option for all workers
Check for new mail (recent, unseen, exists counts) with an external
command, or for imap with the STATUS command, at start or on
reconnection and every X time duration

IMAP:
The selected folder is skipped, per specification. Additional config
options are included for including/excluding folders explicitly.

Maildir/Notmuch:
An external command will be run in the background to check for new mail.
An optional timeout can be used with maildir/notmuch. Default is 10s

New account options:
check-mail
check-mail-cmd (maildir/notmuch only)
check-mail-timeout (maildir/notmuch only), default 10s
check-mail-include (IMAP only)
check-mail-exclude (IMAP only)

If unset, or set less than or equal to 0, check-mail will be ignored

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Tested-by: Moritz Poldrack <moritz@poldrack.dev>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-05-31 14:32:51 +02:00
Moritz Poldrack e30bd324a3 go vet: composite literal uses unkeyed fields
This commit fixes all occurrences of the abovementioned lint-error in
the codebase.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
Acked-by: Robin Jarry <robin@jarry.cc>
2022-03-18 13:33:16 +01:00
wagner riffel 55ae3d2cab maildir: fix data race in maildir worker
Fix a data race due dirInfo pointer being read in the main goroutine
by NewMessageStore and written in the anonymous goroutine launched in
Worker.getDirectoryInfo.

To address the issue raised in https://todo.sr.ht/~rjarry/aerc/16, we
use readdir(3) once, parse and cache its results, this replaces
go-maildir library Dir.Flags based  stat(3) and filepath.Glob
causing the issue when N (emails) is large.

Signed-off-by: wagner riffel <w@104d.net>
2022-03-07 10:01:53 +01:00
Robin Jarry 622802d3a5 maildir: defer the count of recent messages
Since commit 01c96e78df ("Update DirectoryInfo handling for maildir"),
flags are checked for every message of a folder when entering it.
Iterating over all messages of a folder takes a long time for large
collections of emails.

Only count the number of messages and state that the directory info
counts are not accurate. Defer the parsing of message flags in
a goroutine to have a more responsive UI.

Fixes: https://todo.sr.ht/~rjarry/aerc/16
Suggested-by: Koni Marti <koni.marti@gmail.com>
Signed-off-by: Robin Jarry <robin@jarry.cc>
2022-01-30 20:49:30 +01:00
Nguyễn Gia Phong bf4abd309e maildir,notmuch: pass in-memory message to callback
This fixes piped full message (:pipe -m) being empty.

Fixes: 904ffacb0e ("maildir,notmuch: avoid leaking open files")
Signed-off-by: Nguyễn Gia Phong <mcsinyx@disroot.org>
2022-01-20 15:44:46 +01:00
Nguyễn Gia Phong 904ffacb0e maildir,notmuch: avoid leaking open files
Previously, Message.NewReader returned the wrapped buffered reader
without a reference to the opened file, so the files descriptors
were left unclosed after reading.  Now, the file reader is returned
directly and closed on the call site.  Buffering is not needed here
because it is an implementation detail of go-message.

Fixes: https://todo.sr.ht/~rjarry/aerc/9
2022-01-19 20:18:00 +01:00
Robin Jarry abcd327359 maildir: watch for message renames
Messages flags can also be changed without changing directories.
Changing flags in maildirs means renaming the message files. Also take
renames into account.

Link: https://cr.yp.to/proto/maildir.html
Fixes: f4d3c8fc77 ("maildir: watch for external changes")
Signed-off-by: Robin Jarry <robin@jarry.cc>
2021-12-06 23:50:04 +01:00
Robin Jarry f4d3c8fc77 maildir: watch for external changes
When a maildir is synchronized by an external process while aerc is
running (e.g. mbsync), some emails may be moved out of "new" to "cur" or
completely deleted.

These deletions are ignored and aerc may assume these messages are still
here, leading to errors.

Take file deletions into account. Also, add "cur" to the watched
folders since these can be modified as well.

Signed-off-by: Robin Jarry <robin@jarry.cc>
2021-12-06 20:54:29 +01:00
Robin Jarry 0d645bcebd go.mod: change base git url
I'm not sure what are the implications but it seems required.

Link: https://github.com/golang/go/issues/20883
Signed-off-by: Robin Jarry <robin@jarry.cc>
2021-11-05 10:21:45 +01:00
Reto Brunner bc48628839 maildir: track the recent flag correctly
In the maildir worker we manually need to track the Recent flag in order for the
notification command etc to work.

Push that responsibility to the container, we must make sure to manually add the
flag though if one grabs the message info.
2021-11-01 13:30:45 +01:00
Reto Brunner 1687e558d3 notmuch/maildir: remove double emit of the dirinfo
There was some bug which could be worked around by double emitting an event.
However that proofed to be brittle:

We send the first message here from the worker goroutine:
https://git.sr.ht/~sircmpwn/aerc/tree/a5553438/item/worker/maildir/worker.g=
o#L306

Then Tick() is waked in the main goroutine and calls ProcessMessage:
https://git.sr.ht/~sircmpwn/aerc/tree/a5553438/item/widgets/account.go#L100

ProcessMessage in the main goroutine reads types.Message state with
msg.getId() and msg.InResponseTo():
https://git.sr.ht/~sircmpwn/aerc/tree/a5553438/item/worker/types/worker.go#=
L74-76

Meanwhile in the worker goroutine we call PostMessage for a second
time with a pointer that points to the *same* previous message that
ProcessMessage is reading:
https://git.sr.ht/~sircmpwn/aerc/tree/a5553438/item/worker/maildir/worker.g=
o#L306

The second PostMessage call makes writes to message while
ProcessMessage in the main goroutine is possibly reading:
https://git.sr.ht/~sircmpwn/aerc/tree/a5553438/item/worker/types/worker.go#=
L59

This led to a data race in the event loop

Reported-By: Wagner Riffel <w@104d.net>
2021-04-28 07:54:16 +02:00
ARaspiK fe1cabb077 Add support for :rmdir
The `:rmdir` command removes the current directory (`-f` is required if
the directory is not empty).

This is not supported on the notmuch backend.

An issue with the maildir backend is that some sync programs (e.g.
offlineimap) may recover the directory after it is deleted.  They need
to specifically be configured to accept deletions, or special commands
need to be executed (e.g. `offlineimap --delete-folder`) to properly
delete folders.

A danger of using this on the IMAP backend is that it is possible for a
new message to be added to the directory and for aerc to not show it
immediately (due to a slow connection) - using `:rmdir` at this moment
(with `-f` if the directory already contains messages) would delete the
directory and the new message that just arrived (and all other
contents).  This is documented in aerc(1) so that users are aware of
possible risks.
2020-08-19 11:38:57 +02:00
Tero Koskinen f81cc2803c maildir: Provide nicer error message on invalid url
If accounts.conf contains an invalid maildir url, return a nice
error instead of panicking.

Log a couple of different error cases to provide extra
information about the error to the user.
2020-07-27 18:26:57 +02:00
Andrew Jeffery 126c9437e8 Only send directory info once from maildir
The directory info only needs to be sent once for all the messages, this
reduces unnecessary messages being sent which could lock up the ui.
2020-07-19 11:16:05 +02:00
ARaspiK 0535f6333f Add additional flagging functionality
More mail flags can now be set, unset, and toggled, not just the
read/seen flag.

This functionality is implemented with a new `:flag` and `:unflag`
command, which are extensions to the matching `:read` and `:unread`
commands, adding support for different flags.  In fact, the
`read`/`unread` commands are now recognized aliases to `flag`/`unflag`.
The new commands are also well documented in aerc(1).

The change mostly extends the previous read/unread setting functionality
by adding a selection for the flag to change.
2020-07-08 09:13:03 +02:00
Srivathsan Murali b1eb7ad18d Set AnsweredFlag on successful reply 2020-05-25 11:29:53 -04:00
Reto Brunner fefb08f831 maildir: remove read handling from FetchMessageBodyPart 2020-05-11 09:47:21 -04:00
Jeffas 08eabef17d Count recent messages in maildir exists total too 2020-03-09 09:13:46 -04:00
Galen Abell 6ff3c7a1ba Mark sent messages as "seen" in maildir
- Add maildir flags to complement a messages imap flags
- Set the "seen" flag on sent messages when using the maildir backend
- Cleanup AppendMessage interface to use models.Flag for both IMAP and
  maildir
2020-03-03 20:08:37 +01:00
Jeffas 01c96e78df Update DirectoryInfo handling for maildir
This ensures that the directory info is up to date on events in the
maildir worker. This also sets up the initial dirinfo for other
directories and updates them when using built-in commands.

FS events are still only watched for the selected directory. This should
be changed in a future patch to watch other directories too in order to
cover UI updates for folders when an event occurs in a non-selected
folder.
2020-02-28 09:26:17 -05:00
Galen Abell 5ba1569734 Ensure new directory exists before unwatching old 2020-02-25 16:36:37 -05:00
Jeffas 90d26da58a Add sorting functionality
There is a command and config option. The criteria are a list of the
sort criterion and each can be individually reversed.

This only includes support for sorting in the maildir backend currently.
The other backends are not supported in this patch.
2019-09-20 14:56:02 -04:00
Jeffas 43435ba06c Add directory info messages
This populates the directory info model properly when requested,
allowing the fields to be relied upon elsewhere.

This also sends the dirinfo when new messages come in.
2019-09-18 19:34:30 -04:00
Jeffas c97d0d6320 Add basic searching to the maildir backend
Basic searching is supported with the following:
- read messages
- unread messages
- from addresses
- text in body
- text in subject
- text in all

The implementation loops through all messages in the selected directory.
It tries to be smart by detecting which parts of each message the search
query needs to use and only loads these from the filesystem.
2019-09-16 12:40:26 -04:00
Ben Burwell 04ccbd09b1 Clean maildirs when opened
This removes old aborted deliveries from the tmp directory.
2019-08-02 09:26:07 -04:00
Nicolai Dagestad d526786c93 Fix error handling in maildir worker 2019-07-19 17:33:33 -04:00
Reto Brunner 6fed04bb9f Register worker in init.
This allows backends which can't always be compiled due to missing
dependencies (say libnotmuch) to be compiled conditionally with buildflags.
2019-07-19 15:37:55 -04:00
Ben Burwell 6473848d87 maildir: Watch for new messages
When a directory is opened, start watching its "new" subdirectory for
incoming messages using the fsnotify library. When creation events are
detected, run the Unseen routine to move the message from new to cur and
add new UIDs to the store, updating the UI's list of directory contents
as we go.
2019-07-17 17:29:11 -04:00
Ben Burwell d15ba24a2f Implement maildir copy
Create a delivery in the destination directory with the content of the
source message.
2019-07-12 11:26:39 -04:00
Ben Burwell 1b8b6e218c Add maildir backend worker
Add the initial implementation of a backend for Maildir accounts. Much
of the functionality required is implemented in the go-message and
go-maildir libraries, so we use them as much as possible.

The maildir worker hooks into a new maildir:// URL scheme in the
accounts.conf file which points to a container of several maildir
directories. From there, the OpenDirectory, FetchDirectoryContents, etc
messages work on subdirectories. This is implemented as a Container
struct which handles mapping between the symbolic email folder names and
UIDs to the concrete directories and file names.
2019-07-12 11:09:50 -04:00