Commit Graph

1163 Commits (a8dad31776fe078fc346c7494e09dfe4cc18447f)

Author SHA1 Message Date
Manos Pitsidianakis a8dad31776
melib/imap: renamed cache module to sync
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 6513c18810
melib/imap: on sync only update exists/unseen if loaded
When resyncing with resync_basic and resync_condstore, we would update
the unseen and exists counts for the mailbox without inspecting if the
mailbox was loaded or not. Since a previous commit reset total not yet
seen to 0 when inserting new entries to mail totals, this would lead in
unloaded mailboxes go from having their original unseen counts to having
only the new envelopes in the total.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 14f2d91193
melib/backends: change RefreshEvent field decl order
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 3216324ccc
melib/mbox: impl FromStr for MboxFormat
Add a FromStr implementation so that we can parse a string into a format
value from other places in the code.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 33836a3263
melib/error: add WrapResultIntoError helper trait
Add a new WrapResultIntoError trait with method wrap_err() so we can
wrap a result and set its error as a source for a new error and
description, this allows for more descriptive error messages like:

Before:

let mbox_format = parse(some_string)?; <- error msg is "invalid mbox
format value, expected blah blah"

After:

let mbox_format = parse(some_string).wrap_err(|| "Could parse
configuration of account {}", account_name)?; <- error msg is "Could not
parse configuration of account myaccount, Caused by: invalid mbox format
value, expected blah blah"

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 20d7329263
melib: replace async-stream dep with async-fn-stream
Replace proc-macro stream impl with a non-macro one for better
compilation times

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 8e300c4661
melib/jmap: call req text(). asap
Call text() on a RequestBody as soon as it is returned, to avoid
exceeding timeout values, according to isahc documentation.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 6ae2cf0b6b
Bump version to 0.8.7
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis e329097d0b
melib/jmap: fix EmailBodyPart schema mismatch
EmailBodyPart required partId and blobId to be non-null, which is
invalid. Make them Option<_>s instead.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis f2e9cac38e
melib/jmap: use suggested minimum for maxObjectsInGet
Instead of using the actual maxObjectsInGet batch size when fetching
email, use min(maxObjectsInGet, 500). This makes things not time-out
this easily when the maxObjectsInGet is large (e.g. 4096)

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 41d07fbcef
melib/jmap: newState in EmailImportResponse cannot be null
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 52c75e92b5
melib/jmap/email.rs: use HeaderName constants
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 8b568f6e3b
melib/jmap: add if_in_state argument in Set::new()
JMAP code should be using if_in_state wherever possible, to detect
mismatch between current server state and current client state.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 46df4b573b
melib/attachments: remove unused function stub
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 85a55ed633
melib/backends: add some missing ErrorKinds to errors
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 824de287b4
melib/jmap: fix make_address! use
make_address! macro was called with a .take() expression, which was
substituted in the macro more than once hence take() would be called
more than once.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 197132cca0
melib/imap: support fetching with BODY[] for buggy servers
It appears icloud IMAP servers do not support fetching RFC822 items with
the FETCH command. They reply to the fetch successfully but with the
item missing. To support this clearly non-standard and buggy behavior,
retry one more time by fetching with BODY[] instead if the RFC822 is
missing.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 97af00cd83
melib/jmap: respect timeout value from user configuration
While the timeout value was parsed, it was only used for mutex lock
timeouts and not the http connection.

This commit sets the isahc HTTP connections timeouts using the value, if
provided.

Fixes #422

Resolves: https://git.meli-email.org/meli/meli/issues/422
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 15eeac5191
melib/jmap: enable dns_cache, tcp_keepalive & tcp_nodelay
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis afccebf331
melib/imap: add AUTH=PLAIN support
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis f5f1e06878
melib/imap: add UIDPLUS support
Add UIDPLUS extension support (Only UID EXPUNGE)

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 06437e607c
melib/LazyCountSet: set not_yet_seen to 0 when inserting existing
Not yet seen behavior is unreliable and leads to false unread counts.
Set it to 0 instead when inserting an existing count.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 96cc02a000
melib/imap/error: do not use ErrorKind::Configuration
Do not use ErrorKind::Configuration for ValidationError

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 91fdef9820
melib/imap/cache: return NotFound on cache miss
Set error kind to NotFound instead of Bug, since it is possible a
mailbox state is not cached. Also add convenience function
ignore_not_found() that converts NotFound Err Results to Ok(()).

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 86f9b213bf
melib/jmap: add `timeout` conf field in validate()
`timeout` while valid was not checked in the validate() function, so it
could not be used: the validation would reject it.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 073aef8671
Fix lints/errors when compiling specific feature combos
- Building with sqlite3 non-bundled may result in compile-time error if
  the system version is not new enough; the bindgen feature must be
  enabled to create ffi bindings from the system version.
- Some unused code warnings show up if some features are disabled,
  refactor code to make them go away.
- Update libloading to 0.8 to prevent dual dependencies in
  Cargo.lock (rusqlite's bundled feature requires it)

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 1e50911c55
melib/imap: add utils module to protocol_parser
Add utils module with parser helpers for syntax items that can be NIL

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 2429f17b44
melib/jmap: on invalid conf value, print what value is expected
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis d1499242b2
melib/error: add From<Infallible> impl
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 386208664b
melib/error: detect DNS lookup std::io::Error
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 100fa8b3d1
melib/utils: fix edge case in ShellExpandTrait
If there is no "/" prefix after stripping the argument prefix, the
result was reverted.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 39e903b1d3
melib/utils: fix issues with ShellExpandTrait
ShellExpandTrait was not expanding paths properly: tilde was expanded
even if it wasn't the first byte in the sequence. Since $HOME tends to
be an absolute path, the entire value of the path accumulator up till
that point was overwritten, meaning a /path/to/~/some/file would get
expanded to ${HOME}/some/file.

ShellExpandTrait was also not completing paths properly, especially
between the generic impl and the linux specialized one. This commit adds
test to make sure their behavior is synced and changes the result type
to an enum to make the result more descriptive.

Concerns #431.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
3 months ago
Manos Pitsidianakis 5110813e87
melib/maildir: refactor MaildirOp and watch()
Refactor to remove unwraps and add None checks with returning errors
where appropriate.

Hopefully addresses #426

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis 84d93d6555
melib/imap: add support for ID extension (opt-in)
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis af6838c20c
melib: add metadata field to MailBackendCapabilities
Add field for arbitrary metadata as a serde_json::Value.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis d40ee6928f
melib/imap: extract tests mod from protocol_parser
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis 7c47f70217
melib/sieve: extract test and parser modules to files
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis ebc1fa3b8a
melib/sieve: move module to self dir
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis e96e9789db
melib/imap: don't discard pre-auth capabilities
The library user can retrieve capabilities from a mail backend, and they
might want to see pre-auth capabilities as well.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis e3c1656e05
melib/imap: fix LOGINDISABLED support
LOGINDISABLED disables the LOGIN command, not authenticating in general;
doh! 🤦🤦🤦🤦

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis 9fb5bc41b4
melib/imap: impl AUTH=ANONYMOUS (RFC4505)
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis 1cce8c1162
melib/imap: accept invalid "+" CRLF cont req
Some servers erroneously send a "+" CRLF sequence instead of "+" SP
CRLF.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis a9e9d952d5
melib/imap: change termination_string arg to Option
Change ImapConnection::read_lines function argument termination_string
from &[u8] to Option<&[u8]>.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis 6e1fea8059
melib/jmap: show suggestions on Unauthorized error
Show suggestions for solving Unauthorized connection errors.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis f9a3b33397
melib/imap/operations: return NotFound on empty FETCH
If UID FETCH returns an OK response but without untagged fetch
responses, it means the UID was not found. Return a NotFound error in
this case and a ProtocolError in other error cases.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis 8c880dc747
melib/error: add {Error,ErrorKind}::is_recoverable()
Add methods to guess whether the error is transient and can be recovered
from.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis 7200589a9e
melib/error: add ErrorKind::NotFound
Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis 6da4e2eca6
Replace stringify! in Debug impls with type checked macro
Add identify! macro which expands to stringify! but also const type
checks the value to prevent typos/wrong values.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Manos Pitsidianakis e107d613a0
melib/backends: add prelude module for import cleanup
Add a prelude module under melib::backends that exports all types needed
to interact with a mail backend. This reduces the number of imports in
every related file.

Signed-off-by: Manos Pitsidianakis <manos@pitsidianak.is>
4 months ago
Andrei Zisu c04b593bdf
Use BODY instead of RFC822
RFC3501 seems to prefer BODY attributes as the more modern equivalent
to RFC822. For example, this also allows us to use BODY.PEEK. Since the
fetch methods in melib are tightly coupled with the parser, we have to
add this here if we want to use BODY attributes during fetch.
4 months ago