mirror of
https://github.com/chatmail/core.git
synced 2026-04-05 23:22:11 +03:00
Start implementing #1994 TODO (in later PRs): - Add a hint to the watch settings that all folders are fetched from time to time (to be done in the individual UIs) - folder names are case-insensitive, so double-check that all comparisons are case-insensitive - The `scan_folders.rs` file didn't get as large as I expected and it's probably not worth it having an extra file for it. But if there are no objections, I'll make another PR to rename it to `folders.rs` and also put into it `configure_folders()` from `imap/mod.rs` and `needs_move()` with all its tests from `message.rs`. Done: - Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them, what do we do about this? The most reliable way to detect such messages that we found up to now is: If there is no `Received` header AND it's not in the `ConfiguredSentbox`, then ignore the email. - before or after INBOX idle trigger a new "scan all folders for messages". It does a "list folders" and then goes through all folders with select-statements, checking if "next-uid" was changed since checked last time. This might be batchable but in any case should not consume a lot of traffic. We might debounce this scan activity to happen at most every N minutes - if next-uid changed for a folder, we "prefetch" and "fetch" DC-messages as as needed ("dc-messages" are not just those with "Chat-Version" headers, but can also be regular emails) - if we discover DC-messages in folders that have the "/Spam" flag (maybe excluding ContactRequests) we automatically move them to INBOX/DeltaChat folder to help provider-spam-systems to regard this contact/mail as non-spam - for now, we do not change any user visible option, but introduce this "scan all" automatically and on top of what exists. The DeltaChat folder-watching does not perform scan-all-folders (maybe with the exception to trigger scan-all also with DeltaChat if INBOX is not watched) - Tests (except if you have ideas to improve them) - all folders, their last uidvalidity, next-seen etc. are kept in a separate "imap-sync" sqlite table. Maybe this can be used to streamline some of the "Sent" folder and "DeltaChat" folder detection code we already have. - We now also move self-sent messages from the Inbox to the Sent folder if `mvbox_move` is off, as this was very easy to do now. This way, we now behave more like a normal MUA if the user wants this. FOR LATER PRs: - maybe for the first 50 messages or so, we could reduce the IDLE-timeout (currently 23 minutes or so) to faster detect messages sent to non-inbox folders. However, on Android and iOS, we would likely trigger scan-all when the app moves to foreground, and so it might not be neccessary to reduce the current idle-timeout at least for them. We can leave this "faster discovery" question for the end, after we move to real-life testing. - (Later on, after the above works, we can consider heuristics on which folders to perform IDLE on, and remove the Watch-folder options (inbox, deltachat, sent). We tried to find a safe scheme for already doing it but failed to fine one, too many unknowns, also some questions regarding multi-device (you might have different settings with each of it, one moves, the other doesn't etc.) so we postponed this in favor of the above incremental suggestion.) * Start implementing #1994 * Add debug logs, it seems like the SQL migration can go into another pr * Let fetch_new_messages return whether there are new emails * Code style * Don't prefetch if there are no new emails * clippy * Even more debug logs * If the folder was not newly selected, return always try to fetch as uid_next is probably outdated * Fix new bug * Recognize spam folder * if we discover DC-messages in folders that have the "/Spam" flag (excluding ContactRequests) we automatically move them to INBOX/DeltaChat folder to help provider-spam-systems to regard this contact/mail as non-spam * Clippy, prioritize folder_meaning over folder_name_meaning * Add a first test, for the first day after installation only debounce to 2s * Start adding two tests (both of them fail) * Don't abort folder scan if one folder fails * More consts * Replace bool return value by enum * Split test up into multiple tests * Print logs during rust tests * Rust tests pass now * . * One of the Python tests passes now - reconfigure folders during scanning * Make the last test pass - Delete emails in all folders when starting the test, not only inbox and mvbox The problem had been that emails were left in the folder "xyz" * lint * DB migration (untested) * Store uid_next in SQL instead of lastseen in a config * Revert "If Inbox-watch is disabled and enabled again, do not fetch emails from in between" all folders are always watched, anyway * clippy, rm debug logs, comments * Codestyle, comments * fixing things again * Fix another test: don't fetch from uid_next-1 but uid_next; make some {} to {:#} so that we can use `.context(...)` * move self-sent, non-setupmessage chat messages to the Sent folder if `mvbox_move` is off * comment * Comments, make sure things work even if there is no uid_next * Style * Comments * The rust test tested wrongly * comments, small codestyle change * Ignore emails that are probably only drafts Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them. So: If there is no Received header AND it's not in the ConfiguredSentbox, then ignore the email. Also: Add test. * Fix occasional test failure, it was introduced as DC now moves messages from Inbox to Sent * Add `Received` header to the rust tests * After this PR we will always watch all folders and delete messages there if server_delete is enabled. So, for people who have server_delete on, disable it and add a hint to the devicechat * comment, small fix * link2xt's first review * Use ON CONFLICT(FOLDER) DO to update and if it doesn't exist, then insert Reason from link2xt: We had a problem with multiple peerstates inserted due to key fingerprint parsing error previously. With logic in Rust a similar problem can occur: an UPDATE can fail for reasons other than a conflict. PRIMARY KEY should ensure uniqueness in this case, but anyway. * Remove two TODO statements, remove fetch_new_messages: ignoring uid {}, uid_next was {} log * Next TODO: Make uidvalidity and uid_next DEFAULT 0 * rm two TODOs, Seems like we are not going to `exclude folders that are watched anyway` in this PR * small tweak: Handle instants more carefully * Add scan_all_folders_debounce_secs config for tests, set debounce to 60s (before it was just 2s during the first day) * Don't use bold letters for the device message * React to changes in the folders better Before, if there was a configured Sent folder, but then it got removed and replaced with another folder with a name meaning "Sent" but without Sent flag, it would be ignored. So, instead of checking against ConfiguredSentboxFolder, create two Option variables at the beginning of the loop and replace them with Some if it is None. At the end of the loop, store the new values into ConfiguredSendboxFolder and ConfiguredSpamFolder, even if it is None. Also, derive some useful traits. * move job: Return a meaningful error if server_folder is None instead of panicing * small error-handling fix * Fix test_fetch_existing() python test Before, we sometimes got a race condition where scan_folders() sees that there is a Sentbox and saves this info after we set the ConfiguredSentbox to None and before the message is sent. So, just expect that the message is moved to the sentbox. * migration is 72 now * rm 2 TODOs, Don't infinitely retry when dc_receive_imf() returns Err * clippy: Remove glob imports * Delete created folders at the beginning of tests (some created folders made problems in the next tests because) * Improve resetting accounts between tests
=========================
deltachat python bindings
=========================
This package provides bindings to the deltachat-core_ Rust -library
which implements IMAP/SMTP/MIME/PGP e-mail standards and offers
a low-level Chat/Contact/Message API to user interfaces and bots.
Installing pre-built packages (Linux-only)
========================================================
If you have a Linux system you may try to install the ``deltachat`` binary "wheel" packages
without any "build-from-source" steps. Otherwise you need to `compile the Delta Chat bindings
yourself <sourceinstall>`_.
We recommend to first `install virtualenv <https://virtualenv.pypa.io/en/stable/installation/>`_,
then create a fresh Python virtual environment and activate it in your shell::
virtualenv venv # or: python -m venv
source venv/bin/activate
Afterwards, invoking ``python`` or ``pip install`` only
modifies files in your ``venv`` directory and leaves
your system installation alone.
For Linux, we automatically build wheels for all github PR branches
and push them to a python package index. To install the latest
github ``master`` branch::
pip install --pre -i https://m.devpi.net/dc/master deltachat
To verify it worked::
python -c "import deltachat"
.. note::
If you can help to automate the building of wheels for Mac or Windows,
that'd be much appreciated! please then get
`in contact with us <https://delta.chat/en/contribute>`_.
Running tests
=============
After successful binding installation you can install a few more
Python packages before running the tests::
python -m pip install pytest pytest-xdist pytest-timeout pytest-rerunfailures requests
pytest -v tests
This will run all "offline" tests and skip all functional
end-to-end tests that require accounts on real e-mail servers.
.. _livetests:
running "live" tests with temporary accounts
---------------------------------------------
If you want to run live functional tests you can set ``DCC_NEW_TMP_EMAIL``::
export DCC_NEW_TMP_EMAIL=https://testrun.org/new_email?t=1h_4w4r8h7y9nmcdsy
With this, pytest runs create ephemeral e-mail accounts on the http://testrun.org server.
These accounts exists for one 1hour and then are removed completely.
One hour is enough to invoke pytest and run all offline and online tests:
pytest
# or if you have installed pytest-xdist for parallel test execution
pytest -n6
Each test run creates new accounts.
.. _sourceinstall:
Installing bindings from source (Updated: July 2020)
=========================================================
Install Rust and Cargo first.
The easiest is probably to use `rustup <https://rustup.rs/>`_.
Bootstrap Rust and Cargo by using rustup::
curl https://sh.rustup.rs -sSf | sh
Then clone the deltachat-core-rust repo::
git clone https://github.com/deltachat/deltachat-core-rust
cd deltachat-core-rust
To install the Delta Chat Python bindings make sure you have Python3 installed.
E.g. on Debian-based systems `apt install python3 python3-pip
python3-venv` should give you a usable python installation.
Ensure you are in the deltachat-core-rust/python directory, create the
virtual environment and activate it in your shell::
cd python
python3 -m venv venv # or: virtualenv venv
source venv/bin/activate
You should now be able to build the python bindings using the supplied script::
python install_python_bindings.py
The core compilation and bindings building might take a while,
depending on the speed of your machine.
The bindings will be installed in release mode but with debug symbols.
The release mode is currently necessary because some tests generate RSA keys
which is prohibitively slow in non-release mode.
Code examples
=============
You may look at `examples <https://py.delta.chat/examples.html>`_.
.. _`deltachat-core-rust github repository`: https://github.com/deltachat/deltachat-core-rust
.. _`deltachat-core`: https://github.com/deltachat/deltachat-core-rust
Building manylinux based wheels
====================================
Building portable manylinux wheels which come with libdeltachat.so
can be done with docker-tooling.
using docker pull / premade images
------------------------------------
We publish a build environment under the ``deltachat/coredeps`` tag so
that you can pull it from the ``hub.docker.com`` site's "deltachat"
organization::
$ docker pull deltachat/coredeps
This docker image can be used to run tests and build Python wheels for all interpreters::
$ docker run -e DCC_NEW_TMP_EMAIL \
--rm -it -v \$(pwd):/mnt -w /mnt \
deltachat/coredeps ci_scripts/run_all.sh
Optionally build your own docker image
--------------------------------------
If you want to build your own custom docker image you can do this::
$ cd deltachat-core # cd to deltachat-core checkout directory
$ docker build -t deltachat/coredeps ci_scripts/docker_coredeps
This will use the ``ci_scripts/docker_coredeps/Dockerfile`` to build
up docker image called ``deltachat/coredeps``. You can afterwards
find it with::
$ docker images
Troubleshooting
---------------
On more recent systems running the docker image may crash. You can
fix this by adding ``vsyscall=emulate`` to the Linux kernel boot
arguments commandline. E.g. on Debian you'd add this to
``GRUB_CMDLINE_LINUX_DEFAULT`` in ``/etc/default/grub``.