Commit Graph
100 Commits
Author SHA1 Message Date
link2xt a8cf05ea5d accounts: retry remove_account multiple times on failure
When removing an account, try 60 times with 1 second sleep in between
in case removal of database files fails. This happens on Windows
platform sometimes due to a known bug in r2d2 which may result in 30
seconds delay until all connections are closed [1].

[1] https://github.com/sfackler/r2d2/issues/99
2022-04-19 14:14:38 +02:00
link2xt a63464765c dc_receive_imf: remove Received: based draft detection heuristic
Proper draft detection was implemented in
bf7f64d50b

Removing this heuristic also removes the need to pass IMAP folder name
around.
2022-04-17 00:00:00 +00:00
link2xt e9fe8ce118 Merge branch 'markseen-imap-loop' 2022-04-17 17:55:25 +03:00
link2xt 1fa892c239 Rename store_seen_flags into store_seen_flags_on_imap 2022-04-17 14:55:10 +00:00
link2xt 1afbbbc737 Rename markseen_on_imap to markseen_on_imap_table and document it 2022-04-17 11:56:48 +00:00
link2xt 66c4de2607 Mark messages as seen in IMAP loop
MarkseenMsgOnImap job, that was responsible for marking messages as
seen on IMAP and sending MDNs, has been removed.

Messages waiting to be marked as seen are now stored in a
single-column imap_markseen table consisting of foreign keys pointing
to corresponding imap table records.

Messages are marked as seen in batches in the inbox loop. UIDs are
grouped by folders to reduce the number of requests, including folder
selection requests. UID grouping logic has been factored out of
move_delete_messages into UidGrouper iterator to avoid code duplication.

Messages are marked as seen right before fetching from the inbox
folder. This ensures that even if new messages arrive into inbox while
the connection has another folder selected to mark messages there, all
messages are fetched before going IDLE. Ideally marking messages as
seen should be done after fetching and moving, as it is a low-priority
task, but this requires skipping IDLE if UIDNEXT has advanced since
previous time inbox has been selected. This is outside of the scope of
this change.

MDNs are now queued independently of marking the messages as seen.
SendMdn job is created directly rather than after marking the message
as seen on IMAP. Previously sending MDNs was done in MarkseenMsgOnImap
avoid duplicate MDN sending by setting $MDNSent flag together with
\Seen flag and skipping MDN sending if the flag is already set. This
is not the case anymore as $MDNSent flag support has been removed in
9c077c98cd and duplicate MDN sending in
multi-device case is avoided by synchronizing Seen status since
833e5f46cc as long as the server
supports CONDSTORE extension.
2022-04-17 09:50:04 +00:00
link2xt 213e67dea2 Merge branch 'faster_fetch' 2022-04-17 09:47:42 +00:00
link2xt 86c884fe1e Update the comment before delete_expired_imap_messages 2022-04-17 09:47:17 +00:00
link2xt 14ab3c8651 Remove unused stop-token dependency
stop-token 0.2.0 is required by async-imap. This Cargo.toml entry
additionally pulled in unused stop-token 0.7.0.
2022-04-16 11:24:23 +00:00
link2xt f75f8ad76d Interrupt ephemeral loop when new messages are fetched 2022-04-12 22:26:44 +00:00
link2xt 574b78cf31 Interrupt ephemeral loop when delete_device_after is set 2022-04-12 22:26:44 +00:00
link2xt 92f0e8472b Take delete_device_after into account when calculating ephemeral loop timeout 2022-04-12 22:26:44 +00:00
link2xt 26c38070ec Disable unused async-smtp transports
By default file and sendmail transports are enabled,
but deltachat does not use them.
2022-04-09 11:36:32 +00:00
link2xt 494a7f1db9 Update to Rust 1.60
It re-enables incremental compilation.
2022-04-09 09:10:51 +00:00
link2xt de91063fbe scheduler: add comment about fake-idle timeout 2022-04-03 19:30:56 +00:00
link2xt 3d95272707 smtp: retry message sending automatically if loop is not interrupted 2022-04-03 18:55:29 +00:00
link2xt a8ab7c9c04 smtp: do not try to use stale connections
Previously first try used an old connection and. If using stale
connection, an immediate retry was performed using a new connection.

Now if connection is stale, it is closed immediately without trying to
use it.

This should reduce the delay in cases when old connection is unusable.
2022-04-03 13:11:27 +00:00
link2xt 332892b468 ephemeral: clear more fields in delete_expired_messages
These fields are cleared in other places,
but in the case of delete_device_after setting
only txt column was cleared previously.
2022-04-02 17:10:09 +00:00
link2xt 6392300311 job: remove unnecessary anyhow::Error import 2022-04-02 17:06:22 +00:00
link2xt 8c2b9f9901 Do not overwrite better_msg if apply_group_changes returns None 2022-03-27 11:23:45 +00:00
link2xt e9a733a789 Pass better message around instead of mutating mimeparser
This change is aimed at decoupling parsing and
add_parts() stages to eventually separate parsing
from database changes and pipeline message parsing and
decryption.
2022-03-27 11:23:45 +00:00
link2xt 33ba8dabe0 Increase python test timeout 2022-03-27 08:48:43 +00:00
link2xt 0842e54f52 Add ephemeral_timestamp index for msgs table
This reduced get_chat_msgs() benchmark time from 400ms to 170ms.
2022-03-26 20:19:49 +00:00
link2xt 08d34e41c6 Return results from add_parts() via structure
Replaced mutable out parameters with explicit return of structure.
Also moved all decisions about emitted events out of add_parts(). Chat
ID is removed from created_db_entries as it is the same for all parts.
2022-03-26 16:38:08 +00:00
link2xt 26ae8accd4 Automatically unblock chats with outgoing messages 2022-03-20 18:03:10 +00:00
link2xt 7d26968bb3 Try to start ephemeral timers only if some message has nonzero timer 2022-03-20 18:12:01 +00:00
link2xt 83464a882e Optimize markseen_msgs
Use a single SELECT statement for all messages
and start ephemeral timers for all messages at once.
2022-03-20 14:57:14 +00:00
link2xt a3ba19db96 Resultify delete_poi_location() 2022-03-19 17:29:54 +00:00
link2xt d9e9c849e1 imap: do not delete duplicates
Currently if user moves the message into some other folder and then
moves the message back, the message is considered duplicate even
though previous copy was already deleted. This is a common problem
reported by users at least twice.

Keeping duplicates does no harm except for additional storage usage.
If the message is later deleted by the user, all the copies on the
server will be deleted. anyway.
2022-03-19 15:51:17 +00:00
link2xt a997322efb Update MSRV to 1.56 and current version to 1.59
This is needed to support Rust 2021 edition required by the latest versions of `ed25519` and `image` crates.
2022-03-16 10:56:16 +01:00
link2xt 2012833cb3 Fix lint 2022-03-12 20:07:00 +00:00
link2xt e48eef7e32 Start ephemeral timer when seen status is synchronized via imap 2022-03-12 19:28:31 +00:00
link2xt f28fcec81d imap: do not treat messages without Message-ID as duplicates
Message-IDs are now retrieved only during fetching and saved into imap
table. dc_receive_imf_inner does not attempt to extract the Message-ID
anymore.

For messages without Message-ID the ID is now generated in
imap::fetch_new_messages rather than dc_receive_imf_inner,
so the same ID is used in the imap table (maintained by the imap
module) and msgs table (maintained by dc_receive_imf module).

Message-ID generation based on the Date, From and To field hashing has
been replaced with a simple dc_create_id() to avoid retrieving Date,
From, and To fields in the imap module, as it's hard to test that it
stays compatible between Delta Chat versions in this module. This
breaks jump-to-quote for quoted messages without Message-ID, which is
not critical.

Also prefetch X-Microsoft-Original-Message-ID, so retrieval of
duplicate messages with X-Microsoft-Original-Message-ID can be skipped
like it is done for messages with Message-ID header.
2022-03-08 15:23:22 +00:00
link2xt 368f27ffbc Update rusqlite to stable version 2022-02-27 20:00:35 +00:00
link2xt 0e50bc1443 Fix 1.59 clippy warnings 2022-02-27 13:29:02 +00:00
link2xt 7ab6d95b6c mimefactory: place common IMF headers at the top of the message
This moves most common headers like From, To, Subject etc. defined in
the Internet Message Format standard at the top of the message
in the same order as used in RFC 5322.
2022-02-23 17:51:15 +00:00
link2xt 6c32b89906 smtp: add more logging 2022-02-23 17:04:30 +00:00
link2xt 36bce6c468 Remove unused async-std feature 2022-02-19 11:30:48 +00:00
link2xt d708f386a1 smtp: set message state to failed when retry limit is exceeded 2022-02-13 08:59:52 +00:00
link2xt 0f837f4bed Fix a comment typo 2022-02-12 16:29:42 +00:00
link2xt 242e8e2bb3 smtp: remove the message in case of permanent failure
When `smtp_send` returns `Status::Finished`,
the message should be removed from the queue even in case of
failure, such as a permanent error.

In addition to this bugfix, move the retry count increase to
the beginning of `send_msg_to_smtp` to ensure no message is
retried infinitely even in case of similar bugs.
2022-02-12 16:20:13 +00:00
link2xt 1d56b24b67 cargo update 2022-02-12 16:19:44 +00:00
link2xt 6c6d47c89c Fix CI
timeout_func_only makes pytest-rerunfailures work with pytest-timeout,
but it only works with default timeout_method.

See pytest-rerunfailures issue for details:
https://github.com/pytest-dev/pytest-rerunfailures/issues/99
2022-02-08 20:50:11 +00:00
link2xt 196075c031 imap: batch message deletion 2022-02-06 11:42:30 +00:00
link2xt 2e5e8f73c6 imap: simplify get_quota_roots() 2022-02-06 15:17:05 +00:00
link2xt ada5d38272 imap: remove unwrap() 2022-02-06 14:07:04 +00:00
link2xt c4b0f773db python: remove arbitrary timeouts from tests
pytest-timeout already handles all deadlocks and is configurable with
--timeout option. With this change it is possible to disable timeout
with --timeout 0 to run tests on extremely slow connections.
2022-02-06 12:52:48 +00:00
link2xt 276daf631e imap: move messages in batches
Also change how NO response is treated. NO response means there is an
error moving/copying the messages. When there are no matching
messages, the response is "OK No matching messages, so nothing copied"
according to some RFC 9051 examples.
2022-02-05 22:15:46 +00:00
link2xt fb19b58147 Reduce number of unsafe as conversions
Enable clippy::cast_lossless lint and get rid of
some conversions pointed out by  clippy::as_conversions.
2022-02-05 12:42:14 +00:00
link2xt cccdc51ad4 Optimize delete_expired_imap_messages()
For me this reduced query time from 0.3 s to 0.05 s.
2022-01-31 20:34:01 +00:00
link2xt f68088cfb5 imap: avoid reconnection loop when message without Message-ID is marked as seen
- do not attempt to mark reserved meessages as seen when
  messages with empty Message-ID are marked as seen on IMAP
- do not reconnect on Seen flag synchronization failures This avoid
  reconnection loops in case of permanent errors in `sync_seen_flags`
2022-01-31 00:00:00 +00:00
link2xt f304a30193 imap: fetch Inbox before scanning other folders 2022-01-31 12:03:21 +01:00
link2xt 7eadca3959 imap: do not synchronize Seen flags on unwatched folders
Synchronizing seen flags doubles the time required to scan all
folders. Delta Chat only marks messages as Seen on Inbox or DeltaChat,
so there is no need to check for Seen flag on other folders.
2022-01-30 20:00:00 +00:00
link2xt 8aa6decbf9 imap: call delete_expired_imap_messages() less often
This operation takes roughly 0.3 s on a moderate size database.
Calling it once before scanning all folders and scanning
the watched folder instead of each time after downloading
a message from a folder speeds up IMAP loop.
2022-01-30 20:49:32 +00:00
link2xt 7cf4bcaca2 imap: call delete_expired_imap_messages() less often
This operation takes roughly 0.3 s on a moderate size database.
Calling it once before scanning all folders and scanning
the watched folder instead of each time after downloading
a message from a folder speeds up IMAP loop.
2022-01-30 20:47:32 +00:00
link2xt e858a32aa1 smtp: cancel message sending by removing the message
This restores the logic removed in
afd8c0d879
2022-01-30 10:59:10 +00:00
link2xt 0cb9e7922a Remove direct dependency on byteorder crate 2022-01-29 23:24:25 +00:00
link2xt e73107006e smtp: replace thiserror with anyhow 2022-01-29 16:41:47 +00:00
link2xt ca389cc6fc Move webxdc change to Unreleased 2022-01-29 16:41:04 +00:00
link2xt 60ec7f0cbf Move last changelog entry to Unreleased 2022-01-29 16:39:28 +00:00
link2xt 2690fa2da5 Don't watch Sent folder by default 2022-01-29 11:35:02 +00:00
link2xt 81de882e2f Add Protected Headers standard to standards.md 2022-01-23 19:47:10 +00:00
link2xt 593e07cdff cargo update 2022-01-23 19:31:34 +00:00
link2xt f7f899f0a4 smtp: retry immediately if connection is stale 2022-01-22 21:17:01 +00:00
link2xt f21691c122 Add "database_encrypted" field to Context.get_info() 2022-01-22 14:43:37 +00:00
link2xt a1f04d2129 imex: use param2 for passphrase 2022-01-16 13:22:08 +00:00
link2xt fb95573000 cargo update 2022-01-16 09:56:20 +00:00
link2xt 3c38fa6b70 Add API for passphrase-protected accounts
To create encrypted account with account manager, call
dc_accounts_add_closed_account(). Open this account with
dc_context_open() using the passphrase you want to use for encryption.

When application is loaded next time and account manager is created,
it will open all accounts that have no passphrase set. For encrypted
accounts dc_context_is_open() will return 0. To open them, call
dc_context_open() with the correct passphrase. After opening, call
dc_context_start_io() on this account or just dc_accounts_start_io()
to start all accounts that are not started yet.

Support for legacy SQLite-based backup format is removed in this
commit.
2022-01-06 08:54:58 +00:00
link2xt bfa641cea8 Error handling refactoring
- Replace .ok_or_else() and .map_err() with anyhow::Context where possible.
- Use .context() to check Option for None when it's an error
- Resultify Chatlist.get_chat_id()
- Add useful .context() to some errors
- IMAP error handling cleanup
2022-01-07 14:22:37 +00:00
link2xt 29c58efeb3 Remove default signature advertsing Delta Chat 2022-01-07 13:56:58 +00:00
link2xt 27eb82c556 context: hide ongoing process internals from public API
Also hide derive_blobdir and derive_walfile.
2022-01-07 06:25:03 +00:00
link2xt 652d67a20f Revert flaky "sql: enable auto_vacuum on all connections"
It results in "database is locked" errors on CI.

This reverts commit ce0984f02f.
2022-01-07 00:18:21 +03:00
link2xt ce0984f02f sql: enable auto_vacuum on all connections 2022-01-06 09:03:50 +00:00
link2xt bba3a25371 Add CONDSTORE to standards.md 2022-01-03 23:12:29 +00:00
link2xt 095b358aca Test multidevice synchronization of Seen status 2022-01-03 23:12:29 +00:00
link2xt 833e5f46cc Synchronize seen status across devices
Seen status is only synchronized on servers supporting IMAP CONDSTORE
extension. At the end of fetch loop iteration, flags are fetched for
all messages modified since previous synchronization and highest
modification sequence is stored into `imap_sync` table.
2022-01-03 23:12:29 +00:00
link2xt 3e0ce0e07a test_no_old_msg_is_fresh: compare DC_EVENT_MSGS_NOTICED argument to chat id
data1 of DC_EVENT_MSGS_NOTICED contains chat id, not message id
2022-01-03 23:12:29 +00:00
link2xt 1f31dd12fc Replace BTreeMap with BTreeSet in markseen_msgs 2022-01-03 23:12:29 +00:00
link2xt f63efc29bf Resultify update_msg_state 2022-01-03 23:12:29 +00:00
link2xt 3e394f14e8 sql: disable cipher_memory_security SQLCipher PRAGMA
It slows down dc_get_chat_msgs() from ~50ms to seconds on Android. It
is disabled by default in SQLCipher 4.5.0, but currently SQLCipher 4.4.3
is bundled so this PRAGMA has to be disabled manually.
2022-01-03 23:03:59 +00:00
link2xt 304c259a57 Update resync_folder_uids to use imap table 2022-01-02 17:04:16 +00:00
link2xt 630754b52e dc_receive_imf: don't fail on invalid address in the To field
This is an irrecoverable error, dc_receive_imf must not fail on it
as it prevents last seen UID from advancing, so the same message
is prefetched on each iteration of IMAP loop.
2022-01-02 00:20:44 +00:00
link2xt afd8c0d879 Add smtp table
It replaces SendMsgToSmtp job.

Prepared outgoing SMTP payloads are stored in the database now rather
than files in blobdir.
2022-01-01 19:14:53 +00:00
link2xt f3a716fac6 sql: enable auto_vacuum=INCREMENTAL
Previously default of `auto_vacuum=NONE` was used.

`PRAGMA auto_vacuum=INCERMENTAL` allows running `PRAGMA
incremental_vacuum`. Unlike `VACUUM`, `PRAGMA incremental_vacuum`
frees unused pages without rebuilding the whole database, like the
`VACUUM` does, so it does not require additional disk space to build a
vacuumed copy of the database. This may even free enough space on the
disk to run `VACUUM` afterwards.

New setting will only be enabled for new databases or if the `VACUUM`
command runs successfully. Currently `VACUUM` is only executed on
backup export, but may fail nevertheless if there is not enough space
on the disk.

Also try to run `PRAGMA incremental_vacuum` during housekeeping. It
may not be the best strategy, but likely does not make any difference
under normal usage when the database only grows and there are no free
pages. Free pages are created only if enough data is deleted to free
at least one database page of 4096 bytes, for example when automatic
deletion of messages is deleted for the first time. In the future if
more data is placed into the database, like avatars and other blobs,
it may be necessary to revise this strategy, for example to keep some
free pages instead of removing all of them each time by querying
`PRAGMA freelist_pages` and running `PRAGMA incremental_vacuum(N)`.
2021-12-31 21:33:38 +00:00
link2xt 72659580de sql: build rusqlite with sqlcipher 2022-01-01 00:00:00 +00:00
link2xt 30cb0cbcfd Reduce number of AsRef generics
They result in compilation of duplicate code.
2021-12-31 13:57:45 +00:00
link2xt 246cae5d9e Remove inbox_watch option
Also resultified `get_watched_folders`.

Python test `test_moved_markseen` is modified to test using incoming
message instead of BCC-self message, because BCC-self message is
detected immediately in the Inbox.
2021-12-25 18:07:14 +00:00
link2xt 12313543ca Fix leaving the group 2021-12-30 12:51:10 +00:00
link2xt 87e3dead14 Remove unused InterruptInfo.msg_id 2021-12-30 02:15:30 +00:00
link2xt 12823c2213 Add imap table to keep track of message UIDs
`imap` table maps Message-IDs to UIDs on the server. `dc_receive_imf`
no longer gets the UID of the message as an argument and does not
insert the folder and UID of the message into the `msgs`
table. `server_folder` and `server_uid` columns in `msgs` table are
deprecated.

MoveMsg and DeleteMsgOnImap jobs are removed. Now messages are moved
and deleted only in the `fetch_move_delete` procedure that consults
the `target` column of the `imap` table to determine where the message
should go.

Where the message should go is determined after prefetching by the
`imap::target_folder()` procedure.  Messages are only downloaded once
they reach their target folder to avoid race conditions in multidevice
setting, such as:

1. One device trying to FETCH the message while the other tries to
MOVE it.

2. One device marking the message as \Seen in the Inbox while the
other has already copied unseen message to the Movebox and is going to
delete the \Seen message in the Inbox.

3. Device downloads the message from the Inbox while there are newer
messages in the Movebox placed there by the other device, thus
processing the messages out of order.
2021-12-19 00:00:00 +00:00
link2xt 9e7bdc579e Test recovery from lost member removal message
This was fixed in d98d1857a4 but not
tested.

Revert d98d1857a4 to check that the test
is working.
2021-12-19 15:05:48 +00:00
link2xt 61af0c9ac4 python: remove API deprecated in Python 3.10 2021-12-18 17:47:08 +00:00
link2xt 91f02ad553 Rename asymetric test into asymmetric 2021-12-18 17:46:29 +00:00
link2xt 8d3a1e84c3 Remove mvbox_watch option and use mvbox_move instead 2021-12-18 13:55:01 +00:00
link2xt d009835210 Remove unnecessary getattr 2021-12-18 12:48:40 +00:00
link2xt 83a664ca68 Fix mypy error 2021-12-18 12:47:11 +00:00
link2xt d98d1857a4 Improve group updates
- Check that member modifying the group is in the group themselves.

  It is not allowed to readd yourself to the group or remove someone without being in the group themselves.

- Unify code for group member addition and removal.

  Removing a member now recreates the group member list from the To: field.

  Removed member from the Chat-Group-Member-Removed was in the To: field in previous Delta Chat versions,
  so it is excluded explicity. New versions of Delta Chat put removed member in Bcc: instead.

- Apply avatar changes after updating the group member list.

  This allows to check that the contact modifying the avatar is actually a group member.
2021-12-18 11:58:32 +00:00
link2xt dae80cbe35 Recognize MS Exchange read receipts as read receipts
They contain X-MSExch-Correlation-Key header, but no
Original-Message-ID, so they cannot be used to find the original
message, but we want to recognize them as MDN nevertheless to assign
them to the trash chat.
2021-12-11 21:44:54 +00:00
link2xt f8b4ef26b3 Update rustyline
The version was locked to 9.0.0 previsouly because Rust 1.56 requirement.
New version 9.1.1 should support 1.56 again.
2021-12-11 18:10:18 +00:00
link2xt db991453b0 Merge branch 'cargo-update' 2021-12-11 14:48:17 +00:00