Commit Graph

698 Commits

Author SHA1 Message Date
Oswald Buddenhagen
ec4b21535f some reshuffling in maildir_scan() for clarity 2017-01-21 11:41:12 +01:00
Oswald Buddenhagen
3d64f16702 make fetching of partial UID ranges more flexible
instead of a single hard-coded branch, use a generic method to split
ranges as needed.

this is of course entirely over-engineered as of now, but subsequent
commits will make good use of it.
2017-01-21 11:41:12 +01:00
Oswald Buddenhagen
1d3b36f89e factor out app_cr 2017-01-17 22:14:07 +01:00
Oswald Buddenhagen
3dffd68825 factor out copy_msg_convert() 2017-01-17 22:08:49 +01:00
Oswald Buddenhagen
951b7e77f8 factor out copy_msg_bytes() 2017-01-15 13:25:46 +01:00
Oswald Buddenhagen
509a191474 make more use of strnlen()
includes adding the so far superfluous prototype for the replacemnt to
common.h.
2016-12-29 15:18:39 +01:00
Oswald Buddenhagen
3eea668052 make use of memchr() in strnlen() replacement after all
turns out the comment advising against it was bogus - unlike for
memcmp(), the standard does indeed prescribe that the memchr()
implementation may not read past the first occurrence of the searched
char.
2016-12-29 15:17:04 +01:00
Oswald Buddenhagen
357dd51405 adjust return type of strnlen() replacement
it doesn't really matter, but it's nicer to stay consistent with the
official prototype.
2016-12-29 15:17:03 +01:00
Oswald Buddenhagen
67f4aeff1f standardize on 'int' for message sizes
that's what the sources already assumed anyway. size_t is total
overkill, as No Email Ever (TM) will exceed 2GiB.

this also fixes a harmless format string warning in 32 bit builds.
2016-12-29 14:10:35 +01:00
Oswald Buddenhagen
0c36655201 print actually read TUID in debug message 2016-12-26 16:20:27 +01:00
Oswald Buddenhagen
1330f43034 null-terminate lines read from state file & journal
makes the subsequent code less convoluted.
2016-12-26 16:20:27 +01:00
Oswald Buddenhagen
879eb623be mark string_list_t as packed
otherwise we'll regularly over-allocate due to the struct's stride.
2016-12-18 22:03:51 +01:00
Oswald Buddenhagen
4db64967c9 make more use of shifted_bit()
technically, this introduces a redundant AND, but the compiler is smart
enough to prove that (((A & M) ^ B) & M) == ((A ^ B) & M).
2016-12-18 22:03:51 +01:00
Oswald Buddenhagen
3b615bba3c make more use of nfstrndup() 2016-12-18 22:03:51 +01:00
Oswald Buddenhagen
22145f6674 document some additional uses for PipelineDepth 2016-12-18 22:03:51 +01:00
Oswald Buddenhagen
ab955ffe6b Merge branch '1.2'
Conflicts:
	src/drv_imap.c
2016-12-11 12:52:46 +01:00
Oswald Buddenhagen
743968737c silence bogus [-Wmaybe-uninitialized] with -O0/-O1/-Os 2016-12-11 12:51:47 +01:00
Oswald Buddenhagen
ef0e7fdd3e accept NAMESPACE responses without hierarchy delimiter
RFC2342 states that the delimiter may be NIL, which some servers
apparently actually make use of.

REFMAIL: CAM0xXk_FQ83CPrd37iQCMKtc1B2P8=u-r5jX0n2WE5Y+3483nQ@mail.gmail.com
2016-12-04 11:26:06 +01:00
Oswald Buddenhagen
03e25db3b8 validate NAMESPACE response earlier
... and don't silently fail later on.
2016-12-04 11:14:34 +01:00
Oswald Buddenhagen
1a707ab156 inform user if LOGIN was skipped because of missing SSL
'AuthMechs *' technically includes LOGIN, so it is a bit unintuitive
when it's still not used.
2016-12-03 21:17:25 +01:00
Oswald Buddenhagen
1b235d3d46 make * not match LOGIN even in non-SSL builds
this is consistent with the plain text transmission warning below.
2016-12-03 21:13:49 +01:00
Oswald Buddenhagen
fdb03b91f2 be more helpful when no SASL mechanisms are available 2016-12-03 21:13:44 +01:00
Oswald Buddenhagen
2f91e22371 fix LOGIN in SASL builds
if AuthMechs includes more than just LOGIN and the server announces any
AUTH= mechanism, we try SASL. but that can still fail to find any
suitable authentication mechanism, and we must not error out in that
case if we are supposed to fall back to LOGIN.
2016-12-03 20:58:16 +01:00
Oswald Buddenhagen
bc51d0206a fix LOGIN in non-SASL builds
specifically, if AuthMechs included more than just LOGIN (which would be
the case for '*') and the server announced any AUTH= mechanism, we'd
immediately error out upon seeing it, thus failing to actually try
LOGIN.
2016-12-03 14:32:51 +01:00
Oswald Buddenhagen
815822d81c don't arbitrarily limit UIDs to a billion
the number was chosen to make queries more comprehensible when the
server sends no UIDNEXT, but it appears that such insanely large UIDs
actually show up in the wild. so send 32-bit INT_MAX instead.

note that this is again making an assumption: that no server uses
unsigned ints for UIDs. but we can't sent UINT_MAX, as that would break
with servers which use signed ints. also, *we* use signed ints (which is
actually a clear violation of the spec).

it would be possible to special-case the range [1,inf] to 1:*, thus
entirely removing arbitrary limits. however, when the range doesn't
start at 1, we may actually get a single message instead of none due to
the imap uid range limits being unordered. this gets really nasty when
we need to issue multiple queries, as we may list the same message
twice.

a reliable way around this would be issuing a separate query to find the
actual value of UID '*', to make up for the server not sending UIDNEXT
in the first place. this would obviously imply an additional round-trip
per mailbox ...
2016-11-20 13:05:08 +01:00
Oswald Buddenhagen
2bba9b903c wrap message trashing into simple transactions
trashing many messages at once inevitably overtaxes m$ exchange, and the
connection breaks. without any progress tracking, it would restart from
scratch each time, which would lead to a) it never finishing and b) many
copies of the messages in the trash.

full transactions as we do for "proper" syncing would be over the top,
as it's not *that* bad if some messages get duplicated in the trash. so
we record only the messages for which trashing completed, thus allowing
some overlap between the attempts.
2016-11-06 09:26:16 +01:00
Oswald Buddenhagen
5b0c8cfa60 use a temporary for sanity 2016-11-05 18:16:43 +01:00
Oswald Buddenhagen
ae95490d52 pre-sort exception list passed to driver->load_box()
... and use that to optimize the maildir driver somewhat.
2016-11-05 17:32:34 +01:00
Oswald Buddenhagen
7b567164ff abstract growable arrays somewhat
... and sneak in a C99 requirement on the way. just because.
2016-11-05 17:32:34 +01:00
Oswald Buddenhagen
0f24ca31b5 fix SubFolders style Maildir++
turns out i misread the spec in a subtle way: while all other folders
are physically nested under INBOX, the IMAP view puts them at the same
(root) level. to get them shown as subfolders of INBOX, they need to
have _two_ leading dots.

this also implies that the Maildir++ mode has no use for a Path, so
reject attempts to specify one.
2016-11-05 17:32:34 +01:00
Oswald Buddenhagen
b2f6ef391b Merge branch 'isync_1_2_branch' 2016-11-05 13:16:32 +01:00
Oswald Buddenhagen
41308e4814 fix build with openssl 1.1
they finally made their structs opaque, and provided proper getters.
2016-07-24 11:58:57 +02:00
Oswald Buddenhagen
719d4a2437 prune obsolete #include
hmac.h was needed only for the cram-md5 implementation.
2016-07-24 11:58:09 +02:00
Oswald Buddenhagen
2648ef578f fix server certificate validation error reporting
use the right function to decode the error code.

found by Andrés Ramírez <sunshavi@fastmail.fm>.
2016-05-21 13:09:56 +02:00
Oswald Buddenhagen
46e792c3df improve .gitignore files
- add missing entries
- remove redundant entries which are inherited from parent dirs
- mark dirctories as such
- anchor specific files
2015-11-08 12:31:20 +01:00
Oswald Buddenhagen
7ddd8d1737 Merge branch 'isync_1_2_branch' 2015-11-08 12:04:44 +01:00
Oswald Buddenhagen
e054c575ea fix CertificateFile docs & samples
the mbsync manual says explicitly that the system's default certificate
store should *not* be specified.
however, the isync manual talked about CA certificates, which is (and
always was) exactly wrong.
also adjust both .sample rc files.
2015-11-06 22:37:58 +01:00
Oswald Buddenhagen
89dc7592ee don't crash when dns lookup fails (ipv6 path)
we call socket_connect_bail() when getaddrinfo() failed, so it must deal
with no addrinfo being there yet.
2015-09-27 12:13:34 +02:00
Oswald Buddenhagen
cda596d530 remove legacy (bsd-style) locking
flock() may be implemented via fcntl(), which may cause the process to
deadlock itself when trying to apply both types of locks. this is the
case even on linux when the file lives on NFS.

it's unlikely that anything except mbsync would try to access the
.uidvalidity files anyway, so there is no point in trying to be
compatible with anything else ...

REFMAIL: uddy4g589ym.fsf@eismej-u14.spgear.lab.emc.com
2015-09-27 11:47:45 +02:00
Oswald Buddenhagen
8bd6eb433f don't attempt to issue LOGOUT on bad stores
amends 9d22641b.
2015-09-12 11:14:46 +02:00
Oswald Buddenhagen
9a0403f446 de-duplicate cleanup of name-related data in error paths
"name" being both the ipv6 dns info and our own socket label.

sort-of amends 9d22641b.
2015-09-12 11:13:59 +02:00
Oswald Buddenhagen
682a05a676 mention safety of concurrent access; wording improvements 2015-09-07 12:35:12 +02:00
Oswald Buddenhagen
8979ebbdf2 tolerate case changes in X-TUID header name
it is legal for an email system to simply change the case of rfc2822
headers, and at least one imap server apparently does just that.
this would lead to us not finding our own header, which is obviously not
helpful.

REFMAIL: CA+fD2U3hJEszmvwBsXEpTsaWgJ2Dh373mCESM3M0kg3ZwAYjaw@mail.gmail.com
2015-09-01 15:40:54 +02:00
Anton Khirnov
167964933f add support for sending a TLS client certificate 2015-08-09 09:44:55 +02:00
Oswald Buddenhagen
17f3348ff1 make it possible to specifiy Pattern INBOX* with no Path defined
that pattern may very well expand to INBOXNOT, which would naturally
live under Path, so we need to look into the Path. of course, this
actually makes sense only if there *is* a Path, and complaining about
it being absent is backwards.
2015-05-24 14:51:31 +02:00
Oswald Buddenhagen
72c2d695ac remove support for multi-char imap path delimiters again
the idea that this is even possible was based on an incomplete reading
of the imap spec.

however, the infrastructure for supporting multi-char delimiters as such
is retained, as the Flatten option can be used with them.
2015-05-24 14:51:31 +02:00
Oswald Buddenhagen
9d22641b62 make server connection a cancellable operation
this entails splitting drv->open_store() into alloc_store() and
connect_store().
2015-05-24 14:51:31 +02:00
Oswald Buddenhagen
246c417874 validate Path earlier
we cannot know whether it will be needed later, but we can validate it
if it's set.
2015-05-24 14:51:31 +02:00
Oswald Buddenhagen
eb190d2bd5 prune dead SYNC_FAIL_ALL define 2015-05-24 14:51:31 +02:00
Oswald Buddenhagen
1aaf713ffe Merge branch 'isync_1_2_branch' 2015-05-24 14:50:01 +02:00
Oswald Buddenhagen
a3b131b6e8 don't make bogus attempts at enabling compression
recycling server connections skips everything up to setting up the
prefix (Path/NAMESPACE). "everything" should obviously include enabling
compression, as that must be done at most once per connection.
2015-05-24 14:45:50 +02:00
Oswald Buddenhagen
bcd43e2c66 Merge branch 'isync_1_2_branch'
Conflicts:
	configure.ac
	src/drv_imap.c
2015-05-09 19:31:55 +02:00
Oswald Buddenhagen
2013e50b1c rename misnamed functions concerning sending imap commands
cmd_submittable() => cmd_sendable()
cancel_submitted_imap_cmds() => cancel_sent_imap_cmds()

the sequence is exec -> submit -> send.
2015-05-09 19:25:51 +02:00
Oswald Buddenhagen
02af3f4c73 ensure direct exit after calling back
any structures may be invalid after callback invocation.

this has the side effect that the socket write callback now returns
void, like all other callbacks do.
2015-05-09 19:18:40 +02:00
Oswald Buddenhagen
6c08f568d0 fix socket_write() recursion
the synchronous writing to the socket would have typically invoked the
write callback, which would flush further commands, thus recursing.

we take the easy way out and make it fully asynchronous, i.e., no data
is sent before (re-)entering the event loop.

this also has the effect that socket_write() cannot fail any more, and
any errors will be reported asynchronously. this is consistent with
socket_read(), and produces cleaner code.

this introduces a marginal performance regression: the maildir driver is
synchronous, so all messages (which fit into memory) will be read before
any data is sent. this is not considered relevant.
2015-05-09 19:17:41 +02:00
Oswald Buddenhagen
2f7e60a3ed fix #ifdefs around AuthMech & RequireCRAM
these options don't depend on HAVE_LIBSSL.
2015-05-09 18:57:30 +02:00
Oswald Buddenhagen
16aa17053d mask AUTHENTICATE PLAIN commands in error output as well
amends bd0f3af5.
2015-05-09 18:57:30 +02:00
Oswald Buddenhagen
b8d6d833c6 add DisableExtension option to work around (server) bugs 2015-05-08 10:20:09 +02:00
Oswald Buddenhagen
549e6739e8 support verbatim and real Maildir++ subfolder naming styles
the legacy style is a poorly executed attempt at Maildir++, so introduce
the latter for the sake of completeness. but most users will probably
just want to use subfolders without any additional dots.
2015-05-01 20:53:23 +02:00
Oswald Buddenhagen
064f579a92 make maildir_list_recurse() recursion less convoluted
move the unconditional addition of INBOX out ouf the function.
this makes it possible to move the folder check and addition to the
listing before the recursion, which seems clearer.
2015-05-01 20:51:32 +02:00
Oswald Buddenhagen
da9adcc4bd pass a maildir_store_conf_t to maildir_validate_path()
casting early on makes the code clearer.
2015-05-01 20:51:32 +02:00
Oswald Buddenhagen
3de60c8f5c make flags in pattern debugging non-cumulative 2015-05-01 20:51:32 +02:00
Oswald Buddenhagen
ea9f4f0b96 use \fB and \fI consistently, take 2
\fB means literal, while \fI means placeholder, value for placeholder,
or emphasis.
2015-05-01 18:53:08 +02:00
Oswald Buddenhagen
a041766140 Merge branch 'isync_1_2_branch' 2015-04-26 20:59:11 +02:00
Oswald Buddenhagen
b85153f8eb make skipping of failed stores more thorough
in the case of imap stores, the failure is bound to the server config,
not just the store config.

that means that the storage of the failure state needs to be private to
the driver, accessible only through a function.
2015-04-26 20:58:43 +02:00
Oswald Buddenhagen
1eb88d4fea add socket timeout handling 2015-04-26 20:58:22 +02:00
Oswald Buddenhagen
5c4015aee5 remove caching of current time
it's too hard to reliably predict when invalidation will be necessary.
2015-04-26 18:41:32 +02:00
Oswald Buddenhagen
e0171b71e7 don't get system time when dealing with null timers
they fire immediately regardless of wall time, so we can save some
pointless syscalls.
2015-04-26 18:41:32 +02:00
Oswald Buddenhagen
ac7cd86c73 fix -DN not implying -Dn 2015-04-26 18:39:09 +02:00
Oswald Buddenhagen
98bd2b115d make it possible to nest maildir Path under Inbox
simply make the code symmetrical to the inverse case.

note that the result will be sort of awkward, as the folders under Path
(and thus the subfolders of Inbox) don't start with a dot, while the
subfolders of these folders do. this needs to be addressed separately.
2015-04-18 12:01:35 +02:00
Oswald Buddenhagen
2d4ce72a8b make handling of Inbox-in-Path nesting less obfuscated
when we run into Inbox while listing Path, check whether Inbox is being
listed anyway, and just skip it if so, instead of listing it right away
and resetting LIST_INBOX (and thus having a calling order dependency).
2015-04-18 11:58:05 +02:00
Oswald Buddenhagen
41ed101224 don't list IMAP Path under INBOX twice
if NAMESPACE is "INBOX.", listing INBOX recursively will already include
it.

REFMAIL: 1890363108.1020695.1428757117731.JavaMail.yahoo@mail.yahoo.com
2015-04-18 10:54:00 +02:00
Oswald Buddenhagen
83eaac8787 fix uninitialized variable warning
the returned UID is not used when trashing messages, but we still
shouldn't just return an undefined value.
2015-04-13 09:20:09 +02:00
Reimar Döffinger
08dab9465b Make Berkley DB an optional dependency.
It doesn't seem necessary for any of the basic functionality.

Signed-off-by: Reimar Döffinger <Reimar.Doeffinger@gmx.de>
2015-04-13 09:19:02 +02:00
Oswald Buddenhagen
8dc776c528 fix SASL, take 2
USER (the authorization identity) specifies whom to act for.
AUTHNAME (the authentication identity) specifies who is acting (and
thus whose PASS is being used).
USER is derived from AUTHNAME if omitted, but apparently the
GSS-API module automatically adds the REALM, which is not helpful.

it appears to be common to set both USER and AUTHNAME to the same value,
so let's just do it as well.

REFMAIL: 20150407194807.GA1714@leeloo.kyriasis.com
2015-04-09 10:33:51 +02:00
Dmitrij D. Czarkoff
0840026a4b fix crash in maildir_set_msg_flags()
memcpy(3)'s behavior is undefined when source and destination addresses
overlap, and it actually crashed on OpenBSD. use memmove() instead.
2015-04-04 10:46:14 +02:00
Oswald Buddenhagen
95276cd967 don't insert unnecessary linebreaks upon PassCmd invocation
the PassCmd will be typically non-interactive (or it will use a gui
password agent), so starting a new line just makes the progress counter
uglier. so make it configurable and default to no line break.
2015-03-30 14:52:02 +02:00
Oswald Buddenhagen
ba2b42ec9b fix crash when no mailboxes match Patterns
filter_boxes() just returns a null pointer in this case.

REFMAIL: 20150330121211.GA10315@venus.fritz.box
2015-03-30 14:27:23 +02:00
Oswald Buddenhagen
138983c91e fix SASL PLAIN for User != $USER
REFMAIL: 87d29mysnx.fsf@ericabrahamsen.net
2015-03-30 12:59:40 +02:00
Oswald Buddenhagen
03a124051f add debugging for main()
so far, that's mostly mailbox listing
2015-03-30 10:31:59 +02:00
Oswald Buddenhagen
0e1f8f9a3f revamp console output options
- the old meaning of -V[V] was moved to -D{n|N}, as these are really
  debugging options.
- don't print the info messages by default; this can be re-enabled with
  the -V switch, and is implied by most debug options (it was really
  kind of stupid that verbose/debug operation disabled these).
- the sync algo/state debugging can be separately enabled with -Ds now.
2015-03-30 10:31:26 +02:00
Oswald Buddenhagen
8aa22a62e7 make progress counters global
which means they are now cumulative, and include channels and boxes.
2015-03-30 10:30:35 +02:00
Oswald Buddenhagen
1de3ecd883 pre-calculate channel and box lists (as far as possible)
... instead of determining them on the fly, because
- it enables early display of totals (to be used soon)
- it enables re-use of the data (to be used at some point)
- the code is less cryptic

note that we leak the data created in main(), consistently with other
configuration-related data.
2015-03-28 17:56:10 +01:00
Oswald Buddenhagen
f361738ad2 don't claim that INBOX is absent even if it was not listed
IMAP defines that INBOX is always present.
2015-03-28 17:56:10 +01:00
Oswald Buddenhagen
05deb008db rework Pattern application
instead of creating three lists of mailboxes (common, master, slave)
and deriving the mailbox presence from the list being processed, create
a single joined list which contains the presence information.
additionally, the list is sorted alphabetically (with INBOX first),
which is neater.
2015-03-28 17:56:10 +01:00
Oswald Buddenhagen
e00d0f1ac3 static my_strndup() => extern nfstrndup() 2015-03-28 17:56:10 +01:00
Oswald Buddenhagen
4d638c3cf2 make sure that INBOX always exists
makes the Maildir driver consistent with IMAP.
2015-03-28 17:56:10 +01:00
Oswald Buddenhagen
d8225390fc don't refuse to strip Path just because it's INBOX/
no ambiguity can result from this, so there is no reason to treat
sub-folders of INBOX differently from any other namespace.
2015-03-28 17:56:10 +01:00
Oswald Buddenhagen
bd0f3af578 mask AUTHENTICATE PLAIN commands in debug output
they are almost as bad as LOGIN.
2015-03-28 17:56:08 +01:00
Oswald Buddenhagen
06c1a43aa2 remove double "Logging in ..." when using legacy LOGIN 2015-03-28 17:56:08 +01:00
Oswald Buddenhagen
c333a36aee Merge branch 'isync_1_1_branch' 2015-03-28 17:54:23 +01:00
Oswald Buddenhagen
ee8b835c55 fix out-of-Path INBOX never being matched by Patterns
"(null)I" really doesn't cut it.

amends cf0f32f8.
2015-03-23 19:03:16 +01:00
Oswald Buddenhagen
c0ba6f0395 escape backslashes in PassCmd examples
the config parser strips one level of backslash escapes.
2015-03-22 11:44:33 +01:00
Oswald Buddenhagen
4842f5148d fix bogus "unexpected command continuation request"
it helps if the code actually does what the comment above it claims.
clarify it a bit, so i don't get stupid ideas again.

This reverts commit cf6a7b4d18.
2015-03-21 12:30:42 +01:00
Oswald Buddenhagen
1701e3d84f fix chaining of COMPRESS invocation
it was bound to the use of NAMESPACE, which made no sense at all.
2015-03-07 17:46:41 +01:00
Oswald Buddenhagen
a8b26dc4ac soft-limit peak memory usage
propagating many messages from a fast store (typically maildir or a
local IMAP server) to a slow asynchronous store could cause gigabytes of
data being buffered. avoid this by throttling fetches if the target
context reports memory usage above a configurable limit.

REFMAIL: 9737edb14457c71af4ed156c1be0ae59@mpcjanssen.nl
2015-02-15 18:13:05 +01:00
Oswald Buddenhagen
4b31522fdf complain about excess values supplied to options 2015-02-15 12:48:46 +01:00
Oswald Buddenhagen
d4392c9220 handle clean SSL connection shutdowns
some servers actually bother to close down the SSL connection before
closing the socket.

this fixes the spurious "unhandled SSL error 6" messages.

REFMAIL: 20150120114805.GA17586@leeloo.kyriasis.com
2015-02-15 12:19:47 +01:00
Oswald Buddenhagen
9e15ab4a5a refactor socket EOF handling
handling EOF already at the socket level isn't a very good idea - it
breaks the abstraction, and makes implementing sane semantics hard.
2015-02-15 12:15:46 +01:00
Oswald Buddenhagen
13c742529c fix crash on shutdown of compressed connection
the callback may destroy the socket, so it is very unwise to use it for
buffering the return value. use a temporary instead.
2015-02-15 11:49:58 +01:00
Oswald Buddenhagen
c9b8cefc29 handle clean shutdown of zlib stream
the server can actually close the zlib stream before closing the socket,
so we need to accept it.

we don't do anything beyond that - the actual EOF will be signaled by
the socket, and if the server (erroneously) sends more data, zlib will
tell us about it.

REFMAIL: 1423048708-975-1-git-send-email-alex.bennee@linaro.org
2015-02-15 11:49:58 +01:00
Oswald Buddenhagen
ef70bd4a40 don't try to flush if there is nothing to flush
zlib reports Z_BUF_ERROR when a flush is attempted without any activity
since the previous flush (if any). while this is harmless as such,
discerning the condition from genuine errors would be much harder than
avoiding the pointless flush in the first place.

REFMAIL: eb5681612f17be777bc8d138d31dd6d6@mpcjanssen.nl
2015-02-15 11:49:58 +01:00
Oswald Buddenhagen
f4240761f1 introduce and use pending_wakeup()
so we don't need to peek into internal data structures.
2015-02-15 11:49:52 +01:00
Oswald Buddenhagen
74c78c70b9 deal sensibly with permanent errors
don't retry dead Stores for every Channel.

this also introduces a state for transient errors (specifically, connect
failures), but this is currently unused.
2015-01-17 17:51:20 +01:00
Oswald Buddenhagen
5f265ad7da unify .isyncuidmap.db handling with that of .uidvalidity
that is, open the database on demand when locking and close it again
when unlocking.
2015-01-17 17:51:20 +01:00
Oswald Buddenhagen
4da89af7be refactor maildir_set_uid() and maildir_store_uidval()
the latter now handles both the db and the plaintext file, so the former
can make use of it.
2015-01-17 17:51:20 +01:00
Oswald Buddenhagen
f61efdbb9d rename some *uid*() => *uidval*() to better reflect their function 2015-01-17 17:51:20 +01:00
Oswald Buddenhagen
2eece82276 lock .uidvalidity on demand
a maildir re-scan doesn't need to lock it if it doesn't need to allocate
any new uids.
2015-01-17 17:51:20 +01:00
Oswald Buddenhagen
4aad8c9e04 delay unlocking of .uidvalidity
it's wasteful to re-lock all the time. instead, unlock in the background
after 1-2 seconds of inactivity.
2015-01-17 17:51:20 +01:00
Oswald Buddenhagen
d9a983add6 add support for propagating folder deletions 2015-01-17 17:51:20 +01:00
Oswald Buddenhagen
a7eddc6ede don't make intermediate directories proper maildirs
"phantom" mailboxes waste time on syncing. furthermore, mutt's mailbox
navigator provides no means to enter subfolders of maildirs.
2015-01-17 17:51:20 +01:00
Oswald Buddenhagen
7489ff8613 deal sensibly with incomplete maildir directories
a directory is no mailbox unless it contains a cur/ subdir.
but if that one is present, create new/ and tmp/ if they are missing.

this makes it possible to resume interrupted maildir creations.
2015-01-17 17:51:19 +01:00
Oswald Buddenhagen
5f4e3b285e factor out maildir_clear_tmp() 2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
926788f3ae supplement open_box() with box existence information from list_store()
there is no point in trying to open a non-existing box before trying to
create it.
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
7b7304b625 split create_box() off from open_box()
this allows us to do something else than creating missing boxes
depending on circumstances. hypothetically, that is.
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
f1809ddd2b open the mailboxes after loading the sync state
this allows us to react differently to a box'es absence depending on the
state. hypothetically, so far.
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
f43617cd94 lock sync state lazily
don't try to lock it until we actually read or write it.
the idea is to not fail with SyncState * if we tried to load the state
before selecting a non-existing mailbox. this is ok, because if the
mailbox is missing, we obviously have no sync state pertaining to it,
either.
as a side effect, this allows simplifying an error path.
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
fb19d644f7 split off open_box() from select_box()
aka prepare_paths() reloaded. we'll need it in a moment.
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
97a42cd825 factor out {prepare,lock,save,load}_state() 2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
5af1796777 de-duplicate handling of box operation (create & expunge) options
loops work just fine ...
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
9982e7bf08 make some driver function names more descriptive 2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
00ebf45be2 rename driver::prepare_opts() => prepare_load()
... and move it to the right place in the structure and fix the doc to
not claim that it is called before select().
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
bac2b00f1b disable use of LITERAL+ for payloads > 100k
when LITERAL+ is used, the server has no chance for early rejection of
messages. this means that the client can upload megabytes for nothing.
so simply don't use LITERAL+ for big messages. of course this adds
server roundtrips, but that's tough luck.

the limit could be arguably higher than 100k (or even configurable).
i set it to ~2 sec with my fairly average DSL line.
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
6c959c3ee4 fix handling of unsolicited BYE responses
they can come in at any time, after which we must expect the connection
to be closed (and not complain about it).
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
4f3ef54f3a fix treatment of untagged NO and BAD responses
they aren't possible greeting responses. however, they are warning resp.
error reports from the server, so print them accordingly.
2015-01-11 15:05:29 +01:00
Oswald Buddenhagen
139b90be29 added support for IMAP DEFLATE
initial patch by Jesse Weaver <pianohacker@gmail.com>, but mostly
rewritten by me.
2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
f0b80e7d35 make socket writing buffered
the primary objective is reducing the number of small SSL packets (which
are always padded), but fewer syscalls in the non-SSL case should be
good as well.
2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
efb23ab96a vectorize socket_write()
the objective is making the buffer code aware of the total size of a
write in advance. this commit doesn't take advantage of that yet.
2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
3f629af07e remove support for faking notifications
with the existence of timers, this is now superfluous.
2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
a4e2f1a60d use null timer instead of faking a socket notification 2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
7b76d9ff7e add timers to mainloop
they are called "wakeups", though, as timer_t already exists in time.h.
2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
1fd66195d8 change socket notifier design
instead of keeping the structures in an opaque array (which was a shadow
of the struct pollfd array if poll() was supported), make them directly
addressable.

this has the advantage that notifier-altering operations (mostly
en-/disabling) don't need to look up the structure by file handle each
time.
on the downside, data locality in the main loop is worse.
neither of these have any real effect on performance.

note that the structures are not allocated separately, but embedded into
the the parent structure (like sockets already were).
2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
f68e021b90 factor out socket_open_internal() 2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
42cedc8f81 introduce uchar, ushort & uint typedefs 2015-01-11 15:05:28 +01:00
Oswald Buddenhagen
b730f66f7d Merge branch 'isync_1_1_branch' into HEAD
Conflicts:
	src/socket.c
2015-01-11 14:32:15 +01:00
Oswald Buddenhagen
2fa75cf159 fix UID assignment with some non-UIDPLUS servers
the seznam.cz IMAP server seems very eager to send UIDNEXT responses
despite not supporting UIDPLUS. this doesn't appear to be a particularly
sensible combination, but it's valid nonetheless.

however, that means that we need to save the UIDNEXT value before we
start storing messages, lest imap_find_new_msgs() will simply overlook
them. we do that outside the driver, in an already present field - this
actually makes the main path more consistent with the journal recovery
path.

analysis by Tomas Tintera <trosos@seznam.cz>.

REFMAIL: 20141220215032.GA10115@kyvadlo.trosos.seznam.cz
2015-01-11 14:29:19 +01:00
Oswald Buddenhagen
958af473a0 fix conditional for early failure in cancel_done() 2015-01-02 12:38:48 +01:00
Oswald Buddenhagen
9eba3d8cd9 don't leave 2nd store in limbo if opening 1st store fails synchronously
we can't leave the store FRESH, as otherwise the error handling code
will assume it is still being opened and will return to the main loop.
depending on the config this would cause an immediate termination or an
indefinite wait.
2015-01-02 11:29:51 +01:00
Oswald Buddenhagen
3db3f4718e remove stray CRLF from AUTHENTICATE continuations
this re-introduces 6741bc94 (just a bit differently), thus effectively
reverting fbfcfea5. i suppose this extra CRLF is needed by a broken
CRAM-MD5 implementation of some server, which is why it was there in the
original implementation as well. however, it breaks more pedantic
non-broken servers. if somebody complains, we'll need to add a much
more sophisticated hack.
2014-12-29 02:30:33 +01:00
Oswald Buddenhagen
518b5630dc cleanup dead cram() prototype 2014-12-29 02:30:33 +01:00
Oswald Buddenhagen
5dfca41422 fix more memcmp() abuse
amends 1217193fb and 4f383a807.
2014-12-29 02:30:01 +01:00
Oswald Buddenhagen
6f7d416bb8 fix acceptance of trusted SSL certs
we should make no assumptions about the layout of OpenSSL's certificate
store, in particular when they are wrong. so copy the interesting part
instead of "deep-linking" into it.

this code is uglier than it should be, but OpenSSL's extensive use of
macros to manage data types would force us to include the ssl headers
into our headers otherwise, which would be even uglier.

REFMAIL: <545442CC.9020400@nodivisions.com>
2014-11-08 14:00:28 +01:00
Oswald Buddenhagen
f377e7b696 introduce FieldDelimiter and InfoDelimiter options
... for windows fs compatibility.

the maildir-specific InfoDelimiter inherits the global FieldDelimiter
(which affects SyncState), based on the assumption that if the sync
state is on a windows FS, the mailboxes certainly will be as well, while
the inverse is not necessarily true (when running on unix, anyway).

REFMAIL: <CA+m_8J1ynqAjHRJagvKt9sb31yz047Q7NH-ODRmHOKyfru8vtA@mail.gmail.com>
2014-10-25 17:42:48 +02:00
Oswald Buddenhagen
85fd5ceb54 move orig_name out of store_t
it's state specific to the synchronizer.
2014-10-25 15:06:50 +02:00
Oswald Buddenhagen
7ee0483436 nuke home-grown CRAM-MD5 support
it was obsoleted by SASL support.
i deem the additional dependency acceptable when one wants the feature.
2014-10-20 10:10:55 +02:00
Oswald Buddenhagen
eb1005151c add SASL support
patch initially by Jack Stone <jwjstone@fastmail.fm>,
cleaned up by Jan Synacek <jsynacek@redhat.com>,
... and then almost completely rewritten by me. ^^
2014-10-20 10:10:55 +02:00
Oswald Buddenhagen
360600b98d factor out ensure_user() and ensure_password() 2014-10-18 16:18:48 +02:00
Oswald Buddenhagen
1217193fbb rework authentication mechanism configuration
RequireCRAM (another fairly stupid "use if available" option) is now
deprecated. instead, the AuthMech option can be used to give a precise
list of acceptable authentication mechanisms (which is currently "a bit"
short). in particular, this allows *not* using CRAM-MD5 even if it's
available.
2014-10-18 16:18:48 +02:00
Oswald Buddenhagen
aba3524d9b make it possible to disable usage of system cert store 2014-10-18 16:18:48 +02:00
Oswald Buddenhagen
7822bd8a91 require Host if SSL is used despite Tunnel 2014-10-18 16:18:48 +02:00