Commit Graph

1281 Commits

Author SHA1 Message Date
Oswald Buddenhagen
faec30abf4 rename SSLType => TLSType
for consistency with TLSVersions.
the variable names are unchanged to avoid churn.
2022-06-19 16:12:55 +02:00
Oswald Buddenhagen
a7f1b86475 disable TLS 1.0 & 1.1 by default
these were not reasonable defaults any more.
2022-06-19 16:12:55 +02:00
Oswald Buddenhagen
e3056b26e9 supersede SSLVersions option with TLSVersions
the new one isn't an exhaustive set anymore, but a delta to the default
(or previous setting). this has the advantage that new versions aren't
automatically disabled anymore as soon as mbsync learns about them if
the user has a setting they fail to adjust.
2022-06-19 16:12:55 +02:00
Oswald Buddenhagen
7e0e14a686 prune legacy SSL options
they have been deprecated since v1.2.
2022-06-19 16:12:55 +02:00
Oswald Buddenhagen
f7458a96d3 handle copying/trashing failures more carefully
report them as errors (not warnings), let them cause a non-zero exit
code, and in the case of trashing, prevent the subsequent expunge. the
exception are messages that just disappeared below our feet.
2022-06-19 16:12:52 +02:00
Oswald Buddenhagen
4c14123144 postpone check for cancellation in some driver callbacks
the purpose of these checks is preventing triggering more driver calls,
while immediate followups to already completed calls should be still
made.

note that some of the checks are strictly speaking redundant, as
chaining into a next phase will return immediately anyway when the
other side isn't ready yet. but we keep them for clarity.
2022-06-19 16:12:08 +02:00
Oswald Buddenhagen
f29dbb18f1 dissolve SVARS_CHECK_CANCEL_RET
it was small and used only twice, so didn't really pull its weight.
2022-06-19 16:12:08 +02:00
Oswald Buddenhagen
ffb290084a stop abusing SYNC_* for what really should be COPY_* 2022-06-19 16:12:08 +02:00
Oswald Buddenhagen
9e0efd409a prefer DECL_INIT_SVARS over DECL_SVARS+INIT_SVARS
... as a result of relying on C99+.
2022-06-19 16:12:08 +02:00
Oswald Buddenhagen
6bfffa177a make more use of SVARS_CHECK_RET{,_VARS} macro 2022-06-19 16:12:08 +02:00
Oswald Buddenhagen
4d75c45507 add --ext-exit option
this is only a partial solution for reporting changes, but it's
adequate if the goal is merely triggering a bulk action, like
re-indexing the local store.

inspired by patches posted by Yuri D'Elia <wavexx@thregr.org>.
2022-06-19 16:12:06 +02:00
Oswald Buddenhagen
edc901b7af include expunges in progress counters 2022-06-19 16:11:43 +02:00
Oswald Buddenhagen
8fbc4323f4 rate-limit progress counters
for simple local operations, they could easily dominate the cpu load.
also, over a slow remote tty, they could slow down things noticeably.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
1867a7c5ea increase timer resolution to milliseconds
seconds are too coarse for what we intend. technically, centisecs would
be sufficient (and more honest, given that we prefer coarse timers,
which have only tick precision), but that's a somewhat untypical unit.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
8566283c59 make expiration target side configurable
REFMAIL: 87k0fauw7q.fsf@wavexx.thregr.org
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
abb596709b add --dry-run mode
REFMAIL: 20211130142121.xon5oygrpdfj5s2t@fastmail.com
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
5b9256f5dc add support for incomplete headers to copy_msg_convert()
in the spirit of being liberal about what we accept.

this completely re-structures the header processing loop, with the nice
side effect of eliminating the gotos.

REFMAIL: 87bkyzhoov.fsf@curie.anarc.at
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
ed92816fdb preserve stray CRs in copy_msg_convert()
strip only CRs followed by LFs. this has mostly theoretical value (but
will make a subsequent change simpler).
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
669f7dbd8f add test for copy_msg_convert() 2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
dbffebf560 factor out ADD_NL() inside copy_msg_convert() 2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
a32964c34e factor copy_msg_convert() out to own source file 2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
46d244533e return error strings from copy_msg_convert()
... instead of reporting conversion errors directly in copy_msg_convert().
this makes it easier to autotest properly.

this reverts bc15e571 in spirit, sidestepping the problem it tried to
solve instead.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
9b72e10320 make IMAP error messages less confusing
don't print the status, as the user doesn't really care whether it's
NO or BAD. more importantly, "NO LOGIN failed" is a rather misleading
thing to report.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
3aead33008 rework IMAP list parsing
replace the "DOM-like" model with a "streaming" model, i.e., the tokens
are now immediately processed by stateful callbacks as they are found.
this avoids plenty of allocations and copies (though not of the message
contents, yet).
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
f748bd45df tweak debug output for IMAP literals
- short literals are now printed even with only -Dn.
  this ensures that we see all parts of, for example, LIST responses.
  we use xprintf() for that, so we don't mess up the -Dn output in case
  the literal contains something unexpected (we don't care with -DN).
- omitted bytes are now indicated.
- missing trailing newlines are now "pretty-printed".
- long literals are now printed in chunks as we receive them. this
  makes the output messier, but it's necessary for an upcoming change,
  and, on the upside, we'll get better indication when the transfer
  gets stuck in the middle of a message.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
80831e50b9 add xprintf()
this introduces a "commit" callback to the xprintf kernel, to avoid
pointlessly assembling a temporary output string prior to printing it.

one could lift the buffer limitations by introducing a "segment"
callback instead, but that would slow down xvasprintf() due to the
higher callback rate, for no good reason.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
0079ec774a add escaping of non-printable & non-ASCII characters to xvasprintf() 2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
57173bd289 restructure xvasprintf() for uniformity
%\\s now supports length limitations, and \\ on other format specifiers
is now ignored (like .* already was on non-strings).
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
1a89f8a178 move imap_vprintf() to util.c and rename it to xvasprintf()
it's currently used only by IMAP, but it's logically low-level.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
859b7dd7f2 try to avoid extra syscalls when reading sockets
so far we shifted down the buffered data only when we ran out of space.
however, that may cause chopping up the actual socket read, which is a
bad trade-off with avoiding a moderate-sized memmove. so try to keep
enough space for the anticipated read size.

note that this ignores the zlib path, as that always does full-size
socket reads into z_buf, and saving inflate() calls seems pointless.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
ac3b5186b0 don't notify about socket reads that fall short of expectations
this will prospectively make the debug output less messy.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
96b1e52802 make socket_read()'s interface more like socket_read_line()'s
return a pointer into the internal buffer rather than copying into a
user-supplied one. this permits zero-copy in future use cases.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
6f15980cd9 socket_read_line(): reset buffer offset when no bytes are left
socket_read() already did that.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
69653aafeb beautify socket_read_line() somewhat
- use more appropriate name for socket object
- localize some variable declarations
- denoise the code by using more local variables
- don't pointlessly do stuff when we're failing anyway
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
bc3145617a add input length argument to map_name()
... and use it when parsing IMAP LIST responses.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
5243c69863 require IMAP4rev1 capability
technically, we should have been doing that since the beginning, but as
there is IMAP4rev2 now, it might actually matter (in about a decade,
when servers start dropping backwards compat ...).
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
4a5c79993c optimize IMAP flag parsing
uppercase the reference strings and utilize already known string
lengths.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
6b9d4311d2 make IMAP parsing case insensitive
it's easy to overlook, but the spec demands this. we got away with it so
far, as everyone just uses UPPERCASE ... for the things we use so far.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
8d9c68f73a optimize string operations in IMAP parser
the string length is knowable in advance everywhere, so we can use that
for strdups and short-circuiting comparisons.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
c5e967f94d add support for LITERAL- extension
it's the same as LITERAL+, only with a strongly limited payload size.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
5048521d79 make sure that all IMAP lists are parsed
... even if we ignore their contents, as they may (hypothetically)
contain literals, which are relevant for the stream syntax.

amends 6fd4e8de2.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
a07be5f175 improve error reporting from IMAP list parsing
so far, we'd print only a generic message - except in two cases, where
the generic error would be preceded by a specific one. now we always
print a single reasonably specific message.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
c7f50a3069 simplify parsing responses with multiple IMAP lists
the callbacks took the current parsing position only to pass it on to
the next list parse. so instead, store it in the state, and have a
separate function for continuation.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
ad8520b741 revamp sending of IMAP commands with literals
include the literal's length into the command itself, so error messages
become clearer. the commands are initially built for LITERAL+, and are
"edited down" right before sending if necessary.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
abd31aad61 simplify assembly of IMAP APPEND commands
treat the date string the same as the flag string.

amends eb1f1076.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
4ae0159132 handle tagged BAD [TOOBIG] server responses
some servers consider attempts to APPEND too big messages to be BAD
commands, rather than just NO-worthy ones. so just pretend that we did
in fact get a NO, and carry on.

this was tested with gmail. if we run into servers that don't send the
expected response code, we will need to relax the condition.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
5e5c7fb508 free IMAP command's payload prior to invoking its completion callback
otherwise the synching may livelock due to failing to schedule follow-up
commands, thinking the buffers are still full. of course, this is
relevant only for commands that failed early and thus didn't free the
payload right after submission already - which will be possible only
after the next commit.
2022-06-19 16:10:57 +02:00
Oswald Buddenhagen
1225f0b86b add ExpungeSolo option
REFMAIL: CAOgBZNonT0s0b_yPs2vx81Ru3cQp5M93xpZ3syWBW-2CNoX_ow@mail.gmail.com
2022-06-19 16:10:54 +02:00
Oswald Buddenhagen
95a22739fa don't UID EXPUNGE too many messages
we didn't check that the UIDs are adjacent, so we might have caught
not fetched deleted messages between two fetched messages below the
bulk load range.

checking adjacency of UIDs would make expunges in the bulk range (which
is likely to be full of holes) rather inefficient. so we use sequence
numbers instead.

this is admittedly a rather academical fix ...

amends 18225344.
2022-06-19 16:10:01 +02:00
Oswald Buddenhagen
1631361f66 revamp handling of expunged messages
try to purge sync entries based on which messages are *actually*
expunged, rather than those that are *expected* to be expunged.

to save network bandwidth, the IMAP driver doesn't report all expunges,
so some entry purges would be delayed - potentially indefinitely, e.g.,
when only --pull-new --push is used, or Trash isn't used (nor
ExpungeSolo, prospectively). so keep a fallback path to avoid this.
2022-06-19 16:10:01 +02:00