Compare commits

..

18 Commits

Author SHA1 Message Date
Sebastian Klähn
122e66746a integration @r10s' additions 2023-01-23 11:37:57 +01:00
Sebastian Klähn
afd7f90791 Update deltachat-ffi/deltachat.h
Co-authored-by: bjoern <r10s@b44t.com>
2023-01-23 11:13:27 +01:00
Sebastian Klähn
36cb8f3baf Update deltachat-ffi/deltachat.h
Co-authored-by: bjoern <r10s@b44t.com>
2023-01-23 11:13:03 +01:00
Sebastian Klähn
10390ae3c6 Merge branch 'master' into webxdc_update_notifications2 2023-01-16 15:40:29 +01:00
Septias
eab7f8ea15 modernise some stuff 2022-12-12 22:54:40 +01:00
Septias
32cbde0754 fix rebase problems 2022-12-12 22:54:21 +01:00
Sebastian Klähn
7aad25ea50 update events.ts 2022-12-12 22:54:21 +01:00
Sebastian Klähn
119f3ec9f2 change event id 2022-12-12 22:54:21 +01:00
Sebastian Klähn
fd486ec36c change event usage 2022-12-12 22:54:21 +01:00
Sebastian Klähn
e9f77ff753 change api interface 2022-12-12 22:54:21 +01:00
Sebastian Klähn
81415ce20e remove falsy comment 2022-12-12 22:54:21 +01:00
Sebastian Klähn
35f22d6c23 add ffi function 2022-12-12 22:54:21 +01:00
Sebastian Klähn
662f0b9a1c remove print 2022-12-12 22:54:21 +01:00
Sebastian Klähn
44508eb392 clippy fix 2022-12-12 22:54:21 +01:00
Sebastian Klähn
f72f922054 add test 2022-12-12 22:54:21 +01:00
Sebastian Klähn
a895456dac rm diff 2022-12-12 22:54:21 +01:00
Sebastian Klähn
de84a19135 different format 2022-12-12 22:54:21 +01:00
Sebastian Klähn
8d62e5defb webxdc update events 2022-12-12 22:54:21 +01:00
177 changed files with 2642 additions and 4311 deletions

View File

@@ -5,6 +5,8 @@ on:
push:
branches:
- master
- staging
- trying
env:
RUSTFLAGS: -Dwarnings
@@ -16,21 +18,31 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- name: Cache rust cargo artifacts
uses: swatinem/rust-cache@v2
- run: cargo fmt --all -- --check
run_clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install clippy
run: rustup toolchain install 1.67.1 --component clippy
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: clippy
override: true
- name: Cache rust cargo artifacts
uses: swatinem/rust-cache@v2
- name: Run clippy
env:
RUSTUP_TOOLCHAIN: 1.67.1
run: scripts/clippy.sh
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --workspace --tests --examples --benches --features repl -- -D warnings
docs:
name: Rust doc comments
@@ -40,6 +52,13 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v3
- name: Install rust stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
components: rust-docs
override: true
- name: Cache rust cargo artifacts
uses: swatinem/rust-cache@v2
- name: Rustdoc
@@ -71,37 +90,39 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Install Rust ${{ matrix.rust }}
run: rustup toolchain install ${{ matrix.rust }}
- run: rustup override set ${{ matrix.rust }}
- name: Install ${{ matrix.rust }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Cache rust cargo artifacts
uses: swatinem/rust-cache@v2
- name: Check
run: cargo check --workspace --bins --examples --tests --benches
- name: check
run: cargo check --all --bins --examples --tests --features repl --benches
- name: Tests
run: cargo test --workspace
- name: tests
run: cargo test --all
- name: Test cargo vendor
- name: test cargo vendor
run: cargo vendor
- name: Install python
- name: install python
if: ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install tox
- name: install tox
if: ${{ matrix.python }}
run: pip install tox
- name: Build C library
- name: build C library
if: ${{ matrix.python }}
run: cargo build -p deltachat_ffi --features jsonrpc
- name: Run python tests
- name: run python tests
if: ${{ matrix.python }}
env:
DCC_NEW_TMP_EMAIL: ${{ secrets.DCC_NEW_TMP_EMAIL }}
@@ -110,28 +131,28 @@ jobs:
working-directory: python
run: tox -e lint,mypy,doc,py3
- name: Build deltachat-rpc-server
- name: build deltachat-rpc-server
if: ${{ matrix.python }}
run: cargo build -p deltachat-rpc-server
- name: Add deltachat-rpc-server to path
- name: add deltachat-rpc-server to path
if: ${{ matrix.python }}
run: echo ${{ github.workspace }}/target/debug >> $GITHUB_PATH
- name: Run deltachat-rpc-client tests
- name: run deltachat-rpc-client tests
if: ${{ matrix.python }}
env:
DCC_NEW_TMP_EMAIL: ${{ secrets.DCC_NEW_TMP_EMAIL }}
working-directory: deltachat-rpc-client
run: tox -e py3,lint
run: tox -e py3
- name: Install pypy
- name: install pypy
if: ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: 'pypy${{ matrix.python }}'
- name: Run pypy tests
- name: run pypy tests
if: ${{ matrix.python }}
env:
DCC_NEW_TMP_EMAIL: ${{ secrets.DCC_NEW_TMP_EMAIL }}

View File

@@ -12,14 +12,14 @@ jobs:
name: 'Package @deltachat/jsonrpc-client and upload to download.delta.chat'
runs-on: ubuntu-18.04
steps:
- name: Install tree
- name: install tree
run: sudo apt install tree
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Get tag
- name: get tag
id: tag
uses: dawidd6/action-get-tag@v1
continue-on-error: true
@@ -38,11 +38,11 @@ jobs:
npm --version
node --version
echo $DELTACHAT_JSONRPC_TAR_GZ
- name: Install dependencies without running scripts
- name: install dependencies without running scripts
run: |
cd deltachat-jsonrpc/typescript
npm install --ignore-scripts
- name: Package
- name: package
shell: bash
run: |
cd deltachat-jsonrpc/typescript
@@ -65,7 +65,7 @@ jobs:
chmod 600 __TEMP_INPUT_KEY_FILE
scp -o StrictHostKeyChecking=no -v -i __TEMP_INPUT_KEY_FILE -P "22" -r deltachat-jsonrpc/typescript/$DELTACHAT_JSONRPC_TAR_GZ "${{ secrets.USERNAME }}"@"download.delta.chat":"/var/www/html/download/node/preview/"
continue-on-error: true
- name: Post links to details
- name: "Post links to details"
if: steps.upload-preview.outcome == 'success'
run: node ./node/scripts/postLinksToDetails.js
env:

View File

@@ -9,7 +9,7 @@ on:
jobs:
prebuild:
name: Prebuild
name: 'prebuild'
runs-on: ${{ matrix.os }}
strategy:
matrix:
@@ -65,17 +65,17 @@ jobs:
pack-module:
needs: prebuild
name: Package deltachat-node and upload to download.delta.chat
name: 'Package deltachat-node and upload to download.delta.chat'
runs-on: ubuntu-18.04
steps:
- name: Install tree
- name: install tree
run: sudo apt install tree
- name: Checkout
uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: '16'
- name: Get tag
- name: get tag
id: tag
uses: dawidd6/action-get-tag@v1
continue-on-error: true
@@ -97,15 +97,15 @@ jobs:
npm --version
node --version
echo $DELTACHAT_NODE_TAR_GZ
- name: Download Ubuntu prebuild
- name: Download ubuntu prebuild
uses: actions/download-artifact@v1
with:
name: ubuntu-18.04
- name: Download macOS prebuild
- name: Download macos prebuild
uses: actions/download-artifact@v1
with:
name: macos-latest
- name: Download Windows prebuild
- name: Download windows prebuild
uses: actions/download-artifact@v1
with:
name: windows-latest
@@ -117,23 +117,23 @@ jobs:
tar -xvzf windows-latest/windows-latest.tar.gz -C node/prebuilds
tree node/prebuilds
rm -rf ubuntu-18.04 macos-latest windows-latest
- name: Install dependencies without running scripts
- name: install dependencies without running scripts
run: |
npm install --ignore-scripts
- name: Build constants
- name: build constants
run: |
npm run build:core:constants
- name: Build TypeScript part
- name: build typescript part
run: |
npm run build:bindings:ts
- name: Package
- name: package
shell: bash
run: |
mv node/README.md README.md
npm pack .
ls -lah
mv $(find deltachat-node-*) $DELTACHAT_NODE_TAR_GZ
- name: Upload prebuild
- name: Upload Prebuild
uses: actions/upload-artifact@v3
with:
name: deltachat-node.tgz
@@ -148,7 +148,7 @@ jobs:
chmod 600 __TEMP_INPUT_KEY_FILE
scp -o StrictHostKeyChecking=no -v -i __TEMP_INPUT_KEY_FILE -P "22" -r $DELTACHAT_NODE_TAR_GZ "${{ secrets.USERNAME }}"@"download.delta.chat":"/var/www/html/download/node/preview/"
continue-on-error: true
- name: Post links to details
- name: "Post links to details"
if: steps.upload-preview.outcome == 'success'
run: node ./node/scripts/postLinksToDetails.js
env:

View File

@@ -9,7 +9,7 @@ on:
jobs:
tests:
name: Tests
name: 'tests'
runs-on: ${{ matrix.os }}
strategy:
matrix:

View File

@@ -13,11 +13,17 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build -p deltachat-repl --features vendored
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.66.0
override: true
- name: build
run: cargo build --example repl --features repl,vendored
- name: Upload binary
uses: actions/upload-artifact@v3
with:
name: repl.exe
path: 'target/debug/deltachat-repl.exe'
path: 'target/debug/examples/repl.exe'

View File

@@ -2,76 +2,13 @@
## Unreleased
### Changes
- deltachat-rpc-client: use `dataclass` for `Account`, `Chat`, `Contact` and `Message` #4042
- python: mark bindings as supporting typing according to PEP 561 #4045
- retry filesystem operations during account migration #4043
- replace `r2d2` and `r2d2_sqlite` dependencies with an own connection pool #4050 #4053
### Fixes
- deltachat-rpc-server: do not block stdin while processing the request. #4041
deltachat-rpc-server now reads the next request as soon as previous request handler is spawned.
- enable `auto_vacuum` on all SQL connections #2955
### API-Changes
- Remove `MimeMessage::from_bytes()` public interface. #4033
- BREAKING Types: jsonrpc: `get_messages` now returns a map with `MessageLoadResult` instead of failing completely if one of the requested messages could not be loaded. #4038
## 1.108.0
### Changes
- Use read/write timeouts instead of per-command timeouts for SMTP #3985
- Cache DNS results for SMTP connections #3985
- Prefer TLS over STARTTLS during autoconfiguration #4021
- Use SOCKS5 configuration for HTTP requests #4017
- Show non-deltachat emails by default for new installations #4019
### Fixes
- Fix Securejoin for multiple devices on a joining side #3982
- python: handle NULL value returned from `dc_get_msg()` #4020
Account.`get_message_by_id` may return `None` in this case.
### API-Changes
- Remove bitflags from `get_chat_msgs()` interface #4022
C interface is not changed.
Rust and JSON-RPC API have `flags` integer argument
replaced with two boolean flags `info_only` and `add_daymarker`.
- jsonrpc: add API to check if the message is sent by a bot #3877
## 1.107.1
### Changes
- Log server security (TLS/STARTTLS/plain) type #4005
### Fixes
- Disable SMTP pipelining #4006
## 1.107.0
### Changes
- Pipeline SMTP commands #3924
- Cache DNS results for IMAP connections #3970
### Fixes
- Securejoin: Fix adding and handling Autocrypt-Gossip headers #3914
- fix verifier-by addr was empty string intead of None #3961
- Emit DC_EVENT_MSGS_CHANGED for DC_CHAT_ID_ARCHIVED_LINK when the number of archived chats with
unread messages increases #3959
- Fix Peerstate comparison #3962
- Log SOCKS5 configuration for IMAP like already done for SMTP #3964
- Fix SOCKS5 usage for IMAP #3965
- Exit from recently seen loop on interrupt channel errors to avoid busy looping #3966
### API-Changes
- jsonrpc: add verified-by information to `Contact`-Object
- Remove `attach_selfavatar` config #3951
### Changes
- add debug logging support for webxdcs #3296
- `DC_EVENT_WEBXDC_UPDATE_STATE_CHANGED` is emitted when webxdc update state changes #3320
## 1.106.0

365
Cargo.lock generated
View File

@@ -165,18 +165,21 @@ dependencies = [
[[package]]
name = "async-smtp"
version = "0.8.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7384febcabdd07a498c9f4fbaa7e488ff4eb60d0ade14b47b09ec44b8f645301"
checksum = "6da21e1dd19fbad3e095ad519fb1558ab77fd82e5c4778dca8f9be0464589e1e"
dependencies = [
"anyhow",
"async-native-tls",
"async-trait",
"base64 0.13.1",
"bufstream",
"fast-socks5",
"futures",
"hostname",
"log",
"nom 7.1.1",
"pin-project",
"pin-utils",
"thiserror",
"tokio",
]
@@ -259,7 +262,7 @@ dependencies = [
"sha-1",
"sync_wrapper",
"tokio",
"tokio-tungstenite 0.17.2",
"tokio-tungstenite",
"tower",
"tower-http",
"tower-layer",
@@ -268,13 +271,13 @@ dependencies = [
[[package]]
name = "axum"
version = "0.6.4"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5694b64066a2459918d8074c2ce0d5a88f409431994c2356617c8ae0c4721fc"
checksum = "08b108ad2665fa3f6e6a517c3d80ec3e77d224c47d605167aefaa5d7ef97fa48"
dependencies = [
"async-trait",
"axum-core 0.3.2",
"base64 0.20.0",
"axum-core 0.3.0",
"base64 0.13.1",
"bitflags",
"bytes",
"futures-util",
@@ -292,10 +295,10 @@ dependencies = [
"serde_json",
"serde_path_to_error",
"serde_urlencoded",
"sha1",
"sha-1",
"sync_wrapper",
"tokio",
"tokio-tungstenite 0.18.0",
"tokio-tungstenite",
"tower",
"tower-http",
"tower-layer",
@@ -320,9 +323,9 @@ dependencies = [
[[package]]
name = "axum-core"
version = "0.3.2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cae3e661676ffbacb30f1a824089a8c9150e71017f7e1e38f2aa32009188d34"
checksum = "79b8558f5a0581152dc94dcd289132a1d377494bdeafcd41869b3258e3e2ad92"
dependencies = [
"async-trait",
"bytes",
@@ -345,7 +348,7 @@ dependencies = [
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"miniz_oxide 0.6.2",
"object",
"rustc-demangle",
]
@@ -374,12 +377,6 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5"
[[package]]
name = "base64"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
[[package]]
name = "base64ct"
version = "1.5.1"
@@ -453,9 +450,9 @@ checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8"
[[package]]
name = "bumpalo"
version = "3.12.0"
version = "3.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535"
checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3"
[[package]]
name = "byte-pool"
@@ -621,23 +618,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
[[package]]
name = "concolor"
version = "0.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "318d6c16e73b3a900eb212ad6a82fc7d298c5ab8184c7a9998646455bc474a16"
dependencies = [
"bitflags",
"concolor-query",
"is-terminal",
]
[[package]]
name = "concolor-query"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82a90734b3d5dcf656e7624cca6bce9c3a90ee11f900e80141a7427ccfb3d317"
[[package]]
name = "concurrent-queue"
version = "2.0.0"
@@ -893,7 +873,7 @@ checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb"
[[package]]
name = "deltachat"
version = "1.108.0"
version = "1.106.0"
dependencies = [
"ansi_term",
"anyhow",
@@ -903,11 +883,12 @@ dependencies = [
"async-smtp",
"async_zip",
"backtrace",
"base64 0.21.0",
"base64 0.20.0",
"bitflags",
"chrono",
"criterion",
"deltachat_derive",
"dirs",
"email",
"encoded-words",
"escaper",
@@ -928,19 +909,20 @@ dependencies = [
"num-traits",
"num_cpus",
"once_cell",
"parking_lot",
"percent-encoding",
"pgp",
"pretty_env_logger",
"proptest",
"qrcodegen",
"quick-xml",
"r2d2",
"r2d2_sqlite",
"rand 0.8.5",
"ratelimit",
"regex",
"reqwest",
"rusqlite",
"rust-hsluv",
"rustyline",
"sanitize-filename",
"serde",
"serde_json",
@@ -957,19 +939,19 @@ dependencies = [
"tokio-io-timeout",
"tokio-stream",
"tokio-tar",
"toml 0.7.1",
"toml",
"trust-dns-resolver",
"url",
"uuid 1.3.0",
"uuid 1.2.2",
]
[[package]]
name = "deltachat-jsonrpc"
version = "1.108.0"
version = "1.106.0"
dependencies = [
"anyhow",
"async-channel",
"axum 0.6.4",
"axum 0.6.1",
"deltachat",
"env_logger 0.10.0",
"futures",
@@ -985,24 +967,9 @@ dependencies = [
"yerpc",
]
[[package]]
name = "deltachat-repl"
version = "1.108.0"
dependencies = [
"ansi_term",
"anyhow",
"deltachat",
"dirs",
"log",
"pretty_env_logger",
"rusqlite",
"rustyline",
"tokio",
]
[[package]]
name = "deltachat-rpc-server"
version = "1.108.0"
version = "1.106.0"
dependencies = [
"anyhow",
"deltachat-jsonrpc",
@@ -1025,7 +992,7 @@ dependencies = [
[[package]]
name = "deltachat_ffi"
version = "1.108.0"
version = "1.106.0"
dependencies = [
"anyhow",
"deltachat",
@@ -1447,12 +1414,12 @@ dependencies = [
[[package]]
name = "flate2"
version = "1.0.25"
version = "1.0.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841"
checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6"
dependencies = [
"crc32fast",
"miniz_oxide",
"miniz_oxide 0.5.3",
]
[[package]]
@@ -1491,9 +1458,9 @@ version = "1.0.0"
[[package]]
name = "futures"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84"
checksum = "38390104763dc37a5145a53c29c63c1290b5d316d6086ec32c293f6736051bb0"
dependencies = [
"futures-channel",
"futures-core",
@@ -1506,9 +1473,9 @@ dependencies = [
[[package]]
name = "futures-channel"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5"
checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed"
dependencies = [
"futures-core",
"futures-sink",
@@ -1516,15 +1483,15 @@ dependencies = [
[[package]]
name = "futures-core"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608"
checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac"
[[package]]
name = "futures-executor"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e"
checksum = "7acc85df6714c176ab5edf386123fafe217be88c0840ec11f199441134a074e2"
dependencies = [
"futures-core",
"futures-task",
@@ -1533,9 +1500,9 @@ dependencies = [
[[package]]
name = "futures-io"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531"
checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb"
[[package]]
name = "futures-lite"
@@ -1554,9 +1521,9 @@ dependencies = [
[[package]]
name = "futures-macro"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70"
checksum = "bdfb8ce053d86b91919aad980c220b1fb8401a9394410e1c289ed7e66b61835d"
dependencies = [
"proc-macro2",
"quote",
@@ -1565,21 +1532,21 @@ dependencies = [
[[package]]
name = "futures-sink"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364"
checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9"
[[package]]
name = "futures-task"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366"
checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea"
[[package]]
name = "futures-util"
version = "0.3.26"
version = "0.3.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1"
checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6"
dependencies = [
"futures-channel",
"futures-core",
@@ -1666,6 +1633,15 @@ version = "1.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7"
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
@@ -1677,11 +1653,11 @@ dependencies = [
[[package]]
name = "hashlink"
version = "0.8.1"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa"
checksum = "7249a3129cbc1ffccd74857f81464a323a152173cdb134e0fd81bc803b29facf"
dependencies = [
"hashbrown",
"hashbrown 0.11.2",
]
[[package]]
@@ -1767,17 +1743,16 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "human-panic"
version = "1.1.0"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87eb03e654582b31967d414b86711a7bbd7c6b28a6b7d32857b7d1d45c0926f9"
checksum = "39f357a500abcbd7c5f967c1d45c8838585b36743823b9d43488f24850534e36"
dependencies = [
"backtrace",
"concolor",
"os_info",
"os_type",
"serde",
"serde_derive",
"termcolor",
"toml 0.5.11",
"toml",
"uuid 0.8.2",
]
@@ -1914,7 +1889,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
dependencies = [
"autocfg",
"hashbrown",
"hashbrown 0.12.3",
]
[[package]]
@@ -2073,9 +2048,9 @@ checksum = "292a948cd991e376cf75541fe5b97a1081d713c618b4f1b9500f8844e49eb565"
[[package]]
name = "libsqlite3-sys"
version = "0.25.2"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29f835d03d717946d28b1d1ed632eb6f0e24a299388ee623d0c23118d3e8a7fa"
checksum = "898745e570c7d0453cc1fbc4a701eb6c662ed54e8fec8b7d14be137ebeeb9d14"
dependencies = [
"cc",
"openssl-sys",
@@ -2200,6 +2175,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc"
dependencies = [
"adler",
]
[[package]]
name = "miniz_oxide"
version = "0.6.2"
@@ -2256,11 +2240,10 @@ dependencies = [
[[package]]
name = "nix"
version = "0.25.1"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4"
checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc"
dependencies = [
"autocfg",
"bitflags",
"cfg-if",
"libc",
@@ -2286,15 +2269,6 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "nom8"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
dependencies = [
"memchr",
]
[[package]]
name = "num-bigint-dig"
version = "0.8.1"
@@ -2437,9 +2411,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
version = "111.25.0+1.1.1t"
version = "111.22.0+1.1.1q"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3173cd3626c43e3854b1b727422a276e568d9ec5fe8cec197822cf52cfb743d6"
checksum = "8f31f0d509d1c1ae9cada2f9539ff8f37933831fd5098879e482aa687d659853"
dependencies = [
"cc",
]
@@ -2458,23 +2432,21 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "os_info"
version = "2.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2cc1b4330bb29087e791ae2a5cf56be64fb8946a4ff5aec2ba11c6ca51f5d60"
dependencies = [
"log",
"serde",
"winapi",
]
[[package]]
name = "os_str_bytes"
version = "6.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee"
[[package]]
name = "os_type"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3df761f6470298359f84fcfb60d86db02acc22c251c37265c07a3d1057d2389"
dependencies = [
"regex",
]
[[package]]
name = "ouroboros"
version = "0.15.2"
@@ -2684,7 +2656,7 @@ dependencies = [
"bitflags",
"crc32fast",
"flate2",
"miniz_oxide",
"miniz_oxide 0.6.2",
]
[[package]]
@@ -2795,6 +2767,27 @@ version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20f14e071918cbeefc5edc986a7aa92c425dae244e003a35e1cdddb5ca39b5cb"
[[package]]
name = "r2d2"
version = "0.8.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93"
dependencies = [
"log",
"parking_lot",
"scheduled-thread-pool",
]
[[package]]
name = "r2d2_sqlite"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fdc8e4da70586127893be32b7adf21326a4c6b1aba907611edf467d13ffe895"
dependencies = [
"r2d2",
"rusqlite",
]
[[package]]
name = "radix_trie"
version = "0.2.1"
@@ -2885,10 +2878,6 @@ dependencies = [
"rand_core 0.6.3",
]
[[package]]
name = "ratelimit"
version = "1.0.0"
[[package]]
name = "rayon"
version = "1.5.3"
@@ -2935,9 +2924,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.7.1"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
checksum = "e076559ef8e241f2ae3479e36f97bd5741c0330689e217ad51ce2c76808b868a"
dependencies = [
"aho-corasick",
"memchr",
@@ -2961,11 +2950,11 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.11.14"
version = "0.11.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9"
checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c"
dependencies = [
"base64 0.21.0",
"base64 0.13.1",
"bytes",
"encoding_rs",
"futures-core",
@@ -3038,15 +3027,16 @@ dependencies = [
[[package]]
name = "rusqlite"
version = "0.28.0"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a"
checksum = "85127183a999f7db96d1a976a309eebbfb6ea3b0b400ddd8340190129de6eb7a"
dependencies = [
"bitflags",
"fallible-iterator",
"fallible-streaming-iterator",
"hashlink",
"libsqlite3-sys",
"memchr",
"smallvec",
]
@@ -3098,9 +3088,9 @@ checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8"
[[package]]
name = "rustyline"
version = "10.1.1"
version = "10.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1e83c32c3f3c33b08496e0d1df9ea8c64d39adb8eb36a1ebb1440c690697aef"
checksum = "1d1cd5ae51d3f7bf65d7969d579d502168ef578f289452bd8ccc91de28fda20e"
dependencies = [
"bitflags",
"cfg-if",
@@ -3160,6 +3150,15 @@ dependencies = [
"windows-sys 0.36.1",
]
[[package]]
name = "scheduled-thread-pool"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "977a7519bff143a44f842fd07e80ad1329295bd71686457f18e496736f4bf9bf"
dependencies = [
"parking_lot",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
@@ -3229,15 +3228,6 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
dependencies = [
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
@@ -3554,9 +3544,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.25.0"
version = "1.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af"
checksum = "1d9f76183f91ecfb55e1d7d5602bd1d979e38a3a522fe900241cf195624d67ae"
dependencies = [
"autocfg",
"bytes",
@@ -3638,19 +3628,7 @@ dependencies = [
"futures-util",
"log",
"tokio",
"tungstenite 0.17.3",
]
[[package]]
name = "tokio-tungstenite"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd"
dependencies = [
"futures-util",
"log",
"tokio",
"tungstenite 0.18.0",
"tungstenite",
]
[[package]]
@@ -3669,47 +3647,13 @@ dependencies = [
[[package]]
name = "toml"
version = "0.5.11"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234"
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
dependencies = [
"serde",
]
[[package]]
name = "toml"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "772c1426ab886e7362aedf4abc9c0d1348a979517efedfc25862944d10137af0"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.19.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90a238ee2e6ede22fb95350acc78e21dc40da00bb66c0334bde83de4ed89424e"
dependencies = [
"indexmap",
"nom8",
"serde",
"serde_spanned",
"toml_datetime",
]
[[package]]
name = "tower"
version = "0.4.13"
@@ -3860,25 +3804,6 @@ dependencies = [
"utf-8",
]
[[package]]
name = "tungstenite"
version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788"
dependencies = [
"base64 0.13.1",
"byteorder",
"bytes",
"http",
"httparse",
"log",
"rand 0.8.5",
"sha1",
"thiserror",
"url",
"utf-8",
]
[[package]]
name = "twofish"
version = "0.7.1"
@@ -3936,7 +3861,7 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c5faade31a542b8b35855fff6e8def199853b2da8da256da52f52f1316ee3137"
dependencies = [
"hashbrown",
"hashbrown 0.12.3",
"regex",
]
@@ -4001,9 +3926,9 @@ dependencies = [
[[package]]
name = "uuid"
version = "1.3.0"
version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1674845326ee10d37ca60470760d4288a6f80f304007d92e5c53bab78c9cfd79"
checksum = "422ee0de9031b5b948b97a8fc04e3aa35230001a722ddd27943e0be31564ce4c"
dependencies = [
"getrandom 0.2.7",
"serde",
@@ -4331,9 +4256,9 @@ dependencies = [
[[package]]
name = "yerpc"
version = "0.4.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d383dfbc1842f5b915a01deeaea3523eef8653fcd734f79f6c696d51521c70f"
checksum = "d1baa6fce4cf16d1cff91b557baceac3e363106f66e555fff906a7f82dce8153"
dependencies = [
"anyhow",
"async-channel",
@@ -4353,9 +4278,9 @@ dependencies = [
[[package]]
name = "yerpc_derive"
version = "0.4.0"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd5e0da8e7a58236986d9032bad52f30995999f94cd39142aa1144b5875e8bce"
checksum = "e70f944ca6789bc55ddc86839478f6d49c9d2a66e130f69fd1f8d171b3108990"
dependencies = [
"convert_case",
"darling 0.14.1",

View File

@@ -1,6 +1,6 @@
[package]
name = "deltachat"
version = "1.108.0"
version = "1.106.0"
edition = "2021"
license = "MPL-2.0"
rust-version = "1.63"
@@ -13,12 +13,6 @@ opt-level = 1
[profile.test]
opt-level = 0
# Always optimize dependencies.
# This does not apply to crates in the workspace.
# <https://doc.rust-lang.org/cargo/reference/profiles.html#overrides>
[profile.dev.package."*"]
opt-level = 3
[profile.release]
lto = true
panic = 'abort'
@@ -26,19 +20,20 @@ panic = 'abort'
[dependencies]
deltachat_derive = { path = "./deltachat_derive" }
format-flowed = { path = "./format-flowed" }
ratelimit = { path = "./deltachat-ratelimit" }
ansi_term = { version = "0.12.1", optional = true }
anyhow = "1"
async-imap = { git = "https://github.com/async-email/async-imap", branch = "master", default-features = false, features = ["runtime-tokio"] }
async-native-tls = { version = "0.4", default-features = false, features = ["runtime-tokio"] }
async-smtp = { version = "0.8", default-features = false, features = ["runtime-tokio"] }
async-smtp = { version = "0.5", default-features = false, features = ["smtp-transport", "socks5", "runtime-tokio"] }
trust-dns-resolver = "0.22"
tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] }
tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar
backtrace = "0.3"
base64 = "0.21"
base64 = "0.20"
bitflags = "1.3"
chrono = { version = "0.4", default-features=false, features = ["clock", "std"] }
dirs = { version = "4", optional=true }
email = { git = "https://github.com/deltachat/rust-email", branch = "master" }
encoded-words = { git = "https://github.com/async-email/encoded-words", branch = "master" }
escaper = "0.1"
@@ -48,21 +43,24 @@ image = { version = "0.24.5", default-features=false, features = ["gif", "jpeg",
kamadak-exif = "0.5"
lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" }
libc = "0.2"
log = {version = "0.4.16", optional = true }
mailparse = "0.14"
native-tls = "0.2"
num_cpus = "1.15"
num-derive = "0.3"
num-traits = "0.2"
once_cell = "1.17.0"
parking_lot = "0.12"
percent-encoding = "2.2"
pgp = { version = "0.9", default-features = false }
pretty_env_logger = { version = "0.4", optional = true }
quick-xml = "0.27"
r2d2 = "0.8"
r2d2_sqlite = "0.20"
rand = "0.8"
regex = "1.7"
rusqlite = { version = "0.28", features = ["sqlcipher", "release_memory"] }
rusqlite = { version = "0.27", features = ["sqlcipher"] }
rust-hsluv = "0.1"
rustyline = { version = "10", optional = true }
sanitize-filename = "0.4"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
@@ -72,7 +70,7 @@ smallvec = "1"
strum = "0.24"
strum_macros = "0.24"
thiserror = "1"
toml = "0.7"
toml = "0.5"
url = "2"
uuid = { version = "1", features = ["serde", "v4"] }
fast-socks5 = "0.8"
@@ -84,7 +82,7 @@ async-channel = "1.8.0"
futures-lite = "1.12.0"
tokio-stream = { version = "0.1.11", features = ["fs"] }
tokio-io-timeout = "1.2.0"
reqwest = { version = "0.11.14", features = ["json"] }
reqwest = { version = "0.11.13", features = ["json"] }
async_zip = { version = "0.0.9", default-features = false, features = ["deflate"] }
[dev-dependencies]
@@ -103,14 +101,18 @@ members = [
"deltachat_derive",
"deltachat-jsonrpc",
"deltachat-rpc-server",
"deltachat-ratelimit",
"deltachat-repl",
"format-flowed",
]
[[example]]
name = "simple"
path = "examples/simple.rs"
required-features = ["repl"]
[[example]]
name = "repl"
path = "examples/repl/main.rs"
required-features = ["repl"]
[[bench]]
@@ -137,15 +139,14 @@ harness = false
name = "get_chatlist"
harness = false
[[bench]]
name = "send_events"
harness = false
[features]
default = ["vendored"]
internals = []
repl = ["internals", "rustyline", "log", "pretty_env_logger", "ansi_term", "dirs"]
vendored = [
"async-native-tls/vendored",
"async-smtp/native-tls-vendored",
"rusqlite/bundled-sqlcipher-vendored-openssl",
"reqwest/native-tls-vendored"
]
nightly = ["pgp/nightly"]

View File

@@ -19,19 +19,10 @@ $ curl https://sh.rustup.rs -sSf | sh
Compile and run Delta Chat Core command line utility, using `cargo`:
```
$ RUST_LOG=repl=info cargo run -p deltachat-repl -- ~/deltachat-db
$ RUST_LOG=repl=info cargo run --example repl --features repl -- ~/deltachat-db
```
where ~/deltachat-db is the database file. Delta Chat will create it if it does not exist.
Optionally, install `deltachat-repl` binary with
```
$ cargo install --path deltachat-repl/
```
and run as
```
$ deltachat-repl ~/deltachat-db
```
Configure your account (if not already configured):
```

View File

@@ -14,7 +14,7 @@ async fn address_book_benchmark(n: u32, read_count: u32) {
.unwrap();
let book = (0..n)
.map(|i| format!("Name {i}\naddr{i}@example.org\n"))
.map(|i| format!("Name {}\naddr{}@example.org\n", i, i))
.collect::<Vec<String>>()
.join("");

View File

@@ -1,7 +1,6 @@
use std::path::PathBuf;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use deltachat::accounts::Accounts;
use std::path::PathBuf;
use tempfile::tempdir;
async fn create_accounts(n: u32) {

View File

@@ -1,6 +1,7 @@
use std::path::Path;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use deltachat::chat::{self, ChatId};
use deltachat::chatlist::Chatlist;
use deltachat::context::Context;
@@ -14,7 +15,7 @@ async fn get_chat_msgs_benchmark(dbfile: &Path, chats: &[ChatId]) {
.unwrap();
for c in chats.iter().take(10) {
black_box(chat::get_chat_msgs(&context, *c).await.ok());
black_box(chat::get_chat_msgs(&context, *c, 0).await.ok());
}
}

View File

@@ -1,6 +1,7 @@
use std::path::Path;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use deltachat::chatlist::Chatlist;
use deltachat::context::Context;
use deltachat::stock_str::StockStrings;

View File

@@ -1,9 +1,8 @@
use std::path::Path;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use deltachat::context::Context;
use deltachat::stock_str::StockStrings;
use deltachat::Events;
use std::path::Path;
async fn search_benchmark(dbfile: impl AsRef<Path>) {
let id = 100;

View File

@@ -1,47 +0,0 @@
use criterion::{criterion_group, criterion_main, Criterion};
use deltachat::context::Context;
use deltachat::stock_str::StockStrings;
use deltachat::{info, Event, EventType, Events};
use tempfile::tempdir;
async fn send_events_benchmark(context: &Context) {
let emitter = context.get_event_emitter();
for _i in 0..1_000_000 {
info!(context, "interesting event...");
}
info!(context, "DONE");
loop {
match emitter.recv().await.unwrap() {
Event {
typ: EventType::Info(info),
..
} if info.contains("DONE") => {
break;
}
_ => {}
}
}
}
fn criterion_benchmark(c: &mut Criterion) {
let dir = tempdir().unwrap();
let dbfile = dir.path().join("db.sqlite");
let rt = tokio::runtime::Runtime::new().unwrap();
let context = rt.block_on(async {
Context::new(&dbfile, 100, Events::new(), StockStrings::new())
.await
.expect("failed to create context")
});
let executor = tokio::runtime::Runtime::new().unwrap();
c.bench_function("Sending 1.000.000 events", |b| {
b.to_async(&executor)
.iter(|| send_events_benchmark(&context))
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);

View File

@@ -1,6 +1,6 @@
[package]
name = "deltachat_ffi"
version = "1.108.0"
version = "1.106.0"
description = "Deltachat FFI"
edition = "2018"
readme = "README.md"
@@ -29,5 +29,6 @@ once_cell = "1.17.0"
[features]
default = ["vendored"]
vendored = ["deltachat/vendored"]
nightly = ["deltachat/nightly"]
jsonrpc = ["deltachat-jsonrpc"]

View File

@@ -1082,6 +1082,17 @@ int dc_send_webxdc_status_update (dc_context_t* context, uint32_t msg_id, const
*/
char* dc_get_webxdc_status_updates (dc_context_t* context, uint32_t msg_id, uint32_t serial);
/**
* Checks if a webxdc has pending updates to be sent out.
* @param context The context object.
* @param msg_id The ID of the message with the webxdc instance.
* @return 1 = webxdc is updating , 0 = webxdc is not updating
*/
int dc_is_webxdc_updating (dc_context_t* context, uint32_t msg_id);
/**
* Save a draft for a chat in the database.
*
@@ -1159,7 +1170,7 @@ uint32_t dc_add_device_msg (dc_context_t* context, const char*
/**
* Check if a device-message with a given label was ever added.
* Device-messages can be added with dc_add_device_msg().
* Device-messages can be added dc_add_device_msg().
*
* @memberof dc_context_t
* @param context The context object.
@@ -5671,7 +5682,7 @@ void dc_event_unref(dc_event_t* event);
#define DC_EVENT_INCOMING_MSG 2005
/**
* Downloading a bunch of messages just finished. This is an
* Downloading a bunch of messages just finished. This is an experimental
* event to allow the UI to only show one notification per message bunch,
* instead of cluttering the user with many notifications.
* For each of the msg_ids, an additional #DC_EVENT_INCOMING_MSG event was emitted before.
@@ -5872,10 +5883,17 @@ void dc_event_unref(dc_event_t* event);
*
* @param data1 (int) msg_id
*/
#define DC_EVENT_WEBXDC_INSTANCE_DELETED 2121
/**
* Webxdc changed it's update sending state
*
* @param data1 (int) msg_id
* @param data1 (int) is_sending
*/
#define DC_EVENT_WEBXDC_UPDATE_STATE_CHANGED 2122
/**
* @}
*/

View File

@@ -23,34 +23,34 @@ use std::sync::Arc;
use std::time::{Duration, SystemTime};
use anyhow::Context as _;
use deltachat::chat::{ChatId, ChatVisibility, MessageListOptions, MuteDuration, ProtectionStatus};
use deltachat::qr_code_generator::get_securejoin_qr_svg;
use num_traits::{FromPrimitive, ToPrimitive};
use once_cell::sync::Lazy;
use rand::Rng;
use tokio::runtime::Runtime;
use tokio::sync::RwLock;
use deltachat::chat::{ChatId, ChatVisibility, MuteDuration, ProtectionStatus};
use deltachat::constants::DC_MSG_ID_LAST_SPECIAL;
use deltachat::contact::{Contact, ContactId, Origin};
use deltachat::context::Context;
use deltachat::ephemeral::Timer as EphemeralTimer;
use deltachat::key::DcKey;
use deltachat::message::MsgId;
use deltachat::qr_code_generator::get_securejoin_qr_svg;
use deltachat::reaction::{get_msg_reactions, send_reaction, Reactions};
use deltachat::stock_str::StockMessage;
use deltachat::stock_str::StockStrings;
use deltachat::webxdc::StatusUpdateSerial;
use deltachat::*;
use deltachat::{accounts::Accounts, log::LogExt};
use num_traits::{FromPrimitive, ToPrimitive};
use once_cell::sync::Lazy;
use rand::Rng;
use tokio::runtime::Runtime;
use tokio::sync::RwLock;
use tokio::task::JoinHandle;
mod dc_array;
mod lot;
mod string;
use deltachat::chatlist::Chatlist;
use self::string::*;
use deltachat::chatlist::Chatlist;
// as C lacks a good and portable error handling,
// in general, the C Interface is forgiving wrt to bad parameters.
@@ -60,8 +60,7 @@ use self::string::*;
// this avoids panics if the ui just forgets to handle a case
// - finally, this behaviour matches the old core-c API and UIs already depend on it
const DC_GCM_ADDDAYMARKER: u32 = 0x01;
const DC_GCM_INFO_ONLY: u32 = 0x02;
// TODO: constants
// dc_context_t
@@ -116,7 +115,7 @@ pub unsafe extern "C" fn dc_context_new(
match ctx {
Ok(ctx) => Box::into_raw(Box::new(ctx)),
Err(err) => {
eprintln!("failed to create context: {err:#}");
eprintln!("failed to create context: {:#}", err);
ptr::null_mut()
}
}
@@ -140,7 +139,7 @@ pub unsafe extern "C" fn dc_context_new_closed(dbfile: *const libc::c_char) -> *
)) {
Ok(context) => Box::into_raw(Box::new(context)),
Err(err) => {
eprintln!("failed to create context: {err:#}");
eprintln!("failed to create context: {:#}", err);
ptr::null_mut()
}
}
@@ -215,7 +214,7 @@ pub unsafe extern "C" fn dc_set_config(
if key.starts_with("ui.") {
ctx.set_ui_config(&key, value.as_deref())
.await
.with_context(|| format!("Can't set {key} to {value:?}"))
.with_context(|| format!("Can't set {} to {:?}", key, value))
.log_err(ctx, "dc_set_config() failed")
.is_ok() as libc::c_int
} else {
@@ -223,7 +222,7 @@ pub unsafe extern "C" fn dc_set_config(
Ok(key) => ctx
.set_config(key, value.as_deref())
.await
.with_context(|| format!("Can't set {key} to {value:?}"))
.with_context(|| format!("Can't set {} to {:?}", key, value))
.log_err(ctx, "dc_set_config() failed")
.is_ok() as libc::c_int,
Err(_) => {
@@ -350,7 +349,7 @@ fn render_info(
) -> std::result::Result<String, std::fmt::Error> {
let mut res = String::new();
for (key, value) in &info {
writeln!(&mut res, "{key}={value}")?;
writeln!(&mut res, "{}={}", key, value)?;
}
Ok(res)
@@ -522,6 +521,7 @@ pub unsafe extern "C" fn dc_event_get_id(event: *mut dc_event_t) -> libc::c_int
EventType::SelfavatarChanged => 2110,
EventType::WebxdcStatusUpdate { .. } => 2120,
EventType::WebxdcInstanceDeleted { .. } => 2121,
EventType::WebxdcUpdateStateChanged { .. } => 2122,
}
}
@@ -571,6 +571,7 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
}
EventType::WebxdcStatusUpdate { msg_id, .. } => msg_id.to_u32() as libc::c_int,
EventType::WebxdcInstanceDeleted { msg_id, .. } => msg_id.to_u32() as libc::c_int,
EventType::WebxdcUpdateStateChanged { msg_id, .. } => msg_id.to_u32() as libc::c_int,
}
}
@@ -619,6 +620,10 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
status_update_serial,
..
} => status_update_serial.to_u32() as libc::c_int,
EventType::WebxdcUpdateStateChanged {
has_pending_updates: is_send,
..
} => *is_send as libc::c_int,
}
}
@@ -663,6 +668,7 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
| EventType::SelfavatarChanged
| EventType::WebxdcStatusUpdate { .. }
| EventType::WebxdcInstanceDeleted { .. }
| EventType::WebxdcUpdateStateChanged { .. }
| EventType::ChatEphemeralTimerModified { .. } => ptr::null_mut(),
EventType::ConfigureProgress { comment, .. } => {
if let Some(comment) = comment {
@@ -1157,21 +1163,12 @@ pub unsafe extern "C" fn dc_get_chat_msgs(
}
let ctx = &*context;
let info_only = (flags & DC_GCM_INFO_ONLY) != 0;
let add_daymarker = (flags & DC_GCM_ADDDAYMARKER) != 0;
block_on(async move {
Box::into_raw(Box::new(
chat::get_chat_msgs_ex(
ctx,
ChatId::new(chat_id),
MessageListOptions {
info_only,
add_daymarker,
},
)
.await
.unwrap_or_log_default(ctx, "failed to get chat msgs")
.into(),
chat::get_chat_msgs(ctx, ChatId::new(chat_id), flags)
.await
.unwrap_or_log_default(ctx, "failed to get chat msgs")
.into(),
))
})
}
@@ -1295,11 +1292,11 @@ pub unsafe extern "C" fn dc_get_chat_media(
} else {
Some(ChatId::new(chat_id))
};
let msg_type = from_prim(msg_type).expect(&format!("invalid msg_type = {msg_type}"));
let msg_type = from_prim(msg_type).expect(&format!("invalid msg_type = {}", msg_type));
let or_msg_type2 =
from_prim(or_msg_type2).expect(&format!("incorrect or_msg_type2 = {or_msg_type2}"));
from_prim(or_msg_type2).expect(&format!("incorrect or_msg_type2 = {}", or_msg_type2));
let or_msg_type3 =
from_prim(or_msg_type3).expect(&format!("incorrect or_msg_type3 = {or_msg_type3}"));
from_prim(or_msg_type3).expect(&format!("incorrect or_msg_type3 = {}", or_msg_type3));
block_on(async move {
Box::into_raw(Box::new(
@@ -1331,11 +1328,11 @@ pub unsafe extern "C" fn dc_get_next_media(
};
let ctx = &*context;
let msg_type = from_prim(msg_type).expect(&format!("invalid msg_type = {msg_type}"));
let msg_type = from_prim(msg_type).expect(&format!("invalid msg_type = {}", msg_type));
let or_msg_type2 =
from_prim(or_msg_type2).expect(&format!("incorrect or_msg_type2 = {or_msg_type2}"));
from_prim(or_msg_type2).expect(&format!("incorrect or_msg_type2 = {}", or_msg_type2));
let or_msg_type3 =
from_prim(or_msg_type3).expect(&format!("incorrect or_msg_type3 = {or_msg_type3}"));
from_prim(or_msg_type3).expect(&format!("incorrect or_msg_type3 = {}", or_msg_type3));
block_on(async move {
chat::get_next_media(
@@ -2195,7 +2192,7 @@ pub unsafe extern "C" fn dc_imex(
let what = match imex::ImexMode::from_i32(what_raw) {
Some(what) => what,
None => {
eprintln!("ignoring invalid argument {what_raw} to dc_imex");
eprintln!("ignoring invalid argument {} to dc_imex", what_raw);
return;
}
};
@@ -3083,7 +3080,7 @@ pub unsafe extern "C" fn dc_msg_new(
return ptr::null_mut();
}
let context = &*context;
let viewtype = from_prim(viewtype).expect(&format!("invalid viewtype = {viewtype}"));
let viewtype = from_prim(viewtype).expect(&format!("invalid viewtype = {}", viewtype));
let msg = MessageWrapper {
context,
message: message::Message::new(viewtype),
@@ -3266,7 +3263,7 @@ pub unsafe extern "C" fn dc_msg_get_webxdc_blob(
ptr as *mut libc::c_char
}
Err(err) => {
eprintln!("failed read blob from archive: {err}");
eprintln!("failed read blob from archive: {}", err);
ptr::null_mut()
}
}
@@ -3295,6 +3292,24 @@ pub unsafe extern "C" fn dc_msg_get_webxdc_info(msg: *mut dc_msg_t) -> *mut libc
})
}
#[no_mangle]
pub unsafe extern "C" fn dc_is_webxdc_updating(
context: *mut dc_context_t,
msg_id: u32,
) -> libc::c_int {
if context.is_null() {
eprintln!("ignoring careless call to dc_is_webxdc_updating()");
return 0;
}
let ctx = &*context;
block_on(async move {
webxdc::get_busy_webxdc_instances(ctx)
.await
.unwrap_or_default()
.contains(&MsgId::new(msg_id)) as libc::c_int
})
}
#[no_mangle]
pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c_char {
if msg.is_null() {
@@ -4319,7 +4334,7 @@ pub unsafe extern "C" fn dc_accounts_new(
Ok(accs) => Box::into_raw(Box::new(AccountsWrapper::new(accs))),
Err(err) => {
// We are using Anyhow's .context() and to show the inner error, too, we need the {:#}:
eprintln!("failed to create accounts: {err:#}");
eprintln!("failed to create accounts: {:#}", err);
ptr::null_mut()
}
}
@@ -4387,7 +4402,8 @@ pub unsafe extern "C" fn dc_accounts_select_account(
Ok(()) => 1,
Err(err) => {
accounts.emit_event(EventType::Error(format!(
"Failed to select account: {err:#}"
"Failed to select account: {:#}",
err
)));
0
}
@@ -4409,7 +4425,10 @@ pub unsafe extern "C" fn dc_accounts_add_account(accounts: *mut dc_accounts_t) -
match accounts.add_account().await {
Ok(id) => id,
Err(err) => {
accounts.emit_event(EventType::Error(format!("Failed to add account: {err:#}")));
accounts.emit_event(EventType::Error(format!(
"Failed to add account: {:#}",
err
)));
0
}
}
@@ -4430,7 +4449,10 @@ pub unsafe extern "C" fn dc_accounts_add_closed_account(accounts: *mut dc_accoun
match accounts.add_closed_account().await {
Ok(id) => id,
Err(err) => {
accounts.emit_event(EventType::Error(format!("Failed to add account: {err:#}")));
accounts.emit_event(EventType::Error(format!(
"Failed to add account: {:#}",
err
)));
0
}
}
@@ -4455,7 +4477,8 @@ pub unsafe extern "C" fn dc_accounts_remove_account(
Ok(()) => 1,
Err(err) => {
accounts.emit_event(EventType::Error(format!(
"Failed to remove account: {err:#}"
"Failed to remove account: {:#}",
err
)));
0
}
@@ -4485,7 +4508,8 @@ pub unsafe extern "C" fn dc_accounts_migrate_account(
Ok(id) => id,
Err(err) => {
accounts.emit_event(EventType::Error(format!(
"Failed to migrate account: {err:#}"
"Failed to migrate account: {:#}",
err
)));
0
}
@@ -4578,12 +4602,11 @@ pub unsafe extern "C" fn dc_accounts_get_event_emitter(
#[cfg(feature = "jsonrpc")]
mod jsonrpc {
use super::*;
use deltachat_jsonrpc::api::CommandApi;
use deltachat_jsonrpc::events::event_to_json_rpc_notification;
use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession};
use super::*;
pub struct dc_jsonrpc_instance_t {
receiver: OutReceiver,
handle: RpcSession<CommandApi>,

View File

@@ -1,12 +1,10 @@
//! # Legacy generic return values for C API.
use std::borrow::Cow;
use anyhow::Error;
use crate::message::MessageState;
use crate::qr::Qr;
use crate::summary::{Summary, SummaryPrefix};
use anyhow::Error;
use std::borrow::Cow;
/// An object containing a set of values.
/// The meaning of the values is defined by the function returning the object.
@@ -22,15 +20,20 @@ pub enum Lot {
}
#[repr(u8)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Meaning {
#[default]
None = 0,
Text1Draft = 1,
Text1Username = 2,
Text1Self = 3,
}
impl Default for Meaning {
fn default() -> Self {
Meaning::None
}
}
impl Lot {
pub fn get_text1(&self) -> Option<&str> {
match self {
@@ -146,9 +149,9 @@ impl Lot {
}
#[repr(u32)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LotState {
#[default]
// Default
Undefined = 0,
// Qr States
@@ -210,6 +213,12 @@ pub enum LotState {
MsgOutMdnRcvd = 28,
}
impl Default for LotState {
fn default() -> Self {
LotState::Undefined
}
}
impl From<MessageState> for LotState {
fn from(s: MessageState) -> Self {
use MessageState::*;

View File

@@ -287,9 +287,8 @@ fn as_path_unicode<'a>(s: *const libc::c_char) -> &'a std::path::Path {
#[cfg(test)]
mod tests {
use libc::{free, strcmp};
use super::*;
use libc::{free, strcmp};
#[test]
fn test_os_str_to_c_string_cwd() {

View File

@@ -1,6 +1,6 @@
[package]
name = "deltachat-jsonrpc"
version = "1.108.0"
version = "1.106.0"
description = "DeltaChat JSON-RPC API"
edition = "2021"
default-run = "deltachat-jsonrpc-server"
@@ -19,20 +19,20 @@ serde = { version = "1.0", features = ["derive"] }
tempfile = "3.3.0"
log = "0.4"
async-channel = { version = "1.8.0" }
futures = { version = "0.3.26" }
futures = { version = "0.3.25" }
serde_json = "1.0.91"
yerpc = { version = "^0.4.0", features = ["anyhow_expose"] }
yerpc = { version = "^0.3.1", features = ["anyhow_expose"] }
typescript-type-def = { version = "0.5.5", features = ["json_value"] }
tokio = { version = "1.25.0" }
tokio = { version = "1.23.1" }
sanitize-filename = "0.4"
walkdir = "2.3.2"
# optional dependencies
axum = { version = "0.6.4", optional = true, features = ["ws"] }
axum = { version = "0.6.1", optional = true, features = ["ws"] }
env_logger = { version = "0.10.0", optional = true }
[dev-dependencies]
tokio = { version = "1.25.0", features = ["full", "rt-multi-thread"] }
tokio = { version = "1.23.1", features = ["full", "rt-multi-thread"] }
[features]

View File

@@ -281,6 +281,7 @@ pub enum JSONRPCEventType {
WebxdcInstanceDeleted {
msg_id: u32,
},
WebxdcUpdateStateChanged,
}
impl From<EventType> for JSONRPCEventType {
@@ -381,6 +382,7 @@ impl From<EventType> for JSONRPCEventType {
EventType::WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
msg_id: msg_id.to_u32(),
},
EventType::WebxdcUpdateStateChanged { .. } => WebxdcUpdateStateChanged,
}
}
}

View File

@@ -1,14 +1,8 @@
use std::collections::BTreeMap;
use std::sync::Arc;
use std::{collections::HashMap, str::FromStr};
use anyhow::{anyhow, bail, ensure, Context, Result};
pub use deltachat::accounts::Accounts;
use deltachat::{
chat::{
self, add_contact_to_chat, forward_msgs, get_chat_media, get_chat_msgs, get_chat_msgs_ex,
marknoticed_chat, remove_contact_from_chat, Chat, ChatId, ChatItem, MessageListOptions,
ProtectionStatus,
self, add_contact_to_chat, forward_msgs, get_chat_media, get_chat_msgs, marknoticed_chat,
remove_contact_from_chat, Chat, ChatId, ChatItem, ProtectionStatus,
},
chatlist::Chatlist,
config::Config,
@@ -29,14 +23,21 @@ use deltachat::{
webxdc::StatusUpdateSerial,
};
use sanitize_filename::is_sanitized;
use std::collections::BTreeMap;
use std::sync::Arc;
use std::{collections::HashMap, str::FromStr};
use tokio::{fs, sync::RwLock};
use walkdir::WalkDir;
use yerpc::rpc;
pub use deltachat::accounts::Accounts;
pub mod events;
pub mod types;
use num_traits::FromPrimitive;
use crate::api::types::chat_list::{get_chat_list_item_by_id, ChatListItemFetchResult};
use crate::api::types::qr::QrObject;
use types::account::Account;
use types::chat::FullChat;
use types::chat_list::ChatListEntry;
@@ -45,7 +46,6 @@ use types::message::MessageObject;
use types::provider_info::ProviderInfo;
use types::webxdc::WebxdcMessageInfo;
use self::types::message::MessageLoadResult;
use self::types::{
chat::{BasicChat, JSONRPCChatVisibility, MuteDuration},
location::JsonrpcLocation,
@@ -53,8 +53,8 @@ use self::types::{
JSONRPCMessageListItem, MessageNotificationInfo, MessageSearchResult, MessageViewtype,
},
};
use crate::api::types::chat_list::{get_chat_list_item_by_id, ChatListItemFetchResult};
use crate::api::types::qr::QrObject;
use num_traits::FromPrimitive;
#[derive(Clone, Debug)]
pub struct CommandApi {
@@ -86,11 +86,6 @@ impl CommandApi {
#[rpc(all_positional, ts_outdir = "typescript/generated")]
impl CommandApi {
/// Test function.
async fn sleep(&self, delay: f64) {
tokio::time::sleep(std::time::Duration::from_secs_f64(delay)).await
}
// ---------------------------------------------
// Misc top level functions
// ---------------------------------------------
@@ -141,7 +136,7 @@ impl CommandApi {
if let Some(ctx) = context_option {
accounts.push(Account::from_context(&ctx, id).await?)
} else {
println!("account with id {id} doesn't exist anymore");
println!("account with id {} doesn't exist anymore", id);
}
}
Ok(accounts)
@@ -249,7 +244,7 @@ impl CommandApi {
for (key, value) in config.into_iter() {
set_config(&ctx, &key, value.as_deref())
.await
.with_context(|| format!("Can't set {key} to {value:?}"))?;
.with_context(|| format!("Can't set {} to {:?}", key, value))?;
}
Ok(())
}
@@ -466,7 +461,7 @@ impl CommandApi {
Ok(res) => res,
Err(err) => ChatListItemFetchResult::Error {
id: entry.0,
error: format!("{err:#}"),
error: format!("{:?}", err),
},
},
);
@@ -810,7 +805,7 @@ impl CommandApi {
let ctx = self.get_context(account_id).await?;
// TODO: implement this in core with an SQL query, that will be way faster
let messages = get_chat_msgs(&ctx, ChatId::new(chat_id)).await?;
let messages = get_chat_msgs(&ctx, ChatId::new(chat_id), 0).await?;
let mut first_unread_message_id = None;
for item in messages.into_iter().rev() {
if let ChatItem::Message { msg_id } = item {
@@ -885,23 +880,9 @@ impl CommandApi {
markseen_msgs(&ctx, msg_ids.into_iter().map(MsgId::new).collect()).await
}
async fn get_message_ids(
&self,
account_id: u32,
chat_id: u32,
info_only: bool,
add_daymarker: bool,
) -> Result<Vec<u32>> {
async fn get_message_ids(&self, account_id: u32, chat_id: u32, flags: u32) -> Result<Vec<u32>> {
let ctx = self.get_context(account_id).await?;
let msg = get_chat_msgs_ex(
&ctx,
ChatId::new(chat_id),
MessageListOptions {
info_only,
add_daymarker,
},
)
.await?;
let msg = get_chat_msgs(&ctx, ChatId::new(chat_id), flags).await?;
Ok(msg
.iter()
.map(|chat_item| -> u32 {
@@ -917,19 +898,10 @@ impl CommandApi {
&self,
account_id: u32,
chat_id: u32,
info_only: bool,
add_daymarker: bool,
flags: u32,
) -> Result<Vec<JSONRPCMessageListItem>> {
let ctx = self.get_context(account_id).await?;
let msg = get_chat_msgs_ex(
&ctx,
ChatId::new(chat_id),
MessageListOptions {
info_only,
add_daymarker,
},
)
.await?;
let msg = get_chat_msgs(&ctx, ChatId::new(chat_id), flags).await?;
Ok(msg
.iter()
.map(|chat_item| (*chat_item).into())
@@ -946,27 +918,17 @@ impl CommandApi {
MsgId::new(message_id).get_html(&ctx).await
}
/// get multiple messages in one call,
/// if loading one message fails the error is stored in the result object in it's place.
///
/// this is the batch variant of [get_message]
async fn get_messages(
&self,
account_id: u32,
message_ids: Vec<u32>,
) -> Result<HashMap<u32, MessageLoadResult>> {
) -> Result<HashMap<u32, MessageObject>> {
let ctx = self.get_context(account_id).await?;
let mut messages: HashMap<u32, MessageLoadResult> = HashMap::new();
let mut messages: HashMap<u32, MessageObject> = HashMap::new();
for message_id in message_ids {
let message_result = MessageObject::from_message_id(&ctx, message_id).await;
messages.insert(
message_id,
match message_result {
Ok(message) => MessageLoadResult::Message(message),
Err(error) => MessageLoadResult::LoadingError {
error: format!("{error:#}"),
},
},
MessageObject::from_message_id(&ctx, message_id).await?,
);
}
Ok(messages)
@@ -1754,7 +1716,7 @@ async fn set_config(
ctx.set_ui_config(key, value).await?;
} else {
ctx.set_config(
Config::from_str(key).with_context(|| format!("unknown key {key:?}"))?,
Config::from_str(key).with_context(|| format!("unknown key {:?}", key))?,
value,
)
.await?;
@@ -1776,7 +1738,7 @@ async fn get_config(
if key.starts_with("ui.") {
ctx.get_ui_config(key).await
} else {
ctx.get_config(Config::from_str(key).with_context(|| format!("unknown key {key:?}"))?)
ctx.get_config(Config::from_str(key).with_context(|| format!("unknown key {:?}", key))?)
.await
}
}

View File

@@ -19,13 +19,6 @@ use super::contact::ContactObject;
use super::reactions::JSONRPCReactions;
use super::webxdc::WebxdcMessageInfo;
#[derive(Serialize, TypeDef)]
#[serde(rename_all = "camelCase", tag = "variant")]
pub enum MessageLoadResult {
Message(MessageObject),
LoadingError { error: String },
}
#[derive(Serialize, TypeDef)]
#[serde(rename = "Message", rename_all = "camelCase")]
pub struct MessageObject {
@@ -55,10 +48,6 @@ pub struct MessageObject {
is_setupmessage: bool,
is_info: bool,
is_forwarded: bool,
/// True if the message was sent by a bot.
is_bot: bool,
/// when is_info is true this describes what type of system message it is
system_message_type: SystemMessageType,
@@ -193,7 +182,6 @@ impl MessageObject {
is_setupmessage: message.is_setupmessage(),
is_info: message.is_info(),
is_forwarded: message.is_forwarded(),
is_bot: message.is_bot(),
system_message_type: message.get_info_type().into(),
duration: message.get_duration(),

View File

@@ -10,7 +10,7 @@ pub mod reactions;
pub mod webxdc;
pub fn color_int_to_hex_string(color: u32) -> String {
format!("{color:#08x}").replace("0x", "#")
format!("{:#08x}", color).replace("0x", "#")
}
fn maybe_empty_string_to_option(string: String) -> Option<String> {

View File

@@ -4,13 +4,12 @@ pub use yerpc;
#[cfg(test)]
mod tests {
use super::api::{Accounts, CommandApi};
use async_channel::unbounded;
use futures::StreamExt;
use tempfile::TempDir;
use yerpc::{RpcClient, RpcSession};
use super::api::{Accounts, CommandApi};
#[tokio::test(flavor = "multi_thread")]
async fn basic_json_rpc_functionality() -> anyhow::Result<()> {
let tmp_dir = TempDir::new().unwrap().path().into();
@@ -37,7 +36,7 @@ mod tests {
let response = r#"{"jsonrpc":"2.0","id":1,"result":1}"#;
session.handle_incoming(request).await;
let result = receiver.next().await;
println!("{result:?}");
println!("{:?}", result);
assert_eq!(result, Some(response.to_owned()));
}
{
@@ -45,7 +44,7 @@ mod tests {
let response = r#"{"jsonrpc":"2.0","id":2,"result":[1]}"#;
session.handle_incoming(request).await;
let result = receiver.next().await;
println!("{result:?}");
println!("{:?}", result);
assert_eq!(result, Some(response.to_owned()));
}

View File

@@ -1,7 +1,6 @@
use axum::{extract::ws::WebSocketUpgrade, response::Response, routing::get, Extension, Router};
use std::net::SocketAddr;
use std::path::PathBuf;
use axum::{extract::ws::WebSocketUpgrade, response::Response, routing::get, Extension, Router};
use yerpc::axum::handle_ws_rpc;
use yerpc::{RpcClient, RpcSession};

View File

@@ -68,22 +68,22 @@ async function run() {
null
);
for (const [chatId, _messageId] of chats) {
const chat = await client.rpc.getFullChatById(selectedAccount, chatId);
const chat = await client.rpc.getFullChatById(
selectedAccount,
chatId
);
write($main, `<h3>${chat.name}</h3>`);
const messageIds = await client.rpc.getMessageIds(
selectedAccount,
chatId,
false,
false
0
);
const messages = await client.rpc.getMessages(
selectedAccount,
messageIds
);
for (const [_messageId, message] of Object.entries(messages)) {
if (message.variant === "message")
write($main, `<p>${message.text}</p>`);
else write($main, `<p>loading error: ${message.error}</p>`);
write($main, `<p>${message.text}</p>`);
}
}
}

View File

@@ -3,27 +3,24 @@ import { DeltaChat } from "../dist/deltachat.js";
run().catch(console.error);
async function run() {
const delta = new DeltaChat("ws://localhost:20808/ws");
const delta = new DeltaChat('ws://localhost:20808/ws');
delta.on("event", (event) => {
console.log("event", event.data);
});
const email = process.argv[2];
const password = process.argv[3];
if (!email || !password)
throw new Error(
"USAGE: node node-add-account.js <EMAILADDRESS> <PASSWORD>"
);
console.log(`creating acccount for ${email}`);
const id = await delta.rpc.addAccount();
console.log(`created account id ${id}`);
const email = process.argv[2]
const password = process.argv[3]
if (!email || !password) throw new Error('USAGE: node node-add-account.js <EMAILADDRESS> <PASSWORD>')
console.log(`creating acccount for ${email}`)
const id = await delta.rpc.addAccount()
console.log(`created account id ${id}`)
await delta.rpc.setConfig(id, "addr", email);
await delta.rpc.setConfig(id, "mail_pw", password);
console.log("configuration updated");
await delta.rpc.configure(id);
console.log("account configured!");
console.log('configuration updated')
await delta.rpc.configure(id)
console.log('account configured!')
const accounts = await delta.rpc.getAllAccounts();
console.log("accounts", accounts);
console.log("waiting for events...");
console.log("waiting for events...")
}

View File

@@ -10,5 +10,5 @@ async function run() {
const accounts = await delta.rpc.getAllAccounts();
console.log("accounts", accounts);
console.log("waiting for events...");
console.log("waiting for events...")
}

View File

@@ -0,0 +1,3 @@
// AUTO-GENERATED by typescript-type-def
export type EventTypeName=("Info"|"SmtpConnected"|"ImapConnected"|"SmtpMessageSent"|"ImapMessageDeleted"|"ImapMessageMoved"|"NewBlobFile"|"DeletedBlobFile"|"Warning"|"Error"|"ErrorSelfNotInGroup"|"MsgsChanged"|"IncomingMsg"|"MsgsNoticed"|"MsgDelivered"|"MsgFailed"|"MsgRead"|"ChatModified"|"ChatEphemeralTimerModified"|"ContactsChanged"|"LocationChanged"|"ConfigureProgress"|"ImexProgress"|"ImexFileWritten"|"SecurejoinInviterProgress"|"SecurejoinJoinerProgress"|"ConnectivityChanged"|"SelfavatarChanged"|"WebxdcStatusUpdate"|"WebxdcInstanceDeleted"|"WebxdcUpdateStateChanged");

View File

@@ -38,8 +38,8 @@
"example:start": "http-server .",
"extract-constants": "node ./scripts/generate-constants.js",
"generate-bindings": "cargo test",
"prettier:check": "prettier --check .",
"prettier:fix": "prettier --write .",
"prettier:check": "prettier --check **.ts",
"prettier:fix": "prettier --write **.ts",
"test": "run-s test:prepare test:run-coverage test:report-coverage",
"test:prepare": "cargo build --package deltachat-rpc-server --bin deltachat-rpc-server",
"test:report-coverage": "node report_api_coverage.mjs",
@@ -48,5 +48,5 @@
},
"type": "module",
"types": "dist/deltachat.d.ts",
"version": "1.108.0"
}
"version": "1.106.0"
}

View File

@@ -43,7 +43,7 @@ export class BaseDeltaChat<
const method = request.method;
if (method === "event") {
const event = request.params! as DCWireEvent<Event>;
//@ts-ignore
//@ts-ignore
this.emit(event.event.type, event.contextId, event.event as any);
this.emit("ALL", event.contextId, event.event as any);
@@ -120,7 +120,7 @@ export class StdioTransport extends BaseTransport {
});
}
_send(message: any): void {
_send(message: RPC.Message): void {
const serialized = JSON.stringify(message);
this.input.write(serialized + "\n");
}

View File

@@ -4,7 +4,10 @@ import chaiAsPromised from "chai-as-promised";
chai.use(chaiAsPromised);
import { StdioDeltaChat as DeltaChat } from "../deltachat.js";
import { RpcServerHandle, startServer } from "./test_base.js";
import {
RpcServerHandle,
startServer,
} from "./test_base.js";
describe("basic tests", () => {
let serverHandle: RpcServerHandle;
@@ -12,9 +15,9 @@ describe("basic tests", () => {
before(async () => {
serverHandle = await startServer();
dc = new DeltaChat(serverHandle.stdin, serverHandle.stdout);
dc = new DeltaChat(serverHandle.stdin, serverHandle.stdout)
// dc.on("ALL", (event) => {
//console.log("event", event);
//console.log("event", event);
// });
});
@@ -108,8 +111,8 @@ describe("basic tests", () => {
assert((await dc.rpc.getConfig(accountId, "addr")) == "valid@email");
});
it("set invalid key should throw", async function () {
await expect(dc.rpc.setConfig(accountId, "invalid_key", "some value")).to
.be.eventually.rejected;
await expect(dc.rpc.setConfig(accountId, "invalid_key", "some value")).to.be
.eventually.rejected;
});
it("get invalid key should throw", async function () {
await expect(dc.rpc.getConfig(accountId, "invalid_key")).to.be.eventually
@@ -122,10 +125,7 @@ describe("basic tests", () => {
it("set and retrive (batch)", async function () {
const config = { addr: "valid@email", mail_pw: "1234" };
await dc.rpc.batchSetConfig(accountId, config);
const retrieved = await dc.rpc.batchGetConfig(
accountId,
Object.keys(config)
);
const retrieved = await dc.rpc.batchGetConfig(accountId, Object.keys(config));
expect(retrieved).to.deep.equal(config);
});
it("set and retrive ui.* (batch)", async function () {
@@ -134,10 +134,7 @@ describe("basic tests", () => {
"ui.enter_key_sends": "true",
};
await dc.rpc.batchSetConfig(accountId, config);
const retrieved = await dc.rpc.batchGetConfig(
accountId,
Object.keys(config)
);
const retrieved = await dc.rpc.batchGetConfig(accountId, Object.keys(config));
expect(retrieved).to.deep.equal(config);
});
it("set and retrive mixed(ui and core) (batch)", async function () {
@@ -148,10 +145,7 @@ describe("basic tests", () => {
mail_pw: "123456",
};
await dc.rpc.batchSetConfig(accountId, config);
const retrieved = await dc.rpc.batchGetConfig(
accountId,
Object.keys(config)
);
const retrieved = await dc.rpc.batchGetConfig(accountId, Object.keys(config));
expect(retrieved).to.deep.equal(config);
});
});

View File

@@ -97,8 +97,7 @@ describe("online tests", function () {
const messageList = await dc.rpc.getMessageIds(
accountId2,
chatIdOnAccountB,
false,
false
0
);
expect(messageList).have.length(1);
@@ -134,8 +133,7 @@ describe("online tests", function () {
const messageList = await dc.rpc.getMessageIds(
accountId2,
chatIdOnAccountB,
false,
false
0
);
const message = await dc.rpc.getMessage(
accountId2,
@@ -152,7 +150,7 @@ describe("online tests", function () {
await eventPromise2;
const messageId = (
await dc.rpc.getMessageIds(accountId1, chatId, false, false)
await dc.rpc.getMessageIds(accountId1, chatId, 0)
).reverse()[0];
const message2 = await dc.rpc.getMessage(accountId1, messageId);
expect(message2.text).equal("super secret message");

View File

@@ -59,13 +59,13 @@ export async function startServer(): Promise<RpcServerHandle> {
export async function createTempUser(url: string) {
const response = await fetch(url, {
method: "POST",
method: "POST",
headers: {
"cache-control": "no-cache",
},
});
if (!response.ok) throw new Error("Received invalid response");
return response.json();
if (!response.ok) throw new Error('Received invalid response')
return response.json();
}
function getTargetDir(): Promise<string> {
@@ -89,3 +89,4 @@ function getTargetDir(): Promise<string> {
);
});
}

View File

@@ -1,8 +0,0 @@
[package]
name = "ratelimit"
version = "1.0.0"
description = "Token bucket implementation"
edition = "2021"
license = "MPL-2.0"
[dependencies]

View File

@@ -1,19 +0,0 @@
[package]
name = "deltachat-repl"
version = "1.108.0"
edition = "2021"
[dependencies]
ansi_term = "0.12.1"
anyhow = "1"
deltachat = { path = "..", features = ["internals"]}
dirs = "4"
log = "0.4.16"
pretty_env_logger = "0.4"
rusqlite = "0.28"
rustyline = "10"
tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] }
[features]
default = ["vendored"]
vendored = ["deltachat/vendored"]

View File

@@ -27,7 +27,9 @@ async def log_error(event):
@hooks.on(events.MemberListChanged)
async def on_memberlist_changed(event):
logging.info("member %s was %s", event.member, "added" if event.member_added else "removed")
logging.info(
"member %s was %s", event.member, "added" if event.member_added else "removed"
)
@hooks.on(events.GroupImageChanged)
@@ -64,8 +66,7 @@ async def main():
bot = Bot(account, hooks)
if not await bot.is_configured():
# Save a reference to avoid garbage collection of the task.
_configure_task = asyncio.create_task(bot.configure(email=sys.argv[1], password=sys.argv[2]))
asyncio.create_task(bot.configure(email=sys.argv[1], password=sys.argv[2]))
await bot.run_forever()

View File

@@ -32,7 +32,7 @@ async def main():
async def process_messages():
for message in await account.get_fresh_messages_in_arrival_order():
snapshot = await message.get_snapshot()
if not snapshot.is_bot and not snapshot.is_info:
if not snapshot.is_info:
await snapshot.chat.send_text(snapshot.text)
await snapshot.message.mark_seen()

View File

@@ -13,6 +13,13 @@ dynamic = [
"version"
]
[tool.setuptools]
# We declare the package not-zip-safe so that our type hints are also available
# when checking client code that uses our (installed) package.
# Ref:
# https://mypy.readthedocs.io/en/stable/installed_packages.html?highlight=zip#using-installed-packages-with-mypy-pep-561
zip-safe = false
[tool.setuptools.package-data]
deltachat_rpc_client = [
"py.typed"
@@ -20,13 +27,3 @@ deltachat_rpc_client = [
[project.entry-points.pytest11]
"deltachat_rpc_client.pytestplugin" = "deltachat_rpc_client.pytestplugin"
[tool.black]
line-length = 120
[tool.ruff]
select = ["E", "F", "W", "N", "YTT", "B", "C4", "ISC", "ICN", "PT", "RET", "SIM", "TID", "ARG", "DTZ", "ERA", "PLC", "PLE", "PLW", "PIE", "COM"]
line-length = 120
[tool.isort]
profile = "black"

View File

@@ -8,18 +8,3 @@ from .contact import Contact
from .deltachat import DeltaChat
from .message import Message
from .rpc import Rpc
__all__ = [
"Account",
"AttrDict",
"Bot",
"Chat",
"Client",
"Contact",
"DeltaChat",
"EventType",
"Message",
"Rpc",
"run_bot_cli",
"run_client_cli",
]

View File

@@ -30,7 +30,12 @@ class AttrDict(dict):
"""Dictionary that allows accessing values usin the "dot notation" as attributes."""
def __init__(self, *args, **kwargs) -> None:
super().__init__({_camel_to_snake(key): _to_attrdict(value) for key, value in dict(*args, **kwargs).items()})
super().__init__(
{
_camel_to_snake(key): _to_attrdict(value)
for key, value in dict(*args, **kwargs).items()
}
)
def __getattr__(self, attr):
if attr in self:
@@ -46,7 +51,7 @@ class AttrDict(dict):
async def run_client_cli(
hooks: Optional[Iterable[Tuple[Callable, Union[type, "EventFilter"]]]] = None,
argv: Optional[list] = None,
**kwargs,
**kwargs
) -> None:
"""Run a simple command line app, using the given hooks.
@@ -60,7 +65,7 @@ async def run_client_cli(
async def run_bot_cli(
hooks: Optional[Iterable[Tuple[Callable, Union[type, "EventFilter"]]]] = None,
argv: Optional[list] = None,
**kwargs,
**kwargs
) -> None:
"""Run a simple bot command line using the given hooks.
@@ -75,7 +80,7 @@ async def _run_cli(
client_type: Type["Client"],
hooks: Optional[Iterable[Tuple[Callable, Union[type, "EventFilter"]]]] = None,
argv: Optional[list] = None,
**kwargs,
**kwargs
) -> None:
from .deltachat import DeltaChat
from .rpc import Rpc
@@ -102,10 +107,12 @@ async def _run_cli(
client = client_type(account, hooks)
client.logger.debug("Running deltachat core %s", core_version)
if not await client.is_configured():
assert args.email, "Account is not configured and email must be provided"
assert args.password, "Account is not configured and password must be provided"
# Save a reference to avoid garbage collection of the task.
_configure_task = asyncio.create_task(client.configure(email=args.email, password=args.password))
assert (
args.email and args.password
), "Account is not configured and email and password must be provided"
asyncio.create_task(
client.configure(email=args.email, password=args.password)
)
await client.run_forever()

View File

@@ -1,5 +1,4 @@
from typing import TYPE_CHECKING, List, Optional, Tuple, Union
from dataclasses import dataclass
from ._utils import AttrDict
from .chat import Chat
@@ -12,17 +11,28 @@ if TYPE_CHECKING:
from .deltachat import DeltaChat
@dataclass
class Account:
"""Delta Chat account."""
manager: "DeltaChat"
id: int
def __init__(self, manager: "DeltaChat", account_id: int) -> None:
self.manager = manager
self.id = account_id
@property
def _rpc(self) -> Rpc:
return self.manager.rpc
def __eq__(self, other) -> bool:
if not isinstance(other, Account):
return False
return self.id == other.id and self.manager == other.manager
def __ne__(self, other) -> bool:
return not self == other
def __repr__(self) -> str:
return f"<Account id={self.id}>"
async def wait_for_event(self) -> AttrDict:
"""Wait until the next event and return it."""
return AttrDict(await self._rpc.wait_for_event(self.id))
@@ -79,7 +89,9 @@ class Account:
"""Configure an account."""
await self._rpc.configure(self.id)
async def create_contact(self, obj: Union[int, str, Contact], name: Optional[str] = None) -> Contact:
async def create_contact(
self, obj: Union[int, str, Contact], name: Optional[str] = None
) -> Contact:
"""Create a new Contact or return an existing one.
Calling this method will always result in the same
@@ -108,7 +120,10 @@ class Account:
async def get_blocked_contacts(self) -> List[AttrDict]:
"""Return a list with snapshots of all blocked contacts."""
contacts = await self._rpc.get_blocked_contacts(self.id)
return [AttrDict(contact=Contact(self, contact["id"]), **contact) for contact in contacts]
return [
AttrDict(contact=Contact(self, contact["id"]), **contact)
for contact in contacts
]
async def get_contacts(
self,
@@ -133,7 +148,10 @@ class Account:
if snapshot:
contacts = await self._rpc.get_contacts(self.id, flags, query)
return [AttrDict(contact=Contact(self, contact["id"]), **contact) for contact in contacts]
return [
AttrDict(contact=Contact(self, contact["id"]), **contact)
for contact in contacts
]
contacts = await self._rpc.get_contact_ids(self.id, flags, query)
return [Contact(self, contact_id) for contact_id in contacts]
@@ -174,7 +192,9 @@ class Account:
if alldone_hint:
flags |= ChatlistFlag.ADD_ALLDONE_HINT
entries = await self._rpc.get_chatlist_entries(self.id, flags, query, contact and contact.id)
entries = await self._rpc.get_chatlist_entries(
self.id, flags, query, contact and contact.id
)
if not snapshot:
return [Chat(self, entry[0]) for entry in entries]

View File

@@ -1,7 +1,6 @@
import calendar
from datetime import datetime
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
from dataclasses import dataclass
from ._utils import AttrDict
from .const import ChatVisibility
@@ -13,17 +12,28 @@ if TYPE_CHECKING:
from .account import Account
@dataclass
class Chat:
"""Chat object which manages members and through which you can send and retrieve messages."""
account: "Account"
id: int
def __init__(self, account: "Account", chat_id: int) -> None:
self.account = account
self.id = chat_id
@property
def _rpc(self) -> Rpc:
return self.account._rpc
def __eq__(self, other) -> bool:
if not isinstance(other, Chat):
return False
return self.id == other.id and self.account == other.account
def __ne__(self, other) -> bool:
return not self == other
def __repr__(self) -> str:
return f"<Chat id={self.id} account={self.account.id}>"
async def delete(self) -> None:
"""Delete this chat and all its messages.
@@ -53,7 +63,7 @@ class Chat:
"""
if duration is not None:
assert duration > 0, "Invalid duration"
dur: Union[str, dict] = {"Until": duration}
dur: Union[str, dict] = dict(Until=duration)
else:
dur = "Forever"
await self._rpc.set_chat_mute_duration(self.account.id, self.id, dur)
@@ -64,19 +74,27 @@ class Chat:
async def pin(self) -> None:
"""Pin this chat."""
await self._rpc.set_chat_visibility(self.account.id, self.id, ChatVisibility.PINNED)
await self._rpc.set_chat_visibility(
self.account.id, self.id, ChatVisibility.PINNED
)
async def unpin(self) -> None:
"""Unpin this chat."""
await self._rpc.set_chat_visibility(self.account.id, self.id, ChatVisibility.NORMAL)
await self._rpc.set_chat_visibility(
self.account.id, self.id, ChatVisibility.NORMAL
)
async def archive(self) -> None:
"""Archive this chat."""
await self._rpc.set_chat_visibility(self.account.id, self.id, ChatVisibility.ARCHIVED)
await self._rpc.set_chat_visibility(
self.account.id, self.id, ChatVisibility.ARCHIVED
)
async def unarchive(self) -> None:
"""Unarchive this chat."""
await self._rpc.set_chat_visibility(self.account.id, self.id, ChatVisibility.NORMAL)
await self._rpc.set_chat_visibility(
self.account.id, self.id, ChatVisibility.NORMAL
)
async def set_name(self, name: str) -> None:
"""Set name of this chat."""
@@ -115,7 +133,9 @@ class Chat:
if isinstance(quoted_msg, Message):
quoted_msg = quoted_msg.id
msg_id, _ = await self._rpc.misc_send_msg(self.account.id, self.id, text, file, location, quoted_msg)
msg_id, _ = await self._rpc.misc_send_msg(
self.account.id, self.id, text, file, location, quoted_msg
)
return Message(self.account, msg_id)
async def send_text(self, text: str) -> Message:
@@ -164,9 +184,9 @@ class Chat:
snapshot["message"] = Message(self.account, snapshot.id)
return snapshot
async def get_messages(self, info_only: bool = False, add_daymarker: bool = False) -> List[Message]:
async def get_messages(self, flags: int = 0) -> List[Message]:
"""get the list of messages in this chat."""
msgs = await self._rpc.get_message_ids(self.account.id, self.id, info_only, add_daymarker)
msgs = await self._rpc.get_message_ids(self.account.id, self.id, flags)
return [Message(self.account, msg_id) for msg_id in msgs]
async def get_fresh_message_count(self) -> int:
@@ -221,17 +241,23 @@ class Chat:
timestamp_to: Optional[datetime] = None,
) -> List[AttrDict]:
"""Get list of location snapshots for the given contact in the given timespan."""
time_from = calendar.timegm(timestamp_from.utctimetuple()) if timestamp_from else 0
time_from = (
calendar.timegm(timestamp_from.utctimetuple()) if timestamp_from else 0
)
time_to = calendar.timegm(timestamp_to.utctimetuple()) if timestamp_to else 0
contact_id = contact.id if contact else 0
result = await self._rpc.get_locations(self.account.id, self.id, contact_id, time_from, time_to)
result = await self._rpc.get_locations(
self.account.id, self.id, contact_id, time_from, time_to
)
locations = []
contacts: Dict[int, Contact] = {}
for loc in result:
loc = AttrDict(loc)
loc["chat"] = self
loc["contact"] = contacts.setdefault(loc.contact_id, Contact(self.account, loc.contact_id))
loc["contact"] = contacts.setdefault(
loc.contact_id, Contact(self.account, loc.contact_id)
)
loc["message"] = Message(self.account, loc.msg_id)
locations.append(loc)
return locations

View File

@@ -47,11 +47,15 @@ class Client:
self._should_process_messages = 0
self.add_hooks(hooks or [])
def add_hooks(self, hooks: Iterable[Tuple[Callable, Union[type, EventFilter]]]) -> None:
def add_hooks(
self, hooks: Iterable[Tuple[Callable, Union[type, EventFilter]]]
) -> None:
for hook, event in hooks:
self.add_hook(hook, event)
def add_hook(self, hook: Callable, event: Union[type, EventFilter] = RawEvent) -> None:
def add_hook(
self, hook: Callable, event: Union[type, EventFilter] = RawEvent
) -> None:
"""Register hook for the given event filter."""
if isinstance(event, type):
event = event()
@@ -60,7 +64,7 @@ class Client:
isinstance(
event,
(NewMessage, MemberListChanged, GroupImageChanged, GroupNameChanged),
),
)
)
self._hooks.setdefault(type(event), set()).add((hook, event))
@@ -72,7 +76,7 @@ class Client:
isinstance(
event,
(NewMessage, MemberListChanged, GroupImageChanged, GroupNameChanged),
),
)
)
self._hooks.get(type(event), set()).remove((hook, event))
@@ -91,7 +95,9 @@ class Client:
"""Process events forever."""
await self.run_until(lambda _: False)
async def run_until(self, func: Callable[[AttrDict], Union[bool, Coroutine]]) -> AttrDict:
async def run_until(
self, func: Callable[[AttrDict], Union[bool, Coroutine]]
) -> AttrDict:
"""Process events until the given callable evaluates to True.
The callable should accept an AttrDict object representing the
@@ -116,7 +122,9 @@ class Client:
if stop:
return event
async def _on_event(self, event: AttrDict, filter_type: Type[EventFilter] = RawEvent) -> None:
async def _on_event(
self, event: AttrDict, filter_type: Type[EventFilter] = RawEvent
) -> None:
for hook, evfilter in self._hooks.get(filter_type, []):
if await evfilter.filter(event):
try:
@@ -125,7 +133,11 @@ class Client:
self.logger.exception(ex)
async def _parse_command(self, event: AttrDict) -> None:
cmds = [hook[1].command for hook in self._hooks.get(NewMessage, []) if hook[1].command]
cmds = [
hook[1].command
for hook in self._hooks.get(NewMessage, [])
if hook[1].command
]
parts = event.message_snapshot.text.split(maxsplit=1)
payload = parts[1] if len(parts) > 1 else ""
cmd = parts.pop(0)
@@ -190,7 +202,11 @@ class Client:
for message in await self.account.get_fresh_messages_in_arrival_order():
snapshot = await message.get_snapshot()
await self._on_new_msg(snapshot)
if snapshot.is_info and snapshot.system_message_type != SystemMessageType.WEBXDC_INFO_MESSAGE:
if (
snapshot.is_info
and snapshot.system_message_type
!= SystemMessageType.WEBXDC_INFO_MESSAGE
):
await self._handle_info_msg(snapshot)
await snapshot.message.mark_seen()

View File

@@ -1,5 +1,4 @@
from typing import TYPE_CHECKING
from dataclasses import dataclass
from ._utils import AttrDict
from .rpc import Rpc
@@ -9,7 +8,6 @@ if TYPE_CHECKING:
from .chat import Chat
@dataclass
class Contact:
"""
Contact API.
@@ -17,8 +15,20 @@ class Contact:
Essentially a wrapper for RPC, account ID and a contact ID.
"""
account: "Account"
id: int
def __init__(self, account: "Account", contact_id: int) -> None:
self.account = account
self.id = contact_id
def __eq__(self, other) -> bool:
if not isinstance(other, Contact):
return False
return self.id == other.id and self.account == other.account
def __ne__(self, other) -> bool:
return not self == other
def __repr__(self) -> str:
return f"<Contact id={self.id} account={self.account.id}>"
@property
def _rpc(self) -> Rpc:

View File

@@ -10,7 +10,7 @@ from .const import EventType
def _tuple_of(obj, type_: type) -> tuple:
if not obj:
return ()
return tuple()
if isinstance(obj, type_):
obj = (obj,)
@@ -39,7 +39,7 @@ class EventFilter(ABC):
"""Return True if two event filters are equal."""
def __ne__(self, other):
return not self == other
return not self.__eq__(other)
async def _call_func(self, event) -> bool:
if not self.func:
@@ -65,7 +65,9 @@ class RawEvent(EventFilter):
should be dispatched or not.
"""
def __init__(self, types: Union[None, EventType, Iterable[EventType]] = None, **kwargs):
def __init__(
self, types: Union[None, EventType, Iterable[EventType]] = None, **kwargs
):
super().__init__(**kwargs)
try:
self.types = _tuple_of(types, EventType)
@@ -96,9 +98,6 @@ class NewMessage(EventFilter):
content.
:param command: If set, only match messages with the given command (ex. /help).
Setting this property implies `is_info==False`.
:param is_bot: If set to True only match messages sent by bots, if set to None
match messages from bots and users. If omitted or set to False
only messages from users will be matched.
:param is_info: If set to True only match info/system messages, if set to False
only match messages that are not info/system messages. If omitted
info/system messages as well as normal messages will be matched.
@@ -116,12 +115,10 @@ class NewMessage(EventFilter):
re.Pattern,
] = None,
command: Optional[str] = None,
is_bot: Optional[bool] = False,
is_info: Optional[bool] = None,
func: Optional[Callable[[AttrDict], bool]] = None,
) -> None:
super().__init__(func=func)
self.is_bot = is_bot
self.is_info = is_info
if command is not None and not isinstance(command, str):
raise TypeError("Invalid command")
@@ -138,28 +135,19 @@ class NewMessage(EventFilter):
raise TypeError("Invalid pattern type")
def __hash__(self) -> int:
return hash((self.pattern, self.command, self.is_bot, self.is_info, self.func))
return hash((self.pattern, self.func))
def __eq__(self, other) -> bool:
if isinstance(other, NewMessage):
return (
self.pattern,
self.command,
self.is_bot,
self.is_info,
self.func,
) == (
return (self.pattern, self.command, self.is_info, self.func) == (
other.pattern,
other.command,
other.is_bot,
other.is_info,
other.func,
)
return False
async def filter(self, event: AttrDict) -> bool:
if self.is_bot is not None and self.is_bot != event.message_snapshot.is_bot:
return False
if self.is_info is not None and self.is_info != event.message_snapshot.is_info:
return False
if self.command and self.command != event.command:

View File

@@ -1,6 +1,5 @@
import json
from typing import TYPE_CHECKING, Union
from dataclasses import dataclass
from ._utils import AttrDict
from .contact import Contact
@@ -10,12 +9,23 @@ if TYPE_CHECKING:
from .account import Account
@dataclass
class Message:
"""Delta Chat Message object."""
account: "Account"
id: int
def __init__(self, account: "Account", msg_id: int) -> None:
self.account = account
self.id = msg_id
def __eq__(self, other) -> bool:
if not isinstance(other, Message):
return False
return self.id == other.id and self.account == other.account
def __ne__(self, other) -> bool:
return not self == other
def __repr__(self) -> str:
return f"<Message id={self.id} account={self.account.id}>"
@property
def _rpc(self) -> Rpc:
@@ -39,14 +49,22 @@ class Message:
"""Mark the message as seen."""
await self._rpc.markseen_msgs(self.account.id, [self.id])
async def send_webxdc_status_update(self, update: Union[dict, str], description: str) -> None:
async def send_webxdc_status_update(
self, update: Union[dict, str], description: str
) -> None:
"""Send a webxdc status update. This message must be a webxdc."""
if not isinstance(update, str):
update = json.dumps(update)
await self._rpc.send_webxdc_status_update(self.account.id, self.id, update, description)
await self._rpc.send_webxdc_status_update(
self.account.id, self.id, update, description
)
async def get_webxdc_status_updates(self, last_known_serial: int = 0) -> list:
return json.loads(await self._rpc.get_webxdc_status_updates(self.account.id, self.id, last_known_serial))
return json.loads(
await self._rpc.get_webxdc_status_updates(
self.account.id, self.id, last_known_serial
)
)
async def get_webxdc_info(self) -> dict:
return await self._rpc.get_webxdc_info(self.account.id, self.id)

View File

@@ -2,7 +2,6 @@ import json
import os
from typing import AsyncGenerator, List, Optional
import asyncio
import aiohttp
import pytest_asyncio
@@ -52,13 +51,11 @@ class ACFactory:
await bot.configure(credentials["email"], credentials["password"])
return bot
async def get_online_account(self) -> Account:
account = await self.new_configured_account()
await account.start_io()
return account
async def get_online_accounts(self, num: int) -> List[Account]:
return await asyncio.gather(*[self.get_online_account() for _ in range(num)])
accounts = [await self.new_configured_account() for _ in range(num)]
for account in accounts:
await account.start_io()
return accounts
async def send_message(
self,
@@ -70,7 +67,9 @@ class ACFactory:
) -> Message:
if not from_account:
from_account = (await self.get_online_accounts(1))[0]
to_contact = await from_account.create_contact(await to_account.get_config("addr"))
to_contact = await from_account.create_contact(
await to_account.get_config("addr")
)
if group:
to_chat = await from_account.create_group(group)
await to_chat.add_contact(to_contact)

View File

@@ -30,7 +30,7 @@ class Rpc:
"deltachat-rpc-server",
stdin=asyncio.subprocess.PIPE,
stdout=asyncio.subprocess.PIPE,
**self._kwargs,
**self._kwargs
)
self.id = 0
self.event_queues = {}
@@ -46,7 +46,7 @@ class Rpc:
await self.start()
return self
async def __aexit__(self, _exc_type, _exc, _tb):
async def __aexit__(self, exc_type, exc, tb):
await self.close()
async def reader_loop(self) -> None:
@@ -97,6 +97,5 @@ class Rpc:
raise JsonRpcError(response["error"])
if "result" in response:
return response["result"]
return None
return method

View File

@@ -1,31 +1,19 @@
from unittest.mock import MagicMock
import pytest
import asyncio
from deltachat_rpc_client import EventType, events
from deltachat_rpc_client.rpc import JsonRpcError
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_system_info(rpc) -> None:
system_info = await rpc.get_system_info()
assert "arch" in system_info
assert "deltachat_core_version" in system_info
@pytest.mark.asyncio()
async def test_sleep(rpc) -> None:
"""Test that long-running task does not block short-running task from completion."""
sleep_5_task = asyncio.create_task(rpc.sleep(5.0))
sleep_3_task = asyncio.create_task(rpc.sleep(3.0))
done, pending = await asyncio.wait([sleep_5_task, sleep_3_task], return_when=asyncio.FIRST_COMPLETED)
assert sleep_3_task in done
assert sleep_5_task in pending
sleep_5_task.cancel()
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_email_address_validity(rpc) -> None:
valid_addresses = [
"email@example.com",
@@ -39,7 +27,7 @@ async def test_email_address_validity(rpc) -> None:
assert not await rpc.check_email_validity(addr)
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_acfactory(acfactory) -> None:
account = await acfactory.new_configured_account()
while True:
@@ -53,18 +41,17 @@ async def test_acfactory(acfactory) -> None:
print("Successful configuration")
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_configure_starttls(acfactory) -> None:
account = await acfactory.new_preconfigured_account()
# Use STARTTLS
await account.set_config("mail_security", "2")
await account.set_config("send_security", "2")
await account.configure()
assert await account.is_configured()
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_account(acfactory) -> None:
alice, bob = await acfactory.get_online_accounts(2)
@@ -124,7 +111,7 @@ async def test_account(acfactory) -> None:
await alice.stop_io()
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_chat(acfactory) -> None:
alice, bob = await acfactory.get_online_accounts(2)
@@ -190,7 +177,7 @@ async def test_chat(acfactory) -> None:
await group.get_locations()
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_contact(acfactory) -> None:
alice, bob = await acfactory.get_online_accounts(2)
@@ -208,7 +195,7 @@ async def test_contact(acfactory) -> None:
await alice_contact_bob.create_chat()
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_message(acfactory) -> None:
alice, bob = await acfactory.get_online_accounts(2)
@@ -228,7 +215,6 @@ async def test_message(acfactory) -> None:
snapshot = await message.get_snapshot()
assert snapshot.chat_id == chat_id
assert snapshot.text == "Hello!"
assert not snapshot.is_bot
assert repr(message)
with pytest.raises(JsonRpcError): # chat is not accepted
@@ -240,67 +226,44 @@ async def test_message(acfactory) -> None:
await message.send_reaction("😎")
@pytest.mark.asyncio()
async def test_is_bot(acfactory) -> None:
"""Test that we can recognize messages submitted by bots."""
alice, bob = await acfactory.get_online_accounts(2)
bob_addr = await bob.get_config("addr")
alice_contact_bob = await alice.create_contact(bob_addr, "Bob")
alice_chat_bob = await alice_contact_bob.create_chat()
# Alice becomes a bot.
await alice.set_config("bot", "1")
await alice_chat_bob.send_text("Hello!")
while True:
event = await bob.wait_for_event()
if event.type == EventType.INCOMING_MSG:
msg_id = event.msg_id
message = bob.get_message_by_id(msg_id)
snapshot = await message.get_snapshot()
assert snapshot.chat_id == event.chat_id
assert snapshot.text == "Hello!"
assert snapshot.is_bot
break
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_bot(acfactory) -> None:
mock = MagicMock()
user = (await acfactory.get_online_accounts(1))[0]
bot = await acfactory.new_configured_bot()
bot2 = await acfactory.new_configured_bot()
assert await bot.is_configured()
assert await bot.account.get_config("bot") == "1"
hook = lambda e: mock.hook(e.msg_id) and None, events.RawEvent(EventType.INCOMING_MSG)
hook = lambda e: mock.hook(e.msg_id), events.RawEvent(EventType.INCOMING_MSG)
bot.add_hook(*hook)
event = await acfactory.process_message(from_account=user, to_client=bot, text="Hello!")
snapshot = await bot.account.get_message_by_id(event.msg_id).get_snapshot()
assert not snapshot.is_bot
event = await acfactory.process_message(
from_account=user, to_client=bot, text="Hello!"
)
mock.hook.assert_called_once_with(event.msg_id)
bot.remove_hook(*hook)
def track(e):
mock.hook(e.message_snapshot.id)
track = lambda e: mock.hook(e.message_snapshot.id)
mock.hook.reset_mock()
hook = track, events.NewMessage(r"hello")
bot.add_hook(*hook)
bot.add_hook(track, events.NewMessage(command="/help"))
event = await acfactory.process_message(from_account=user, to_client=bot, text="hello")
event = await acfactory.process_message(
from_account=user, to_client=bot, text="hello"
)
mock.hook.assert_called_with(event.msg_id)
event = await acfactory.process_message(from_account=user, to_client=bot, text="hello!")
event = await acfactory.process_message(
from_account=user, to_client=bot, text="hello!"
)
mock.hook.assert_called_with(event.msg_id)
await acfactory.process_message(from_account=bot2.account, to_client=bot, text="hello")
assert len(mock.hook.mock_calls) == 2 # bot messages are ignored between bots
await acfactory.process_message(from_account=user, to_client=bot, text="hey!")
assert len(mock.hook.mock_calls) == 2
bot.remove_hook(*hook)
mock.hook.reset_mock()
await acfactory.process_message(from_account=user, to_client=bot, text="hello")
event = await acfactory.process_message(from_account=user, to_client=bot, text="/help")
event = await acfactory.process_message(
from_account=user, to_client=bot, text="/help"
)
mock.hook.assert_called_once_with(event.msg_id)

View File

@@ -3,14 +3,16 @@ import pytest
from deltachat_rpc_client import EventType
@pytest.mark.asyncio()
@pytest.mark.asyncio
async def test_webxdc(acfactory) -> None:
alice, bob = await acfactory.get_online_accounts(2)
bob_addr = await bob.get_config("addr")
alice_contact_bob = await alice.create_contact(bob_addr, "Bob")
alice_chat_bob = await alice_contact_bob.create_chat()
await alice_chat_bob.send_message(text="Let's play chess!", file="../test-data/webxdc/chess.xdc")
await alice_chat_bob.send_message(
text="Let's play chess!", file="../test-data/webxdc/chess.xdc"
)
while True:
event = await bob.wait_for_event()

View File

@@ -2,7 +2,6 @@
isolated_build = true
envlist =
py3
lint
[testenv]
commands =
@@ -17,13 +16,3 @@ deps =
pytest-asyncio
aiohttp
aiodns
[testenv:lint]
skipsdist = True
skip_install = True
deps =
ruff
black
commands =
black --check --diff src/ examples/ tests/
ruff src/ examples/ tests/

View File

@@ -1,6 +1,6 @@
[package]
name = "deltachat-rpc-server"
version = "1.108.0"
version = "1.106.0"
description = "DeltaChat JSON-RPC server"
edition = "2021"
readme = "README.md"
@@ -21,5 +21,5 @@ futures-lite = "1.12.0"
log = "0.4"
serde_json = "1.0.91"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.25.0", features = ["io-std"] }
yerpc = { version = "0.4.0", features = ["anyhow_expose"] }
tokio = { version = "1.23.1", features = ["io-std"] }
yerpc = { version = "0.3.1", features = ["anyhow_expose"] }

View File

@@ -1,31 +0,0 @@
# Delta Chat RPC server
This program provides a [JSON-RPC 2.0](https://www.jsonrpc.org/specification) interface to DeltaChat
over standard I/O.
## Install
To install run:
```sh
cargo install --path ../deltachat-rpc-server
```
The `deltachat-rpc-server` executable will be installed into `$HOME/.cargo/bin` that should be available
in your `PATH`.
## Usage
To use just run `deltachat-rpc-server` command. The accounts folder will be created in the current
working directory unless `DC_ACCOUNTS_PATH` is set:
```sh
export DC_ACCOUNTS_PATH=$HOME/delta/
deltachat-rpc-server
```
The common use case for this program is to create bindings to use Delta Chat core from programming
languages other than Rust, for example:
1. Python: https://github.com/deltachat/deltachat-core-rust/tree/master/deltachat-rpc-client/
2. Go: https://github.com/deltachat/deltachat-rpc-client-go/

View File

@@ -40,7 +40,7 @@ async fn main() -> Result<()> {
while let Some(message) = out_receiver.next().await {
let message = serde_json::to_string(&message)?;
log::trace!("RPC send {}", message);
println!("{message}");
println!("{}", message);
}
Ok(())
});
@@ -51,10 +51,7 @@ async fn main() -> Result<()> {
let mut lines = BufReader::new(stdin).lines();
while let Some(message) = lines.next_line().await? {
log::trace!("RPC recv {}", message);
let session = session.clone();
tokio::spawn(async move {
session.handle_incoming(&message).await;
});
session.handle_incoming(&message).await;
}
log::info!("EOF reached on stdin");
Ok(())

View File

@@ -1,9 +1,8 @@
#![recursion_limit = "128"]
extern crate proc_macro;
use quote::quote;
use crate::proc_macro::TokenStream;
use quote::quote;
// For now, assume (not check) that these macroses are applied to enum without
// data. If this assumption is violated, compiler error will point to

View File

@@ -31,7 +31,7 @@ use tokio::fs;
/// Argument is a bitmask, executing single or multiple actions in one call.
/// e.g. bitmask 7 triggers actions definded with bits 1, 2 and 4.
async fn reset_tables(context: &Context, bits: i32) {
println!("Resetting tables ({bits})...");
println!("Resetting tables ({})...", bits);
if 0 != bits & 1 {
context
.sql()
@@ -101,7 +101,7 @@ async fn poke_eml_file(context: &Context, filename: impl AsRef<Path>) -> Result<
let data = read_file(context, filename).await?;
if let Err(err) = receive_imf(context, &data, false).await {
println!("receive_imf errored: {err:?}");
println!("receive_imf errored: {:?}", err);
}
Ok(())
}
@@ -148,7 +148,7 @@ async fn poke_spec(context: &Context, spec: Option<&str>) -> bool {
let name = name_f.to_string_lossy();
if name.ends_with(".eml") {
let path_plus_name = format!("{}/{}", &real_spec, name);
println!("Import: {path_plus_name}");
println!("Import: {}", path_plus_name);
if poke_eml_file(context, path_plus_name).await.is_ok() {
read_cnt += 1
}
@@ -168,7 +168,7 @@ async fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
.await
.expect("invalid contact");
let contact_name = if let Some(name) = msg.get_override_sender_name() {
format!("~{name}")
format!("~{}", name)
} else {
contact.get_display_name().to_string()
};
@@ -223,7 +223,7 @@ async fn log_msg(context: &Context, prefix: impl AsRef<str>, msg: &Message) {
"[WEBXDC: {}, icon={}, document={}, summary={}, source_code_url={}]",
info.name, info.icon, info.document, info.summary, info.source_code_url
),
Err(err) => format!("[get_webxdc_info() failed: {err}]"),
Err(err) => format!("[get_webxdc_info() failed: {}]", err),
}
} else {
"".to_string()
@@ -435,9 +435,10 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
),
},
"initiate-key-transfer" => match initiate_key_transfer(&context).await {
Ok(setup_code) => {
println!("Setup code for the transferred setup message: {setup_code}",)
}
Ok(setup_code) => println!(
"Setup code for the transferred setup message: {}",
setup_code,
),
Err(err) => bail!("Failed to generate setup code: {}", err),
},
"get-setupcodebegin" => {
@@ -527,7 +528,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
ensure!(!arg1.is_empty(), "Argument <key> missing.");
let key = config::Config::from_str(arg1)?;
let val = context.get_config(key).await;
println!("{key}={val:?}");
println!("{}={:?}", key, val);
}
"info" => {
println!("{:#?}", context.get_info().await);
@@ -539,7 +540,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
match context.get_connectivity_html().await {
Ok(html) => {
fs::write(&file, html).await?;
println!("Report written to: {file:#?}");
println!("Report written to: {:#?}", file);
}
Err(err) => {
bail!("Failed to get connectivity html: {}", err);
@@ -612,7 +613,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
"{}{}{} [{}]{}",
summary
.prefix
.map_or_else(String::new, |prefix| format!("{prefix}: ")),
.map_or_else(String::new, |prefix| format!("{}: ", prefix)),
summary.text,
statestr,
&timestr,
@@ -630,8 +631,8 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
if location::is_sending_locations_to_chat(&context, None).await? {
println!("Location streaming enabled.");
}
println!("{cnt} chats");
println!("{time_needed:?} to create this list");
println!("{} chats", cnt);
println!("{:?} to create this list", time_needed);
}
"chat" => {
if sel_chat.is_none() && arg1.is_empty() {
@@ -639,7 +640,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
}
if !arg1.is_empty() {
let id = ChatId::new(arg1.parse()?);
println!("Selecting chat {id}");
println!("Selecting chat {}", id);
sel_chat = Some(Chat::load_from_db(&context, id).await?);
*chat_id = id;
}
@@ -648,15 +649,8 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let sel_chat = sel_chat.as_ref().unwrap();
let time_start = std::time::SystemTime::now();
let msglist = chat::get_chat_msgs_ex(
&context,
sel_chat.get_id(),
chat::MessageListOptions {
info_only: false,
add_daymarker: true,
},
)
.await?;
let msglist =
chat::get_chat_msgs(&context, sel_chat.get_id(), DC_GCM_ADDDAYMARKER).await?;
let time_needed = time_start.elapsed().unwrap_or_default();
let msglist: Vec<MsgId> = msglist
@@ -692,7 +686,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
},
match sel_chat.get_profile_image(&context).await? {
Some(icon) => match icon.to_str() {
Some(icon) => format!(" Icon: {icon}"),
Some(icon) => format!(" Icon: {}", icon),
_ => " Icon: Err".to_string(),
},
_ => "".to_string(),
@@ -718,7 +712,8 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let time_noticed_needed = time_noticed_start.elapsed().unwrap_or_default();
println!(
"{time_needed:?} to create this list, {time_noticed_needed:?} to mark all messages as noticed."
"{:?} to create this list, {:?} to mark all messages as noticed.",
time_needed, time_noticed_needed
);
}
"createchat" => {
@@ -726,26 +721,26 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let contact_id = ContactId::new(arg1.parse()?);
let chat_id = ChatId::create_for_contact(&context, contact_id).await?;
println!("Single#{chat_id} created successfully.",);
println!("Single#{} created successfully.", chat_id,);
}
"creategroup" => {
ensure!(!arg1.is_empty(), "Argument <name> missing.");
let chat_id =
chat::create_group_chat(&context, ProtectionStatus::Unprotected, arg1).await?;
println!("Group#{chat_id} created successfully.");
println!("Group#{} created successfully.", chat_id);
}
"createbroadcast" => {
let chat_id = chat::create_broadcast_list(&context).await?;
println!("Broadcast#{chat_id} created successfully.");
println!("Broadcast#{} created successfully.", chat_id);
}
"createprotected" => {
ensure!(!arg1.is_empty(), "Argument <name> missing.");
let chat_id =
chat::create_group_chat(&context, ProtectionStatus::Protected, arg1).await?;
println!("Group#{chat_id} created and protected successfully.");
println!("Group#{} created and protected successfully.", chat_id);
}
"addmember" => {
ensure!(sel_chat.is_some(), "No chat selected");
@@ -775,7 +770,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
chat::set_chat_name(
&context,
sel_chat.as_ref().unwrap().get_id(),
format!("{arg1} {arg2}").trim(),
format!("{} {}", arg1, arg2).trim(),
)
.await?;
@@ -879,7 +874,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
ensure!(sel_chat.is_some(), "No chat selected.");
ensure!(!arg1.is_empty(), "No message text given.");
let msg = format!("{arg1} {arg2}");
let msg = format!("{} {}", arg1, arg2);
chat::send_text_msg(&context, sel_chat.as_ref().unwrap().get_id(), msg).await?;
}
@@ -921,7 +916,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
chat::send_msg(&context, sel_chat.as_ref().unwrap().get_id(), &mut msg).await?;
}
"sendsyncmsg" => match context.send_sync_msg().await? {
Some(msg_id) => println!("sync message sent as {msg_id}."),
Some(msg_id) => println!("sync message sent as {}.", msg_id),
None => println!("sync message not needed."),
},
"sendupdate" => {
@@ -941,7 +936,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
"listmsgs" => {
ensure!(!arg1.is_empty(), "Argument <query> missing.");
let query = format!("{arg1} {arg2}").trim().to_string();
let query = format!("{} {}", arg1, arg2).trim().to_string();
let chat = sel_chat.as_ref().map(|sel_chat| sel_chat.get_id());
let time_start = std::time::SystemTime::now();
let msglist = context.search_msgs(chat, &query).await?;
@@ -959,7 +954,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
},
query,
);
println!("{time_needed:?} to create this list");
println!("{:?} to create this list", time_needed);
}
"draft" => {
ensure!(sel_chat.is_some(), "No chat selected.");
@@ -1005,9 +1000,9 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
println!("{} images or videos: ", images.len());
for (i, data) in images.iter().enumerate() {
if 0 == i {
print!("{data}");
print!("{}", data);
} else {
print!(", {data}");
print!(", {}", data);
}
}
println!();
@@ -1078,12 +1073,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
let id = MsgId::new(arg1.parse()?);
let res = message::get_msg_info(&context, id).await?;
println!("{res}");
println!("{}", res);
}
"download" => {
ensure!(!arg1.is_empty(), "Argument <msg-id> missing.");
let id = MsgId::new(arg1.parse()?);
println!("Scheduling download for {id:?}");
println!("Scheduling download for {:?}", id);
id.download_full(&context).await?;
}
"html" => {
@@ -1094,7 +1089,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
.join(format!("msg-{}.html", id.to_u32()));
let html = id.get_html(&context).await?.unwrap_or_default();
fs::write(&file, html).await?;
println!("HTML written to: {file:#?}");
println!("HTML written to: {:#?}", file);
}
"listfresh" => {
let msglist = context.get_fresh_msgs().await?;
@@ -1156,7 +1151,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
ensure!(!arg1.is_empty(), "Arguments [<name>] <addr> expected.");
if !arg2.is_empty() {
let book = format!("{arg1}\n{arg2}");
let book = format!("{}\n{}", arg1, arg2);
Contact::add_address_book(&context, &book).await?;
} else {
Contact::create(&context, "", arg1).await?;
@@ -1183,7 +1178,10 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let chatlist = Chatlist::try_load(&context, 0, None, Some(contact_id)).await?;
let chatlist_cnt = chatlist.len();
if chatlist_cnt > 0 {
res += &format!("\n\n{chatlist_cnt} chats shared with Contact#{contact_id}: ",);
res += &format!(
"\n\n{} chats shared with Contact#{}: ",
chatlist_cnt, contact_id,
);
for i in 0..chatlist_cnt {
if 0 != i {
res += ", ";
@@ -1193,7 +1191,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
}
}
println!("{res}");
println!("{}", res);
}
"delcontact" => {
ensure!(!arg1.is_empty(), "Argument <contact-id> missing.");
@@ -1217,13 +1215,13 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
"checkqr" => {
ensure!(!arg1.is_empty(), "Argument <qr-content> missing.");
let qr = check_qr(&context, arg1).await?;
println!("qr={qr:?}");
println!("qr={:?}", qr);
}
"setqr" => {
ensure!(!arg1.is_empty(), "Argument <qr-content> missing.");
match set_config_from_qr(&context, arg1).await {
Ok(()) => println!("Config set from QR code, you can now call 'configure'"),
Err(err) => println!("Cannot set config from QR code: {err:?}"),
Err(err) => println!("Cannot set config from QR code: {:?}", err),
}
}
"providerinfo" => {
@@ -1233,7 +1231,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
.await?;
match provider::get_provider_info(&context, arg1, socks5_enabled).await {
Some(info) => {
println!("Information for provider belonging to {arg1}:");
println!("Information for provider belonging to {}:", arg1);
println!("status: {}", info.status as u32);
println!("before_login_hint: {}", info.before_login_hint);
println!("after_login_hint: {}", info.after_login_hint);
@@ -1243,7 +1241,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
}
}
None => {
println!("No information for provider belonging to {arg1} found.");
println!("No information for provider belonging to {} found.", arg1);
}
}
}
@@ -1252,7 +1250,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
if let Ok(buf) = read_file(&context, &arg1).await {
let (width, height) = get_filemeta(&buf)?;
println!("width={width}, height={height}");
println!("width={}, height={}", width, height);
} else {
bail!("Command failed.");
}
@@ -1263,7 +1261,8 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
let device_cnt = message::estimate_deletion_cnt(&context, false, seconds).await?;
let server_cnt = message::estimate_deletion_cnt(&context, true, seconds).await?;
println!(
"estimated count of messages older than {seconds} seconds:\non device: {device_cnt}\non server: {server_cnt}"
"estimated count of messages older than {} seconds:\non device: {}\non server: {}",
seconds, device_cnt, server_cnt
);
}
"" => (),

View File

@@ -67,7 +67,8 @@ fn receive_event(event: EventType) {
info!(
"{}",
yellow.paint(format!(
"Received MSGS_CHANGED(chat_id={chat_id}, msg_id={msg_id})",
"Received MSGS_CHANGED(chat_id={}, msg_id={})",
chat_id, msg_id,
))
);
}
@@ -79,7 +80,8 @@ fn receive_event(event: EventType) {
info!(
"{}",
yellow.paint(format!(
"Received REACTIONS_CHANGED(chat_id={chat_id}, msg_id={msg_id}, contact_id={contact_id})"
"Received REACTIONS_CHANGED(chat_id={}, msg_id={}, contact_id={})",
chat_id, msg_id, contact_id
))
);
}
@@ -89,7 +91,7 @@ fn receive_event(event: EventType) {
EventType::LocationChanged(contact) => {
info!(
"{}",
yellow.paint(format!("Received LOCATION_CHANGED(contact={contact:?})"))
yellow.paint(format!("Received LOCATION_CHANGED(contact={:?})", contact))
);
}
EventType::ConfigureProgress { progress, comment } => {
@@ -97,20 +99,21 @@ fn receive_event(event: EventType) {
info!(
"{}",
yellow.paint(format!(
"Received CONFIGURE_PROGRESS({progress} ‰, {comment})"
"Received CONFIGURE_PROGRESS({} ‰, {})",
progress, comment
))
);
} else {
info!(
"{}",
yellow.paint(format!("Received CONFIGURE_PROGRESS({progress} ‰)"))
yellow.paint(format!("Received CONFIGURE_PROGRESS({} ‰)", progress))
);
}
}
EventType::ImexProgress(progress) => {
info!(
"{}",
yellow.paint(format!("Received IMEX_PROGRESS({progress} ‰)"))
yellow.paint(format!("Received IMEX_PROGRESS({} ‰)", progress))
);
}
EventType::ImexFileWritten(file) => {
@@ -122,7 +125,7 @@ fn receive_event(event: EventType) {
EventType::ChatModified(chat) => {
info!(
"{}",
yellow.paint(format!("Received CHAT_MODIFIED({chat})"))
yellow.paint(format!("Received CHAT_MODIFIED({})", chat))
);
}
_ => {
@@ -359,7 +362,7 @@ async fn start(args: Vec<String>) -> Result<(), Error> {
false
}
Err(err) => {
println!("Error: {err}");
println!("Error: {}", err);
true
}
}
@@ -374,7 +377,7 @@ async fn start(args: Vec<String>) -> Result<(), Error> {
break;
}
Err(err) => {
println!("Error: {err}");
println!("Error: {}", err);
break;
}
}
@@ -441,7 +444,7 @@ async fn handle_cmd(
if arg0 == "getbadqr" && qr.len() > 40 {
qr.replace_range(12..22, "0000000000")
}
println!("{qr}");
println!("{}", qr);
let output = Command::new("qrencode")
.args(["-t", "ansiutf8", qr.as_str(), "-o", "-"])
.output()
@@ -457,7 +460,7 @@ async fn handle_cmd(
match get_securejoin_qr_svg(&ctx, group).await {
Ok(svg) => {
fs::write(&file, svg).await?;
println!("QR code svg written to: {file:#?}");
println!("QR code svg written to: {:#?}", file);
}
Err(err) => {
bail!("Failed to get QR code svg: {}", err);

View File

@@ -1,3 +1,5 @@
use tempfile::tempdir;
use deltachat::chat::{self, ChatId};
use deltachat::chatlist::*;
use deltachat::config;
@@ -6,7 +8,6 @@ use deltachat::context::*;
use deltachat::message::Message;
use deltachat::stock_str::StockStrings;
use deltachat::{EventType, Events};
use tempfile::tempdir;
fn cb(event: EventType) {
match event {
@@ -28,7 +29,7 @@ fn cb(event: EventType) {
}
}
/// Run with `RUST_LOG=simple=info cargo run --release --example simple -- email pw`.
/// Run with `RUST_LOG=simple=info cargo run --release --example simple --features repl -- email pw`.
#[tokio::main]
async fn main() {
pretty_env_logger::try_init_timed().ok();
@@ -74,7 +75,7 @@ async fn main() {
for i in 0..1 {
log::info!("sending message {}", i);
chat::send_text_msg(&ctx, chat_id, format!("Hi, here is my {i}nth message!"))
chat::send_text_msg(&ctx, chat_id, format!("Hi, here is my {}nth message!", i))
.await
.unwrap();
}

83
fuzz/Cargo.lock generated
View File

@@ -141,18 +141,21 @@ dependencies = [
[[package]]
name = "async-smtp"
version = "0.8.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7384febcabdd07a498c9f4fbaa7e488ff4eb60d0ade14b47b09ec44b8f645301"
checksum = "6da21e1dd19fbad3e095ad519fb1558ab77fd82e5c4778dca8f9be0464589e1e"
dependencies = [
"anyhow",
"async-native-tls",
"async-trait",
"base64 0.13.1",
"bufstream",
"fast-socks5",
"futures",
"hostname",
"log",
"nom 7.1.1",
"pin-project",
"pin-utils",
"thiserror",
"tokio",
]
@@ -232,9 +235,9 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8"
[[package]]
name = "base64"
version = "0.21.0"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5"
[[package]]
name = "base64ct"
@@ -696,7 +699,7 @@ checksum = "23d8666cb01533c39dde32bcbab8e227b4ed6679b2c925eba05feabea39508fb"
[[package]]
name = "deltachat"
version = "1.107.0"
version = "1.104.0"
dependencies = [
"anyhow",
"async-channel",
@@ -705,7 +708,7 @@ dependencies = [
"async-smtp",
"async_zip",
"backtrace",
"base64 0.21.0",
"base64 0.20.0",
"bitflags",
"chrono",
"deltachat_derive",
@@ -735,7 +738,6 @@ dependencies = [
"r2d2",
"r2d2_sqlite",
"rand 0.8.5",
"ratelimit",
"regex",
"reqwest",
"rusqlite",
@@ -1810,15 +1812,6 @@ dependencies = [
"minimal-lexical",
]
[[package]]
name = "nom8"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8"
dependencies = [
"memchr",
]
[[package]]
name = "num-bigint-dig"
version = "0.8.2"
@@ -1955,9 +1948,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
[[package]]
name = "openssl-src"
version = "111.25.0+1.1.1t"
version = "111.24.0+1.1.1s"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3173cd3626c43e3854b1b727422a276e568d9ec5fe8cec197822cf52cfb743d6"
checksum = "3498f259dab01178c6228c6b00dcef0ed2a2d5e20d648c017861227773ea4abd"
dependencies = [
"cc",
]
@@ -2333,10 +2326,6 @@ dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "ratelimit"
version = "1.0.0"
[[package]]
name = "redox_syscall"
version = "0.2.16"
@@ -2374,11 +2363,11 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.11.14"
version = "0.11.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9"
checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c"
dependencies = [
"base64 0.21.0",
"base64 0.13.1",
"bytes",
"encoding_rs",
"futures-core",
@@ -2589,15 +2578,6 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_spanned"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4"
dependencies = [
"serde",
]
[[package]]
name = "serde_urlencoded"
version = "0.7.1"
@@ -2883,9 +2863,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.25.0"
version = "1.24.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af"
checksum = "1d9f76183f91ecfb55e1d7d5602bd1d979e38a3a522fe900241cf195624d67ae"
dependencies = [
"autocfg",
"bytes",
@@ -2972,36 +2952,11 @@ dependencies = [
[[package]]
name = "toml"
version = "0.7.2"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6"
checksum = "1333c76748e868a4d9d1017b5ab53171dfd095f70c712fdb4653a406547f598f"
dependencies = [
"serde",
"serde_spanned",
"toml_datetime",
"toml_edit",
]
[[package]]
name = "toml_datetime"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6a7712b49e1775fb9a7b998de6635b299237f48b404dde71704f2e0e7f37e5"
dependencies = [
"indexmap",
"nom8",
"serde",
"serde_spanned",
"toml_datetime",
]
[[package]]

View File

@@ -28,7 +28,7 @@ This code used to live at [`deltachat-node`](https://github.com/deltachat/deltac
## Install
By default the installation will try to use the bundled prebuilds in the
By default the installation will build try to use the bundled prebuilds in the
npm package. If this fails it falls back to compile `../deltachat-core-rust` from
this repository, using `scripts/rebuild-core.js`.

View File

@@ -60,5 +60,5 @@
"test:mocha": "mocha -r esm node/test/test.js --growl --reporter=spec --bail --exit"
},
"types": "node/dist/index.d.ts",
"version": "1.108.0"
"version": "1.106.0"
}

View File

@@ -11,8 +11,7 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys
import os
import sys, os
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the

View File

@@ -14,10 +14,10 @@ class EchoPlugin:
message.create_chat()
addr = message.get_sender_contact().addr
if message.is_system_message():
message.chat.send_text(f"echoing system message from {addr}:\n{message}")
message.chat.send_text("echoing system message from {}:\n{}".format(addr, message))
else:
text = message.text
message.chat.send_text(f"echoing from {addr}:\n{text}")
message.chat.send_text("echoing from {}:\n{}".format(addr, text))
@account_hookimpl
def ac_message_delivered(self, message):

View File

@@ -14,7 +14,7 @@ class GroupTrackingPlugin:
message.create_chat()
addr = message.get_sender_contact().addr
text = message.text
message.chat.send_text(f"echoing from {addr}:\n{text}")
message.chat.send_text("echoing from {}:\n{}".format(addr, text))
@account_hookimpl
def ac_outgoing_message(self, message):
@@ -28,28 +28,24 @@ class GroupTrackingPlugin:
def ac_chat_modified(self, chat):
print("ac_chat_modified:", chat.id, chat.get_name())
for member in chat.get_contacts():
print(f"chat member: {member.addr}")
print("chat member: {}".format(member.addr))
@account_hookimpl
def ac_member_added(self, chat, contact, actor, message):
print(
"ac_member_added {} to chat {} from {}".format(
contact.addr,
chat.id,
actor or message.get_sender_contact().addr,
),
contact.addr, chat.id, actor or message.get_sender_contact().addr
)
)
for member in chat.get_contacts():
print(f"chat member: {member.addr}")
print("chat member: {}".format(member.addr))
@account_hookimpl
def ac_member_removed(self, chat, contact, actor, message):
print(
"ac_member_removed {} from chat {} by {}".format(
contact.addr,
chat.id,
actor or message.get_sender_contact().addr,
),
contact.addr, chat.id, actor or message.get_sender_contact().addr
)
)

View File

@@ -13,8 +13,8 @@ def datadir():
datadir = path.join("test-data")
if datadir.isdir():
return datadir
pytest.skip("test-data directory not found")
return None
else:
pytest.skip("test-data directory not found")
def test_echo_quit_plugin(acfactory, lp):
@@ -47,7 +47,7 @@ def test_group_tracking_plugin(acfactory, lp):
botproc.fnmatch_lines(
"""
*ac_configure_completed*
""",
"""
)
ac1.add_account_plugin(FFIEventLogger(ac1))
ac2.add_account_plugin(FFIEventLogger(ac2))
@@ -61,7 +61,7 @@ def test_group_tracking_plugin(acfactory, lp):
botproc.fnmatch_lines(
"""
*ac_chat_modified*bot test group*
""",
"""
)
lp.sec("adding third member {}".format(ac2.get_config("addr")))
@@ -76,9 +76,8 @@ def test_group_tracking_plugin(acfactory, lp):
"""
*ac_member_added {}*from*{}*
""".format(
contact3.addr,
ac1.get_config("addr"),
),
contact3.addr, ac1.get_config("addr")
)
)
lp.sec("contact successfully added, now removing")
@@ -87,7 +86,6 @@ def test_group_tracking_plugin(acfactory, lp):
"""
*ac_member_removed {}*from*{}*
""".format(
contact3.addr,
ac1.get_config("addr"),
),
contact3.addr, ac1.get_config("addr")
)
)

View File

@@ -36,11 +36,6 @@ dynamic = [
[project.entry-points.pytest11]
"deltachat.testplugin" = "deltachat.testplugin"
[tool.setuptools.package-data]
deltachat = [
"py.typed"
]
[tool.setuptools_scm]
root = ".."
tag_regex = '^(?P<prefix>py-)?(?P<version>[^\+]+)(?P<suffix>.*)?$'
@@ -49,9 +44,5 @@ git_describe_command = "git describe --dirty --tags --long --match py-*.*"
[tool.black]
line-length = 120
[tool.ruff]
select = ["E", "F", "W", "YTT", "C4", "ISC", "ICN", "TID", "DTZ", "PLC", "PLE", "PLW", "PIE", "COM", "UP004", "UP010", "UP031", "UP032"]
line-length = 120
[tool.isort]
profile = "black"
profile = "black"

View File

@@ -36,8 +36,7 @@ register_global_plugin(events)
def run_cmdline(argv=None, account_plugins=None):
"""Run a simple default command line app, registering the specified
account plugins.
"""
account plugins."""
import argparse
if argv is None:
@@ -55,7 +54,6 @@ def run_cmdline(argv=None, account_plugins=None):
ac.run_account(addr=args.email, password=args.password, account_plugins=account_plugins, show_ffi=args.show_ffi)
addr = ac.get_config("addr")
print(f"{addr}: waiting for message")
print("{}: waiting for message".format(ac.get_config("addr")))
ac.wait_shutdown()

View File

@@ -102,8 +102,8 @@ def find_header(flags):
printf("%s", _dc_header_file_location());
return 0;
}
""",
),
"""
)
)
cwd = os.getcwd()
try:
@@ -171,7 +171,7 @@ def extract_defines(flags):
match = defines_re.match(line)
if match:
defines.append(match.group(1))
return "\n".join(f"#define {d} ..." for d in defines)
return "\n".join("#define {} ...".format(d) for d in defines)
def ffibuilder():
@@ -198,7 +198,7 @@ def ffibuilder():
typedef int... time_t;
void free(void *ptr);
extern int dc_event_has_string_data(int);
""",
"""
)
function_defs = extract_functions(flags)
defines = extract_defines(flags)

View File

@@ -1,12 +1,13 @@
"""Account class implementation."""
""" Account class implementation. """
from __future__ import print_function
import os
from array import array
from contextlib import contextmanager
from email.utils import parseaddr
from threading import Event
from typing import Any, Dict, Generator, List, Optional, Union, TYPE_CHECKING
from typing import Any, Dict, Generator, List, Optional, Union
from . import const, hookspec
from .capi import ffi, lib
@@ -19,12 +20,10 @@ from .cutil import (
from_optional_dc_charpointer,
iter_array,
)
from .events import EventThread, FFIEventLogger
from .message import Message
from .tracker import ConfigureTracker, ImexTracker
if TYPE_CHECKING:
from .events import FFIEventTracker
class MissingCredentials(ValueError):
"""Account is missing `addr` and `mail_pw` config values."""
@@ -40,7 +39,7 @@ def get_core_info():
ffi.gc(
lib.dc_context_new(as_dc_charpointer(""), as_dc_charpointer(path.name), ffi.NULL),
lib.dc_context_unref,
),
)
)
@@ -55,7 +54,7 @@ def get_dc_info_as_dict(dc_context):
return info_dict
class Account:
class Account(object):
"""Each account is tied to a sqlite database file which is fully managed
by the underlying deltachat core library. All public Account methods are
meant to be memory-safe and return memory-safe objects.
@@ -63,12 +62,7 @@ class Account:
MissingCredentials = MissingCredentials
_logid: str
_evtracker: "FFIEventTracker"
def __init__(self, db_path, os_name=None, logging=True, closed=False) -> None:
from .events import EventThread
"""initialize account object.
:param db_path: a path to the account database. The database
@@ -90,7 +84,7 @@ class Account:
ptr = lib.dc_context_new_closed(db_path) if closed else lib.dc_context_new(ffi.NULL, db_path, ffi.NULL)
if ptr == ffi.NULL:
raise ValueError(f"Could not dc_context_new: {os_name} {db_path}")
raise ValueError("Could not dc_context_new: {} {}".format(os_name, db_path))
self._dc_context = ffi.gc(
ptr,
lib.dc_context_unref,
@@ -122,7 +116,7 @@ class Account:
self._logging = True
def __repr__(self):
return f"<Account path={self.db_path}>"
return "<Account path={}>".format(self.db_path)
# def __del__(self):
# self.shutdown()
@@ -133,7 +127,7 @@ class Account:
def _check_config_key(self, name: str) -> None:
if name not in self._configkeys:
raise KeyError(f"{name!r} not a valid config key, existing keys: {self._configkeys!r}")
raise KeyError("{!r} not a valid config key, existing keys: {!r}".format(name, self._configkeys))
def get_info(self) -> Dict[str, str]:
"""return dictionary of built config parameters."""
@@ -147,7 +141,7 @@ class Account:
log("=============== " + self.get_config("displayname") + " ===============")
cursor = 0
for name, val in self.get_info().items():
entry = f"{name.upper()}={val}"
entry = "{}={}".format(name.upper(), val)
if cursor + len(entry) > 80:
log("")
cursor = 0
@@ -178,7 +172,10 @@ class Account:
namebytes = name.encode("utf8")
if isinstance(value, (int, bool)):
value = str(int(value))
valuebytes = value.encode("utf8") if value is not None else ffi.NULL
if value is not None:
valuebytes = value.encode("utf8")
else:
valuebytes = ffi.NULL
lib.dc_set_config(self._dc_context, namebytes, valuebytes)
def get_config(self, name: str) -> str:
@@ -192,7 +189,7 @@ class Account:
self._check_config_key(name)
namebytes = name.encode("utf8")
res = lib.dc_get_config(self._dc_context, namebytes)
assert res != ffi.NULL, f"config value not found for: {name!r}"
assert res != ffi.NULL, "config value not found for: {!r}".format(name)
return from_dc_charpointer(res)
def _preconfigure_keypair(self, addr: str, public: str, secret: str) -> None:
@@ -228,10 +225,9 @@ class Account:
return bool(lib.dc_is_configured(self._dc_context))
def is_open(self) -> bool:
"""Determine if account is open.
"""Determine if account is open
:returns True if account is open.
"""
:returns True if account is open."""
return bool(lib.dc_context_is_open(self._dc_context))
def set_avatar(self, img_path: Optional[str]) -> None:
@@ -302,12 +298,12 @@ class Account:
addr, displayname = obj.get_config("addr"), obj.get_config("displayname")
elif isinstance(obj, Contact):
if obj.account != self:
raise ValueError(f"account mismatch {obj}")
raise ValueError("account mismatch {}".format(obj))
addr, displayname = obj.addr, obj.name
elif isinstance(obj, str):
displayname, addr = parseaddr(obj)
else:
raise TypeError(f"don't know how to create chat for {obj!r}")
raise TypeError("don't know how to create chat for %r" % (obj,))
if name is None and displayname:
name = displayname
@@ -374,7 +370,7 @@ class Account:
def get_fresh_messages(self) -> Generator[Message, None, None]:
"""yield all fresh messages from all chats."""
dc_array = ffi.gc(lib.dc_get_fresh_msgs(self._dc_context), lib.dc_array_unref)
return (x for x in iter_array(dc_array, lambda x: Message.from_db(self, x)) if x is not None)
yield from iter_array(dc_array, lambda x: Message.from_db(self, x))
def create_chat(self, obj) -> Chat:
"""Create a 1:1 chat with Account, Contact or e-mail address."""
@@ -419,7 +415,7 @@ class Account:
def get_device_chat(self) -> Chat:
return Contact(self, const.DC_CONTACT_ID_DEVICE).create_chat()
def get_message_by_id(self, msg_id: int) -> Optional[Message]:
def get_message_by_id(self, msg_id: int) -> Message:
"""return Message instance.
:param msg_id: integer id of this message.
:returns: :class:`deltachat.message.Message` instance.
@@ -434,7 +430,7 @@ class Account:
"""
res = lib.dc_get_chat(self._dc_context, chat_id)
if res == ffi.NULL:
raise ValueError(f"cannot get chat with id={chat_id}")
raise ValueError("cannot get chat with id={}".format(chat_id))
lib.dc_chat_unref(res)
return Chat(self, chat_id)
@@ -547,11 +543,11 @@ class Account:
return from_dc_charpointer(res)
def check_qr(self, qr):
"""check qr code and return :class:`ScannedQRCode` instance representing the result."""
"""check qr code and return :class:`ScannedQRCode` instance representing the result"""
res = ffi.gc(lib.dc_check_qr(self._dc_context, as_dc_charpointer(qr)), lib.dc_lot_unref)
lot = DCLot(res)
if lot.state() == const.DC_QR_ERROR:
raise ValueError(f"invalid or unknown QR code: {lot.text1()}")
raise ValueError("invalid or unknown QR code: {}".format(lot.text1()))
return ScannedQRCode(lot)
def qr_setup_contact(self, qr):
@@ -602,8 +598,6 @@ class Account:
#
def run_account(self, addr=None, password=None, account_plugins=None, show_ffi=False):
from .events import FFIEventLogger
"""get the account running, configure it if necessary. add plugins if provided.
:param addr: the email address of the account
@@ -624,6 +618,8 @@ class Account:
assert addr and password, "you must specify email and password once to configure this database/account"
self.set_config("addr", addr)
self.set_config("mail_pw", password)
self.set_config("mvbox_move", "0")
self.set_config("sentbox_watch", "0")
self.set_config("bot", "1")
configtracker = self.configure()
configtracker.wait_finish()
@@ -666,7 +662,7 @@ class Account:
return lib.dc_all_work_done(self._dc_context)
def start_io(self):
"""start this account's IO scheduling (Rust-core async scheduler).
"""start this account's IO scheduling (Rust-core async scheduler)
If this account is not configured an Exception is raised.
You need to call account.configure() and account.wait_configure_finish()
@@ -709,10 +705,12 @@ class Account:
"""
lib.dc_maybe_network(self._dc_context)
def configure(self) -> ConfigureTracker:
def configure(self, reconfigure: bool = False) -> ConfigureTracker:
"""Start configuration process and return a Configtracker instance
on which you can block with wait_finish() to get a True/False success
value for the configuration process.
:param reconfigure: deprecated, doesn't need to be checked anymore.
"""
if not self.get_config("addr") or not self.get_config("mail_pw"):
raise MissingCredentials("addr or mail_pwd not set in config")
@@ -735,8 +733,7 @@ class Account:
def shutdown(self) -> None:
"""shutdown and destroy account (stop callback thread, close and remove
underlying dc_context).
"""
underlying dc_context)."""
if self._dc_context is None:
return
@@ -751,7 +748,7 @@ class Account:
try:
self._event_thread.wait(timeout=5)
except RuntimeError as e:
self.log(f"Waiting for event thread failed: {e}")
self.log("Waiting for event thread failed: {}".format(e))
if self._event_thread.is_alive():
self.log("WARN: event thread did not terminate yet, ignoring.")

View File

@@ -1,4 +1,4 @@
"""Chat and Location related API."""
""" Chat and Location related API. """
import calendar
import json
@@ -18,7 +18,7 @@ from .cutil import (
from .message import Message
class Chat:
class Chat(object):
"""Chat object which manages members and through which you can send and retrieve messages.
You obtain instances of it through :class:`deltachat.account.Account`.
@@ -37,10 +37,10 @@ class Chat:
return self.id == getattr(other, "id", None) and self.account._dc_context == other.account._dc_context
def __ne__(self, other) -> bool:
return not self == other
return not (self == other)
def __repr__(self) -> str:
return f"<Chat id={self.id} name={self.get_name()}>"
return "<Chat id={} name={}>".format(self.id, self.get_name())
@property
def _dc_chat(self):
@@ -74,19 +74,19 @@ class Chat:
return lib.dc_chat_get_type(self._dc_chat) == const.DC_CHAT_TYPE_GROUP
def is_single(self) -> bool:
"""Return True if this chat is a single/direct chat, False otherwise."""
"""Return True if this chat is a single/direct chat, False otherwise"""
return lib.dc_chat_get_type(self._dc_chat) == const.DC_CHAT_TYPE_SINGLE
def is_mailinglist(self) -> bool:
"""Return True if this chat is a mailing list, False otherwise."""
"""Return True if this chat is a mailing list, False otherwise"""
return lib.dc_chat_get_type(self._dc_chat) == const.DC_CHAT_TYPE_MAILINGLIST
def is_broadcast(self) -> bool:
"""Return True if this chat is a broadcast list, False otherwise."""
"""Return True if this chat is a broadcast list, False otherwise"""
return lib.dc_chat_get_type(self._dc_chat) == const.DC_CHAT_TYPE_BROADCAST
def is_multiuser(self) -> bool:
"""Return True if this chat is a multi-user chat (group, mailing list or broadcast), False otherwise."""
"""Return True if this chat is a multi-user chat (group, mailing list or broadcast), False otherwise"""
return lib.dc_chat_get_type(self._dc_chat) in (
const.DC_CHAT_TYPE_GROUP,
const.DC_CHAT_TYPE_MAILINGLIST,
@@ -94,11 +94,11 @@ class Chat:
)
def is_self_talk(self) -> bool:
"""Return True if this chat is the self-chat (a.k.a. "Saved Messages"), False otherwise."""
"""Return True if this chat is the self-chat (a.k.a. "Saved Messages"), False otherwise"""
return bool(lib.dc_chat_is_self_talk(self._dc_chat))
def is_device_talk(self) -> bool:
"""Returns True if this chat is the "Device Messages" chat, False otherwise."""
"""Returns True if this chat is the "Device Messages" chat, False otherwise"""
return bool(lib.dc_chat_is_device_talk(self._dc_chat))
def is_muted(self) -> bool:
@@ -109,12 +109,12 @@ class Chat:
return bool(lib.dc_chat_is_muted(self._dc_chat))
def is_pinned(self) -> bool:
"""Return True if this chat is pinned, False otherwise."""
"""Return True if this chat is pinned, False otherwise"""
return lib.dc_chat_get_visibility(self._dc_chat) == const.DC_CHAT_VISIBILITY_PINNED
def is_archived(self) -> bool:
"""Return True if this chat is archived, False otherwise.
:returns: True if archived, False otherwise.
:returns: True if archived, False otherwise
"""
return lib.dc_chat_get_visibility(self._dc_chat) == const.DC_CHAT_VISIBILITY_ARCHIVED
@@ -136,7 +136,7 @@ class Chat:
def can_send(self) -> bool:
"""Check if messages can be sent to a give chat.
This is not true eg. for the contact requests or for the device-talk.
This is not true eg. for the contact requests or for the device-talk
:returns: True if the chat is writable, False otherwise
"""
@@ -167,7 +167,7 @@ class Chat:
def get_color(self):
"""return the color of the chat.
:returns: color as 0x00rrggbb.
:returns: color as 0x00rrggbb
"""
return lib.dc_chat_get_color(self._dc_chat)
@@ -178,18 +178,21 @@ class Chat:
return json.loads(s)
def mute(self, duration: Optional[int] = None) -> None:
"""mutes the chat.
"""mutes the chat
:param duration: Number of seconds to mute the chat for. None to mute until unmuted again.
:returns: None
"""
mute_duration = -1 if duration is None else duration
if duration is None:
mute_duration = -1
else:
mute_duration = duration
ret = lib.dc_set_chat_mute_duration(self.account._dc_context, self.id, mute_duration)
if not bool(ret):
raise ValueError("Call to dc_set_chat_mute_duration failed")
def unmute(self) -> None:
"""unmutes the chat.
"""unmutes the chat
:returns: None
"""
@@ -249,8 +252,7 @@ class Chat:
def get_encryption_info(self) -> Optional[str]:
"""Return encryption info for this chat.
:returns: a string with encryption preferences of all chat members
"""
:returns: a string with encryption preferences of all chat members"""
res = lib.dc_get_chat_encrinfo(self.account._dc_context, self.id)
return from_dc_charpointer(res)
@@ -282,20 +284,12 @@ class Chat:
if msg.is_out_preparing():
assert msg.id != 0
# get a fresh copy of dc_msg, the core needs it
maybe_msg = Message.from_db(self.account, msg.id)
if maybe_msg is not None:
msg = maybe_msg
else:
raise ValueError("message does not exist")
msg = Message.from_db(self.account, msg.id)
sent_id = lib.dc_send_msg(self.account._dc_context, self.id, msg._dc_msg)
if sent_id == 0:
raise ValueError("message could not be sent")
# modify message in place to avoid bad state for the caller
sent_msg = Message.from_db(self.account, sent_id)
if sent_msg is None:
raise ValueError("cannot load just sent message from the database")
msg._dc_msg = sent_msg._dc_msg
msg._dc_msg = Message.from_db(self.account, sent_id)._dc_msg
return msg
def send_text(self, text):
@@ -452,7 +446,7 @@ class Chat:
contact = self.account.create_contact(obj)
ret = lib.dc_add_contact_to_chat(self.account._dc_context, self.id, contact.id)
if ret != 1:
raise ValueError(f"could not add contact {contact!r} to chat")
raise ValueError("could not add contact {!r} to chat".format(contact))
return contact
def remove_contact(self, obj):
@@ -465,11 +459,11 @@ class Chat:
contact = self.account.get_contact(obj)
ret = lib.dc_remove_contact_from_chat(self.account._dc_context, self.id, contact.id)
if ret != 1:
raise ValueError(f"could not remove contact {contact!r} from chat")
raise ValueError("could not remove contact {!r} from chat".format(contact))
def get_contacts(self):
"""get all contacts for this chat.
:returns: list of :class:`deltachat.contact.Contact` objects for this chat.
:returns: list of :class:`deltachat.contact.Contact` objects for this chat
"""
from .contact import Contact
@@ -501,7 +495,7 @@ class Chat:
p = as_dc_charpointer(img_path)
res = lib.dc_set_chat_profile_image(self.account._dc_context, self.id, p)
if res != 1:
raise ValueError(f"Setting Profile Image {p!r} failed")
raise ValueError("Setting Profile Image {!r} failed".format(p))
def remove_profile_image(self):
"""remove group profile image.
@@ -553,10 +547,19 @@ class Chat:
:param timespan_to: a datetime object or None (indicating up till now)
:returns: list of :class:`deltachat.chat.Location` objects.
"""
time_from = 0 if timestamp_from is None else calendar.timegm(timestamp_from.utctimetuple())
time_to = 0 if timestamp_to is None else calendar.timegm(timestamp_to.utctimetuple())
if timestamp_from is None:
time_from = 0
else:
time_from = calendar.timegm(timestamp_from.utctimetuple())
if timestamp_to is None:
time_to = 0
else:
time_to = calendar.timegm(timestamp_to.utctimetuple())
contact_id = 0 if contact is None else contact.id
if contact is None:
contact_id = 0
else:
contact_id = contact.id
dc_array = lib.dc_get_locations(self.account._dc_context, self.id, contact_id, time_from, time_to)
return [

View File

@@ -1,4 +1,4 @@
"""Contact object."""
""" Contact object. """
from datetime import date, datetime, timezone
from typing import Optional
@@ -9,7 +9,7 @@ from .chat import Chat
from .cutil import from_dc_charpointer, from_optional_dc_charpointer
class Contact:
class Contact(object):
"""Delta-Chat Contact.
You obtain instances of it through :class:`deltachat.account.Account`.
@@ -28,10 +28,10 @@ class Contact:
return self.account._dc_context == other.account._dc_context and self.id == other.id
def __ne__(self, other):
return not self == other
return not (self == other)
def __repr__(self):
return f"<Contact id={self.id} addr={self.addr} dc_context={self.account._dc_context}>"
return "<Contact id={} addr={} dc_context={}>".format(self.id, self.addr, self.account._dc_context)
@property
def _dc_contact(self):
@@ -76,7 +76,7 @@ class Contact:
return lib.dc_contact_is_verified(self._dc_contact)
def get_verifier(self, contact):
"""Return the address of the contact that verified the contact."""
"""Return the address of the contact that verified the contact"""
return from_dc_charpointer(lib.dc_contact_get_verifier_addr(contact._dc_contact))
def get_profile_image(self) -> Optional[str]:

View File

@@ -79,17 +79,15 @@ class DirectImap:
def select_config_folder(self, config_name: str):
"""Return info about selected folder if it is
configured, otherwise None.
"""
configured, otherwise None."""
if "_" not in config_name:
config_name = f"configured_{config_name}_folder"
config_name = "configured_{}_folder".format(config_name)
foldername = self.account.get_config(config_name)
if foldername:
return self.select_folder(foldername)
return None
def list_folders(self) -> List[str]:
"""return list of all existing folder names."""
"""return list of all existing folder names"""
assert not self._idling
return [folder.name for folder in self.conn.folder.list()]
@@ -105,7 +103,7 @@ class DirectImap:
def get_all_messages(self) -> List[MailMessage]:
assert not self._idling
return list(self.conn.fetch())
return [mail for mail in self.conn.fetch()]
def get_unread_messages(self) -> List[str]:
assert not self._idling
@@ -203,7 +201,7 @@ class IdleManager:
"""(blocking) wait for next idle message from server."""
self.log("imap-direct: calling idle_check")
res = self.direct_imap.conn.idle.poll(timeout=timeout)
self.log(f"imap-direct: idle_check returned {res!r}")
self.log("imap-direct: idle_check returned {!r}".format(res))
return res
def wait_for_new_message(self, timeout=None) -> bytes:
@@ -223,4 +221,5 @@ class IdleManager:
def done(self):
"""send idle-done to server if we are currently in idle mode."""
return self.direct_imap.conn.idle.stop()
res = self.direct_imap.conn.idle.stop()
return res

View File

@@ -13,7 +13,6 @@ from .capi import ffi, lib
from .cutil import from_optional_dc_charpointer
from .hookspec import account_hookimpl
from .message import map_system_message
from .account import Account
def get_dc_event_name(integer, _DC_EVENTNAME_MAP={}):
@@ -32,12 +31,13 @@ class FFIEvent:
def __str__(self):
if self.name == "DC_EVENT_INFO":
return f"INFO {self.data2}"
if self.name == "DC_EVENT_WARNING":
return f"WARNING {self.data2}"
if self.name == "DC_EVENT_ERROR":
return f"ERROR {self.data2}"
return "{name} data1={data1} data2={data2}".format(**self.__dict__)
return "INFO {data2}".format(data2=self.data2)
elif self.name == "DC_EVENT_WARNING":
return "WARNING {data2}".format(data2=self.data2)
elif self.name == "DC_EVENT_ERROR":
return "ERROR {data2}".format(data2=self.data2)
else:
return "{name} data1={data1} data2={data2}".format(**self.__dict__)
class FFIEventLogger:
@@ -69,7 +69,7 @@ class FFIEventLogger:
locname = tname
if self.logid:
locname += "-" + self.logid
s = f"{elapsed:2.2f} [{locname}] {message}"
s = "{:2.2f} [{}] {}".format(elapsed, locname, message)
if os.name == "posix":
WARN = "\033[93m"
@@ -104,7 +104,7 @@ class FFIEventTracker:
timeout = timeout if timeout is not None else self._timeout
ev = self._event_queue.get(timeout=timeout)
if check_error and ev.name == "DC_EVENT_ERROR":
raise ValueError(f"unexpected event: {ev}")
raise ValueError("unexpected event: {}".format(ev))
return ev
def iter_events(self, timeout=None, check_error=True):
@@ -112,7 +112,7 @@ class FFIEventTracker:
yield self.get(timeout=timeout, check_error=check_error)
def get_matching(self, event_name_regex, check_error=True, timeout=None):
rex = re.compile(f"^(?:{event_name_regex})$")
rex = re.compile("^(?:{})$".format(event_name_regex))
for ev in self.iter_events(timeout=timeout, check_error=check_error):
if rex.match(ev.name):
return ev
@@ -135,8 +135,7 @@ class FFIEventTracker:
def wait_for_connectivity(self, connectivity):
"""Wait for the specified connectivity.
This only works reliably if the connectivity doesn't change
again too quickly, otherwise we might miss it.
"""
again too quickly, otherwise we might miss it."""
while 1:
if self.account.get_connectivity() == connectivity:
return
@@ -144,13 +143,12 @@ class FFIEventTracker:
def wait_for_connectivity_change(self, previous, expected_next):
"""Wait until the connectivity changes to `expected_next`.
Fails the test if it changes to something else.
"""
Fails the test if it changes to something else."""
while 1:
current = self.account.get_connectivity()
if current == expected_next:
return
if current != previous:
elif current != previous:
raise Exception("Expected connectivity " + str(expected_next) + " but got " + str(current))
self.get_matching("DC_EVENT_CONNECTIVITY_CHANGED")
@@ -163,20 +161,20 @@ class FFIEventTracker:
def ensure_event_not_queued(self, event_name_regex):
__tracebackhide__ = True
rex = re.compile(f"(?:{event_name_regex}).*")
rex = re.compile("(?:{}).*".format(event_name_regex))
while 1:
try:
ev = self._event_queue.get(False)
except Empty:
break
else:
assert not rex.match(ev.name), f"event found {ev}"
assert not rex.match(ev.name), "event found {}".format(ev)
def wait_securejoin_inviter_progress(self, target):
while 1:
event = self.get_matching("DC_EVENT_SECUREJOIN_INVITER_PROGRESS")
if event.data2 >= target:
print(f"** SECUREJOINT-INVITER PROGRESS {target}", self.account)
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account)
break
def wait_idle_inbox_ready(self):
@@ -185,8 +183,7 @@ class FFIEventTracker:
- ac1 and ac2 are created
- ac1 sends a message to ac2
- ac2 is still running FetchExsistingMsgs job and thinks it's an existing, old message
- therefore no DC_EVENT_INCOMING_MSG is sent
"""
- therefore no DC_EVENT_INCOMING_MSG is sent"""
self.get_info_contains("INBOX: Idle entering")
def wait_next_incoming_message(self):
@@ -196,15 +193,14 @@ class FFIEventTracker:
def wait_next_messages_changed(self):
"""wait for and return next message-changed message or None
if the event contains no msgid
"""
if the event contains no msgid"""
ev = self.get_matching("DC_EVENT_MSGS_CHANGED")
if ev.data2 > 0:
return self.account.get_message_by_id(ev.data2)
return None
def wait_next_reactions_changed(self):
"""wait for and return next reactions-changed message."""
"""wait for and return next reactions-changed message"""
ev = self.get_matching("DC_EVENT_REACTIONS_CHANGED")
assert ev.data1 > 0
return self.account.get_message_by_id(ev.data2)
@@ -222,7 +218,7 @@ class EventThread(threading.Thread):
With each Account init this callback thread is started.
"""
def __init__(self, account: Account) -> None:
def __init__(self, account) -> None:
self.account = account
super(EventThread, self).__init__(name="events")
self.daemon = True
@@ -248,37 +244,36 @@ class EventThread(threading.Thread):
def run(self) -> None:
"""get and run events until shutdown."""
with self.log_execution("EVENT THREAD"):
event_emitter = ffi.gc(
lib.dc_get_event_emitter(self.account._dc_context),
lib.dc_event_emitter_unref,
)
while not self._marked_for_shutdown:
with self.swallow_and_log_exception("Unexpected error in event thread"):
event = lib.dc_get_next_event(event_emitter)
if event == ffi.NULL or self._marked_for_shutdown:
break
self._process_event(event)
self._inner_run()
def _process_event(self, event) -> None:
evt = lib.dc_event_get_id(event)
data1 = lib.dc_event_get_data1_int(event)
# the following code relates to the deltachat/_build.py's helper
# function which provides us signature info of an event call
evt_name = get_dc_event_name(evt)
if lib.dc_event_has_string_data(evt):
data2 = from_optional_dc_charpointer(lib.dc_event_get_data2_str(event))
else:
data2 = lib.dc_event_get_data2_int(event)
def _inner_run(self):
event_emitter = ffi.gc(
lib.dc_get_event_emitter(self.account._dc_context),
lib.dc_event_emitter_unref,
)
while not self._marked_for_shutdown:
event = lib.dc_get_next_event(event_emitter)
if event == ffi.NULL or self._marked_for_shutdown:
break
evt = lib.dc_event_get_id(event)
data1 = lib.dc_event_get_data1_int(event)
# the following code relates to the deltachat/_build.py's helper
# function which provides us signature info of an event call
evt_name = get_dc_event_name(evt)
if lib.dc_event_has_string_data(evt):
data2 = from_optional_dc_charpointer(lib.dc_event_get_data2_str(event))
else:
data2 = lib.dc_event_get_data2_int(event)
lib.dc_event_unref(event)
ffi_event = FFIEvent(name=evt_name, data1=data1, data2=data2)
with self.swallow_and_log_exception(f"ac_process_ffi_event {ffi_event}"):
self.account._pm.hook.ac_process_ffi_event(account=self, ffi_event=ffi_event)
for name, kwargs in self._map_ffi_event(ffi_event):
hook = getattr(self.account._pm.hook, name)
info = f"call {name} kwargs={kwargs} failed"
with self.swallow_and_log_exception(info):
hook(**kwargs)
lib.dc_event_unref(event)
ffi_event = FFIEvent(name=evt_name, data1=data1, data2=data2)
with self.swallow_and_log_exception("ac_process_ffi_event {}".format(ffi_event)):
self.account._pm.hook.ac_process_ffi_event(account=self, ffi_event=ffi_event)
for name, kwargs in self._map_ffi_event(ffi_event):
hook = getattr(self.account._pm.hook, name)
info = "call {} kwargs={} failed".format(name, kwargs)
with self.swallow_and_log_exception(info):
hook(**kwargs)
@contextmanager
def swallow_and_log_exception(self, info):
@@ -287,7 +282,7 @@ class EventThread(threading.Thread):
except Exception as ex:
logfile = io.StringIO()
traceback.print_exception(*sys.exc_info(), file=logfile)
self.account.log(f"{info}\nException {ex}\nTraceback:\n{logfile.getvalue()}")
self.account.log("{}\nException {}\nTraceback:\n{}".format(info, ex, logfile.getvalue()))
def _map_ffi_event(self, ffi_event: FFIEvent):
name = ffi_event.name
@@ -297,32 +292,30 @@ class EventThread(threading.Thread):
if data1 == 0 or data1 == 1000:
success = data1 == 1000
comment = ffi_event.data2
yield "ac_configure_completed", {"success": success, "comment": comment}
yield "ac_configure_completed", dict(success=success, comment=comment)
elif name == "DC_EVENT_INCOMING_MSG":
msg = account.get_message_by_id(ffi_event.data2)
if msg is not None:
yield map_system_message(msg) or ("ac_incoming_message", {"message": msg})
yield map_system_message(msg) or ("ac_incoming_message", dict(message=msg))
elif name == "DC_EVENT_MSGS_CHANGED":
if ffi_event.data2 != 0:
msg = account.get_message_by_id(ffi_event.data2)
if msg is not None:
if msg.is_outgoing():
res = map_system_message(msg)
if res and res[0].startswith("ac_member"):
yield res
yield "ac_outgoing_message", {"message": msg}
elif msg.is_in_fresh():
yield map_system_message(msg) or (
"ac_incoming_message",
{"message": msg},
)
if msg.is_outgoing():
res = map_system_message(msg)
if res and res[0].startswith("ac_member"):
yield res
yield "ac_outgoing_message", dict(message=msg)
elif msg.is_in_fresh():
yield map_system_message(msg) or (
"ac_incoming_message",
dict(message=msg),
)
elif name == "DC_EVENT_REACTIONS_CHANGED":
assert ffi_event.data1 > 0
msg = account.get_message_by_id(ffi_event.data2)
yield "ac_reactions_changed", {"message": msg}
yield "ac_reactions_changed", dict(message=msg)
elif name == "DC_EVENT_MSG_DELIVERED":
msg = account.get_message_by_id(ffi_event.data2)
yield "ac_message_delivered", {"message": msg}
yield "ac_message_delivered", dict(message=msg)
elif name == "DC_EVENT_CHAT_MODIFIED":
chat = account.get_chat_by_id(ffi_event.data1)
yield "ac_chat_modified", {"chat": chat}
yield "ac_chat_modified", dict(chat=chat)

View File

@@ -1,4 +1,4 @@
"""Hooks for Python bindings to Delta Chat Core Rust CFFI."""
""" Hooks for Python bindings to Delta Chat Core Rust CFFI"""
import pluggy

View File

@@ -1,4 +1,4 @@
"""The Message object."""
""" The Message object. """
import json
import os
@@ -12,7 +12,7 @@ from .cutil import as_dc_charpointer, from_dc_charpointer, from_optional_dc_char
from .reactions import Reactions
class Message:
class Message(object):
"""Message object.
You obtain instances of it through :class:`deltachat.account.Account` or
@@ -36,21 +36,21 @@ class Message:
def __repr__(self):
c = self.get_sender_contact()
typ = "outgoing" if self.is_outgoing() else "incoming"
return (
f"<Message {typ} sys={self.is_system_message()} {repr(self.text[:100])} "
f"id={self.id} sender={c.id}/{c.addr} chat={self.chat.id}/{self.chat.get_name()}>"
return "<Message {} sys={} {} id={} sender={}/{} chat={}/{}>".format(
typ,
self.is_system_message(),
repr(self.text[:10]),
self.id,
c.id,
c.addr,
self.chat.id,
self.chat.get_name(),
)
@classmethod
def from_db(cls, account, id) -> Optional["Message"]:
"""Attempt to load the message from the database given its ID.
None is returned if the message does not exist, i.e. deleted."""
def from_db(cls, account, id):
assert id > 0
res = lib.dc_get_msg(account._dc_context, id)
if res == ffi.NULL:
return None
return cls(account, ffi.gc(res, lib.dc_msg_unref))
return cls(account, ffi.gc(lib.dc_get_msg(account._dc_context, id), lib.dc_msg_unref))
@classmethod
def new_empty(cls, account, view_type):
@@ -59,7 +59,10 @@ class Message:
:param view_type: the message type code or one of the strings:
"text", "audio", "video", "file", "sticker", "videochat", "webxdc"
"""
view_type_code = view_type if isinstance(view_type, int) else get_viewtype_code_from_name(view_type)
if isinstance(view_type, int):
view_type_code = view_type
else:
view_type_code = get_viewtype_code_from_name(view_type)
return Message(
account,
ffi.gc(lib.dc_msg_new(account._dc_context, view_type_code), lib.dc_msg_unref),
@@ -115,7 +118,7 @@ class Message:
"""set file for this message from path and mime_type."""
mtype = ffi.NULL if mime_type is None else as_dc_charpointer(mime_type)
if not os.path.exists(path):
raise ValueError(f"path does not exist: {path!r}")
raise ValueError("path does not exist: {!r}".format(path))
lib.dc_msg_set_file(self._dc_msg, as_dc_charpointer(path), mtype)
@props.with_doc
@@ -126,7 +129,7 @@ class Message:
@props.with_doc
def filemime(self) -> str:
"""mime type of the file (if it exists)."""
"""mime type of the file (if it exists)"""
return from_dc_charpointer(lib.dc_msg_get_filemime(self._dc_msg))
def get_status_updates(self, serial: int = 0) -> list:
@@ -138,7 +141,7 @@ class Message:
:param serial: The last known serial. Pass 0 if there are no known serials to receive all updates.
"""
return json.loads(
from_dc_charpointer(lib.dc_get_webxdc_status_updates(self.account._dc_context, self.id, serial)),
from_dc_charpointer(lib.dc_get_webxdc_status_updates(self.account._dc_context, self.id, serial))
)
def send_status_update(self, json_data: Union[str, dict], description: str) -> bool:
@@ -155,11 +158,8 @@ class Message:
json_data = json.dumps(json_data, default=str)
return bool(
lib.dc_send_webxdc_status_update(
self.account._dc_context,
self.id,
as_dc_charpointer(json_data),
as_dc_charpointer(description),
),
self.account._dc_context, self.id, as_dc_charpointer(json_data), as_dc_charpointer(description)
)
)
def send_reaction(self, reaction: str):
@@ -232,18 +232,16 @@ class Message:
ts = lib.dc_msg_get_received_timestamp(self._dc_msg)
if ts:
return datetime.fromtimestamp(ts, timezone.utc)
return None
@props.with_doc
def ephemeral_timer(self):
"""Ephemeral timer in seconds.
"""Ephemeral timer in seconds
:returns: timer in seconds or None if there is no timer
"""
timer = lib.dc_msg_get_ephemeral_timer(self._dc_msg)
if timer:
return timer
return None
@props.with_doc
def ephemeral_timestamp(self):
@@ -257,25 +255,23 @@ class Message:
@property
def quoted_text(self) -> Optional[str]:
"""Text inside the quote.
"""Text inside the quote
:returns: Quoted text
"""
:returns: Quoted text"""
return from_optional_dc_charpointer(lib.dc_msg_get_quoted_text(self._dc_msg))
@property
def quote(self):
"""Quote getter.
"""Quote getter
:returns: Quoted message, if found in the database
"""
:returns: Quoted message, if found in the database"""
msg = lib.dc_msg_get_quoted_msg(self._dc_msg)
if msg:
return Message(self.account, ffi.gc(msg, lib.dc_msg_unref))
@quote.setter
def quote(self, quoted_message):
"""Quote setter."""
"""Quote setter"""
lib.dc_msg_set_quote(self._dc_msg, quoted_message._dc_msg)
def force_plaintext(self) -> None:
@@ -290,7 +286,7 @@ class Message:
:returns: email-mime message object (with headers only, no body).
"""
import email
import email.parser
mime_headers = lib.dc_get_mime_headers(self.account._dc_context, self.id)
if mime_headers:
@@ -301,7 +297,7 @@ class Message:
@property
def error(self) -> Optional[str]:
"""Error message."""
"""Error message"""
return from_optional_dc_charpointer(lib.dc_msg_get_error(self._dc_msg))
@property
@@ -497,8 +493,7 @@ def get_viewtype_code_from_name(view_type_name):
if code is not None:
return code
raise ValueError(
"message typecode not found for {!r}, "
"available {!r}".format(view_type_name, list(_view_type_mapping.keys())),
"message typecode not found for {!r}, " "available {!r}".format(view_type_name, list(_view_type_mapping.keys()))
)
@@ -511,11 +506,14 @@ def map_system_message(msg):
if msg.is_system_message():
res = parse_system_add_remove(msg.text)
if not res:
return None
return
action, affected, actor = res
affected = msg.account.get_contact_by_addr(affected)
actor = None if actor == "me" else msg.account.get_contact_by_addr(actor)
d = {"chat": msg.chat, "contact": affected, "actor": actor, "message": msg}
if actor == "me":
actor = None
else:
actor = msg.account.get_contact_by_addr(actor)
d = dict(chat=msg.chat, contact=affected, actor=actor, message=msg)
return "ac_member_" + res[0], d
@@ -530,8 +528,8 @@ def extract_addr(text):
def parse_system_add_remove(text):
"""return add/remove info from parsing the given system message text.
returns a (action, affected, actor) triple
"""
returns a (action, affected, actor) triple"""
# You removed member a@b.
# You added member a@b.
# Member Me (x@y) removed by a@b.

View File

@@ -8,7 +8,7 @@ def with_doc(f):
# copied over unmodified from
# https://github.com/devpi/devpi/blob/master/common/devpi_common/types.py
def cached(f):
"""returns a cached property that is calculated by function f."""
"""returns a cached property that is calculated by function f"""
def get(self):
try:
@@ -17,9 +17,8 @@ def cached(f):
self._property_cache = {}
except KeyError:
pass
res = f(self)
self._property_cache[f] = res
return res
x = self._property_cache[f] = f(self)
return x
def set(self, val):
propcache = self.__dict__.setdefault("_property_cache", {})

View File

@@ -8,9 +8,8 @@ class ProviderNotFoundError(Exception):
"""The provider information was not found."""
class Provider:
"""
Provider information.
class Provider(object):
"""Provider information.
:param domain: The email to get the provider info for.
"""

View File

@@ -1,10 +1,10 @@
"""The Reactions object."""
""" The Reactions object. """
from .capi import ffi, lib
from .cutil import from_dc_charpointer, iter_array
class Reactions:
class Reactions(object):
"""Reactions object.
You obtain instances of it through :class:`deltachat.message.Message`.
@@ -18,7 +18,7 @@ class Reactions:
self._dc_reactions = dc_reactions
def __repr__(self):
return f"<Reactions dc_reactions={self._dc_reactions}>"
return "<Reactions dc_reactions={}>".format(self._dc_reactions)
@classmethod
def from_msg(cls, msg):

View File

@@ -1,3 +1,5 @@
from __future__ import print_function
import fnmatch
import io
import os
@@ -27,7 +29,7 @@ def pytest_addoption(parser):
"--liveconfig",
action="store",
default=None,
help="a file with >=2 lines where each line contains NAME=VALUE config settings for one account",
help="a file with >=2 lines where each line " "contains NAME=VALUE config settings for one account",
)
group.addoption(
"--ignored",
@@ -122,16 +124,16 @@ def pytest_report_header(config, startdir):
info["deltachat_core_version"],
info["sqlite_version"],
info["journal_mode"],
),
)
]
cfg = config.option.liveconfig
if cfg:
if "?" in cfg:
url, token = cfg.split("?", 1)
summary.append(f"Liveconfig provider: {url}?<token ommitted>")
summary.append("Liveconfig provider: {}?<token ommitted>".format(url))
else:
summary.append(f"Liveconfig file: {cfg}")
summary.append("Liveconfig file: {}".format(cfg))
return summary
@@ -176,13 +178,13 @@ class TestProcess:
except IndexError:
res = requests.post(liveconfig_opt, timeout=60)
if res.status_code != 200:
pytest.fail(f"newtmpuser count={index} code={res.status_code}: '{res.text}'")
pytest.fail("newtmpuser count={} code={}: '{}'".format(index, res.status_code, res.text))
d = res.json()
config = {"addr": d["email"], "mail_pw": d["password"]}
config = dict(addr=d["email"], mail_pw=d["password"])
print("newtmpuser {}: addr={}".format(index, config["addr"]))
self._configlist.append(config)
yield config
pytest.fail(f"more than {MAX_LIVE_CREATED_ACCOUNTS} live accounts requested.")
pytest.fail("more than {} live accounts requested.".format(MAX_LIVE_CREATED_ACCOUNTS))
def cache_maybe_retrieve_configured_db_files(self, cache_addr, db_target_path):
db_target_path = pathlib.Path(db_target_path)
@@ -227,7 +229,7 @@ def write_dict_to_dir(dic, target_dir):
path.write_bytes(content)
@pytest.fixture()
@pytest.fixture
def data(request):
class Data:
def __init__(self) -> None:
@@ -250,8 +252,7 @@ def data(request):
fn = os.path.join(path, *bn.split("/"))
if os.path.exists(fn):
return fn
print(f"WARNING: path does not exist: {fn!r}")
return None
print("WARNING: path does not exist: {!r}".format(fn))
def read_path(self, bn, mode="r"):
fn = self.get_path(bn)
@@ -263,11 +264,8 @@ def data(request):
class ACSetup:
"""
Accounts setup helper to deal with multiple configure-process
and io & imap initialization phases.
From tests, use the higher level
"""accounts setup helper to deal with multiple configure-process
and io & imap initialization phases. From tests, use the higher level
public ACFactory methods instead of its private helper class.
"""
@@ -275,8 +273,6 @@ class ACSetup:
CONFIGURED = "CONFIGURED"
IDLEREADY = "IDLEREADY"
_configured_events: Queue
def __init__(self, testprocess, init_time):
self._configured_events = Queue()
self._account2state = {}
@@ -285,7 +281,7 @@ class ACSetup:
self.init_time = init_time
def log(self, *args):
print("[acsetup]", f"{time.time() - self.init_time:.3f}", *args)
print("[acsetup]", "{:.3f}".format(time.time() - self.init_time), *args)
def add_configured(self, account):
"""add an already configured account."""
@@ -293,7 +289,7 @@ class ACSetup:
self._account2state[account] = self.CONFIGURED
self.log("added already configured account", account, account.get_config("addr"))
def start_configure(self, account):
def start_configure(self, account, reconfigure=False):
"""add an account and start its configure process."""
class PendingTracker:
@@ -303,7 +299,7 @@ class ACSetup:
account.add_account_plugin(PendingTracker(), name="pending_tracker")
self._account2state[account] = self.CONFIGURING
account.configure()
account.configure(reconfigure=reconfigure)
self.log("started configure on", account)
def wait_one_configured(self, account):
@@ -339,7 +335,7 @@ class ACSetup:
def _pop_config_success(self):
acc, success, comment = self._configured_events.get()
if not success:
pytest.fail(f"configuring online account {acc} failed: {comment}")
pytest.fail("configuring online account {} failed: {}".format(acc, comment))
self._account2state[acc] = self.CONFIGURED
return acc
@@ -373,18 +369,13 @@ class ACSetup:
imap.delete("1:*", expunge=True)
else:
imap.conn.folder.delete(folder)
acc.log(f"imap cleaned for addr {addr}")
acc.log("imap cleaned for addr {}".format(addr))
self._imap_cleaned.add(addr)
class ACFactory:
"""Account factory"""
init_time: float
_finalizers: List[Callable[[], None]]
_accounts: List[Account]
_acsetup: ACSetup
_preconfigured_keys: List[str]
def __init__(self, request, testprocess, tmpdir, data) -> None:
self.init_time = time.time()
@@ -402,7 +393,7 @@ class ACFactory:
request.addfinalizer(self.finalize)
def log(self, *args):
print("[acfactory]", f"{time.time() - self.init_time:.3f}", *args)
print("[acfactory]", "{:.3f}".format(time.time() - self.init_time), *args)
def finalize(self):
while self._finalizers:
@@ -420,8 +411,7 @@ class ACFactory:
acc.disable_logging()
def get_next_liveconfig(self):
"""
Base function to get functional online configurations
"""Base function to get functional online configurations
where we can make valid SMTP and IMAP connections with.
"""
configdict = next(self._liveconfig_producer).copy()
@@ -436,16 +426,15 @@ class ACFactory:
assert "addr" in configdict and "mail_pw" in configdict
return configdict
def _get_cached_account(self, addr) -> Optional[Account]:
def _get_cached_account(self, addr):
if addr in self.testprocess._addr2files:
return self._getaccount(addr)
return None
def get_unconfigured_account(self, closed=False) -> Account:
def get_unconfigured_account(self, closed=False):
return self._getaccount(closed=closed)
def _getaccount(self, try_cache_addr=None, closed=False) -> Account:
logid = f"ac{len(self._accounts) + 1}"
def _getaccount(self, try_cache_addr=None, closed=False):
logid = "ac{}".format(len(self._accounts) + 1)
# we need to use fixed database basename for maybe_cache_* functions to work
path = self.tmpdir.mkdir(logid).join("dc.db")
if try_cache_addr:
@@ -458,10 +447,10 @@ class ACFactory:
self._accounts.append(ac)
return ac
def set_logging_default(self, logging) -> None:
def set_logging_default(self, logging):
self._logging = bool(logging)
def remove_preconfigured_keys(self) -> None:
def remove_preconfigured_keys(self):
self._preconfigured_keys = []
def _preconfigure_key(self, account, addr):
@@ -471,12 +460,13 @@ class ACFactory:
except IndexError:
pass
else:
fname_pub = self.data.read_path(f"key/{keyname}-public.asc")
fname_sec = self.data.read_path(f"key/{keyname}-secret.asc")
fname_pub = self.data.read_path("key/{name}-public.asc".format(name=keyname))
fname_sec = self.data.read_path("key/{name}-secret.asc".format(name=keyname))
if fname_pub and fname_sec:
account._preconfigure_keypair(addr, fname_pub, fname_sec)
return True
print(f"WARN: could not use preconfigured keys for {addr!r}")
else:
print("WARN: could not use preconfigured keys for {!r}".format(addr))
def get_pseudo_configured_account(self, passphrase: Optional[str] = None) -> Account:
# do a pseudo-configured account
@@ -484,32 +474,32 @@ class ACFactory:
if passphrase:
ac.open(passphrase)
acname = ac._logid
addr = f"{acname}@offline.org"
addr = "{}@offline.org".format(acname)
ac.update_config(
{
"addr": addr,
"displayname": acname,
"mail_pw": "123",
"configured_addr": addr,
"configured_mail_pw": "123",
"configured": "1",
},
dict(
addr=addr,
displayname=acname,
mail_pw="123",
configured_addr=addr,
configured_mail_pw="123",
configured="1",
)
)
self._preconfigure_key(ac, addr)
self._acsetup.init_logging(ac)
return ac
def new_online_configuring_account(self, cloned_from=None, cache=False, **kwargs) -> Account:
def new_online_configuring_account(self, cloned_from=None, cache=False, **kwargs):
if cloned_from is None:
configdict = self.get_next_liveconfig()
else:
# XXX we might want to transfer the key to the new account
configdict = {
"addr": cloned_from.get_config("addr"),
"mail_pw": cloned_from.get_config("mail_pw"),
"imap_certificate_checks": cloned_from.get_config("imap_certificate_checks"),
"smtp_certificate_checks": cloned_from.get_config("smtp_certificate_checks"),
}
configdict = dict(
addr=cloned_from.get_config("addr"),
mail_pw=cloned_from.get_config("mail_pw"),
imap_certificate_checks=cloned_from.get_config("imap_certificate_checks"),
smtp_certificate_checks=cloned_from.get_config("smtp_certificate_checks"),
)
configdict.update(kwargs)
ac = self._get_cached_account(addr=configdict["addr"]) if cache else None
if ac is not None:
@@ -521,7 +511,7 @@ class ACFactory:
self._acsetup.start_configure(ac)
return ac
def prepare_account_from_liveconfig(self, configdict) -> Account:
def prepare_account_from_liveconfig(self, configdict):
ac = self.get_unconfigured_account()
assert "addr" in configdict and "mail_pw" in configdict, configdict
configdict.setdefault("bcc_self", False)
@@ -531,11 +521,11 @@ class ACFactory:
self._preconfigure_key(ac, configdict["addr"])
return ac
def wait_configured(self, account) -> None:
def wait_configured(self, account):
"""Wait until the specified account has successfully completed configure."""
self._acsetup.wait_one_configured(account)
def bring_accounts_online(self) -> None:
def bring_accounts_online(self):
print("bringing accounts online")
self._acsetup.bring_online()
print("all accounts online")
@@ -610,7 +600,7 @@ class ACFactory:
acc._evtracker.wait_next_incoming_message()
@pytest.fixture()
@pytest.fixture
def acfactory(request, tmpdir, testprocess, data):
am = ACFactory(request=request, tmpdir=tmpdir, testprocess=testprocess, data=data)
yield am
@@ -675,12 +665,12 @@ class BotProcess:
ignored.append(line)
@pytest.fixture()
@pytest.fixture
def tmp_db_path(tmpdir):
return tmpdir.join("test.db").strpath
@pytest.fixture()
@pytest.fixture
def lp():
class Printer:
def sec(self, msg: str) -> None:

View File

@@ -38,7 +38,7 @@ class ImexTracker:
if isinstance(ev, str):
files_written.append(ev)
elif ev == 0:
raise ImexFailed(f"export failed, exp-files: {files_written}")
raise ImexFailed("export failed, exp-files: {}".format(files_written))
elif ev == 1000:
return files_written
@@ -77,11 +77,11 @@ class ConfigureTracker:
self.account.remove_account_plugin(self)
def wait_smtp_connected(self):
"""Wait until SMTP is configured."""
"""wait until smtp is configured."""
self._smtp_finished.wait()
def wait_imap_connected(self):
"""Wait until IMAP is configured."""
"""wait until smtp is configured."""
self._imap_finished.wait()
def wait_progress(self, data1=None):
@@ -91,8 +91,7 @@ class ConfigureTracker:
break
def wait_finish(self, timeout=None):
"""
Wait until configure is completed.
"""wait until configure is completed.
Raise Exception if Configure failed
"""

View File

@@ -15,5 +15,5 @@ if __name__ == "__main__":
p,
"-w",
workspacedir,
],
]
)

View File

@@ -14,7 +14,7 @@ def test_db_busy_error(acfactory, tmpdir):
def log(string):
with log_lock:
print(f"{time.time() - starttime:3.2f} {string}")
print("%3.2f %s" % (time.time() - starttime, string))
# make a number of accounts
accounts = acfactory.get_many_online_accounts(3)
@@ -59,15 +59,15 @@ def test_db_busy_error(acfactory, tmpdir):
if report_type == ReportType.exit:
replier.log("EXIT")
elif report_type == ReportType.ffi_error:
replier.log(f"ERROR: {report_args[0]}")
replier.log("ERROR: {}".format(report_args[0]))
elif report_type == ReportType.message_echo:
continue
else:
raise ValueError(f"{addr} unknown report type {report_type}, args={report_args}")
raise ValueError("{} unknown report type {}, args={}".format(addr, report_type, report_args))
alive_count -= 1
replier.log("shutting down")
replier.account.shutdown()
replier.log(f"shut down complete, remaining={alive_count}")
replier.log("shut down complete, remaining={}".format(alive_count))
class ReportType:
@@ -86,12 +86,12 @@ class AutoReplier:
self.current_sent = 0
self.addr = self.account.get_self_contact().addr
self._thread = threading.Thread(name=f"Stats{self.account}", target=self.thread_stats)
self._thread = threading.Thread(name="Stats{}".format(self.account), target=self.thread_stats)
self._thread.setDaemon(True)
self._thread.start()
def log(self, message):
self._log(f"{self.addr} {message}")
self._log("{} {}".format(self.addr, message))
def thread_stats(self):
# XXX later use, for now we just quit
@@ -107,17 +107,17 @@ class AutoReplier:
return
message.create_chat()
message.mark_seen()
self.log(f"incoming message: {message}")
self.log("incoming message: {}".format(message))
self.current_sent += 1
# we are still alive, let's send a reply
if self.num_bigfiles and self.current_sent % (self.num_send / self.num_bigfiles) == 0:
message.chat.send_text(f"send big file as reply to: {message.text}")
message.chat.send_text("send big file as reply to: {}".format(message.text))
msg = message.chat.send_file(self.account.bigfile)
else:
msg = message.chat.send_text(f"got message id {message.id}, small text reply")
msg = message.chat.send_text("got message id {}, small text reply".format(message.id))
assert msg.text
self.log(f"message-sent: {msg}")
self.log("message-sent: {}".format(msg))
self.report_func(self, ReportType.message_echo)
if self.current_sent >= self.num_send:
self.report_func(self, ReportType.exit)

View File

@@ -216,7 +216,7 @@ def test_fetch_existing(acfactory, lp, mvbox_move):
# would also find the "Sent" folder, but it would be too late:
# The sentbox thread, started by `start_io()`, would have seen that there is no
# ConfiguredSentboxFolder and do nothing.
acfactory._acsetup.start_configure(ac1)
acfactory._acsetup.start_configure(ac1, reconfigure=True)
acfactory.bring_accounts_online()
assert_folders_configured(ac1)
@@ -239,7 +239,7 @@ def test_fetch_existing(acfactory, lp, mvbox_move):
ac1_clone.start_io()
assert_folders_configured(ac1_clone)
lp.sec("check that ac2 contact was fetched during configure")
lp.sec("check that ac2 contact was fetchted during configure")
ac1_clone._evtracker.get_matching("DC_EVENT_CONTACTS_CHANGED")
ac2_addr = ac2.get_config("addr")
assert any(c.addr == ac2_addr for c in ac1_clone.get_contacts())
@@ -537,54 +537,3 @@ def test_see_new_verified_member_after_going_online(acfactory, tmpdir, lp):
msg_in = ac1_offl._evtracker.wait_next_incoming_message()
assert msg_in.text == msg_out.text
assert msg_in.get_sender_contact().addr == ac2_addr
ac1.set_config("bcc_self", "0")
def test_use_new_verified_group_after_going_online(acfactory, tmpdir, lp):
"""Another test for the bug #3836:
- Bob has two devices, the second is offline.
- Alice creates a verified group and sends a QR invitation to Bob.
- Bob joins the group.
- Bob's second devices goes online, but sees a contact request instead of the verified group.
- The "member added" message is not a system message but a plain text message.
- Sending a message fails as the key is missing -- message info says "proper enc-key for <Alice>
missing, cannot encrypt".
"""
ac1, ac2 = acfactory.get_online_accounts(2)
ac2_offl = acfactory.new_online_configuring_account(cloned_from=ac2)
for ac in [ac2, ac2_offl]:
ac.set_config("bcc_self", "1")
acfactory.bring_accounts_online()
dir = tmpdir.mkdir("exportdir")
ac2.export_self_keys(dir.strpath)
ac2_offl.import_self_keys(dir.strpath)
ac2_offl.stop_io()
lp.sec("ac1: create verified-group QR, ac2 scans and joins")
chat = ac1.create_group_chat("hello", verified=True)
assert chat.is_protected()
qr = chat.get_join_qr()
lp.sec("ac2: start QR-code based join-group protocol")
ac2.qr_join_chat(qr)
ac1._evtracker.wait_securejoin_inviter_progress(1000)
lp.sec("ac2_offl: going online, checking the 'member added' message")
ac2_offl.start_io()
# Receive "Member Me (<addr>) added by <addr>." message.
msg_in = ac2_offl._evtracker.wait_next_incoming_message()
assert msg_in.is_system_message()
assert msg_in.get_sender_contact().addr == ac1.get_config("addr")
chat2 = msg_in.chat
assert chat2.is_protected()
lp.sec("ac2_offl: sending message")
msg_out = chat2.send_text("hello")
lp.sec("ac1: receiving message")
msg_in = ac1._evtracker.wait_next_incoming_message()
assert msg_in.chat == chat
assert msg_in.get_sender_contact().addr == ac2.get_config("addr")
assert msg_in.text == msg_out.text
ac2.set_config("bcc_self", "0")

View File

@@ -32,7 +32,7 @@ def test_basic_imap_api(acfactory, tmpdir):
imap2.shutdown()
@pytest.mark.ignored()
@pytest.mark.ignored
def test_configure_generate_key(acfactory, lp):
# A slow test which will generate new keys.
acfactory.remove_preconfigured_keys()
@@ -510,7 +510,7 @@ def test_send_and_receive_message_markseen(acfactory, lp):
idle2.wait_for_seen()
lp.step("1")
for _i in range(2):
for i in range(2):
ev = ac1._evtracker.get_matching("DC_EVENT_MSG_READ")
assert ev.data1 > const.DC_CHAT_ID_LAST_SPECIAL
assert ev.data2 > const.DC_MSG_ID_LAST_SPECIAL
@@ -529,7 +529,7 @@ def test_send_and_receive_message_markseen(acfactory, lp):
pass # mark_seen_messages() has generated events before it returns
def test_moved_markseen(acfactory):
def test_moved_markseen(acfactory, lp):
"""Test that message already moved to DeltaChat folder is marked as seen."""
ac1 = acfactory.new_online_configuring_account()
ac2 = acfactory.new_online_configuring_account(mvbox_move=True)
@@ -553,7 +553,7 @@ def test_moved_markseen(acfactory):
ac2.mark_seen_messages([msg])
uid = idle2.wait_for_seen()
assert len(list(ac2.direct_imap.conn.fetch(AND(seen=True, uid=U(uid, "*"))))) == 1
assert len([a for a in ac2.direct_imap.conn.fetch(AND(seen=True, uid=U(uid, "*")))]) == 1
def test_message_override_sender_name(acfactory, lp):
@@ -832,7 +832,7 @@ def test_send_first_message_as_long_unicode_with_cr(acfactory, lp):
lp.sec("sending multi-line non-unicode message from ac1 to ac2")
text1 = (
"hello\nworld\nthis is a very long message that should be"
" wrapped using format=flowed and unwrapped on the receiver"
+ " wrapped using format=flowed and unwrapped on the receiver"
)
msg_out = chat.send_text(text1)
assert not msg_out.is_encrypted()
@@ -894,7 +894,7 @@ def test_dont_show_emails(acfactory, lp):
message in Drafts that is moved to Sent later
""".format(
ac1.get_config("configured_addr"),
ac1.get_config("configured_addr")
),
)
ac1.direct_imap.append(
@@ -908,7 +908,7 @@ def test_dont_show_emails(acfactory, lp):
message in Sent
""".format(
ac1.get_config("configured_addr"),
ac1.get_config("configured_addr")
),
)
ac1.direct_imap.append(
@@ -922,7 +922,7 @@ def test_dont_show_emails(acfactory, lp):
Unknown message in Spam
""".format(
ac1.get_config("configured_addr"),
ac1.get_config("configured_addr")
),
)
ac1.direct_imap.append(
@@ -936,7 +936,7 @@ def test_dont_show_emails(acfactory, lp):
Unknown & malformed message in Spam
""".format(
ac1.get_config("configured_addr"),
ac1.get_config("configured_addr")
),
)
ac1.direct_imap.append(
@@ -950,7 +950,7 @@ def test_dont_show_emails(acfactory, lp):
Unknown & malformed message in Spam
""".format(
ac1.get_config("configured_addr"),
ac1.get_config("configured_addr")
),
)
ac1.direct_imap.append(
@@ -964,7 +964,7 @@ def test_dont_show_emails(acfactory, lp):
Actually interesting message in Spam
""".format(
ac1.get_config("configured_addr"),
ac1.get_config("configured_addr")
),
)
ac1.direct_imap.append(
@@ -978,7 +978,7 @@ def test_dont_show_emails(acfactory, lp):
Unknown message in Junk
""".format(
ac1.get_config("configured_addr"),
ac1.get_config("configured_addr")
),
)
@@ -1249,7 +1249,7 @@ def test_send_mark_seen_clean_incoming_events(acfactory, lp):
msg = ac2._evtracker.wait_next_incoming_message()
assert msg.text == "hello"
lp.sec(f"ac2: mark seen {msg}")
lp.sec("ac2: mark seen {}".format(msg))
msg.mark_seen()
for ev in ac1._evtracker.iter_events():
@@ -1437,8 +1437,9 @@ def test_import_export_online_all(acfactory, tmpdir, data, lp):
backupdir = tmpdir.mkdir("backup")
lp.sec(f"export all to {backupdir}")
lp.sec("export all to {}".format(backupdir))
with ac1.temp_plugin(ImexTracker()) as imex_tracker:
ac1.stop_io()
ac1.imex(backupdir.strpath, const.DC_IMEX_EXPORT_BACKUP)
@@ -1474,7 +1475,7 @@ def test_import_export_online_all(acfactory, tmpdir, data, lp):
assert_account_is_proper(ac1)
assert_account_is_proper(ac2)
lp.sec(f"Second-time export all to {backupdir}")
lp.sec("Second-time export all to {}".format(backupdir))
ac1.stop_io()
path2 = ac1.export_all(backupdir.strpath)
assert os.path.exists(path2)
@@ -1709,7 +1710,7 @@ def test_system_group_msg_from_blocked_user(acfactory, lp):
assert contact.is_blocked()
chat_on_ac2.remove_contact(ac1)
ac1._evtracker.get_matching("DC_EVENT_CHAT_MODIFIED")
assert ac1.get_self_contact() not in chat_on_ac1.get_contacts()
assert not ac1.get_self_contact() in chat_on_ac1.get_contacts()
def test_set_get_group_image(acfactory, data, lp):
@@ -1783,7 +1784,7 @@ def test_connectivity(acfactory, lp):
lp.sec(
"Test that after calling start_io(), maybe_network() and waiting for `all_work_done()`, "
"all messages are fetched",
+ "all messages are fetched"
)
ac1.direct_imap.select_config_folder("inbox")
@@ -2145,7 +2146,7 @@ def test_group_quote(acfactory, lp):
@pytest.mark.parametrize(
("folder", "move", "expected_destination"),
"folder,move,expected_destination,",
[
(
"xyz",
@@ -2260,44 +2261,11 @@ def test_aeap_flow_verified(acfactory, lp):
assert ac1new.get_config("addr") in [contact.addr for contact in msg_in_2.chat.get_contacts()]
def test_archived_muted_chat(acfactory, lp):
"""If an archived and muted chat receives a new message, DC_EVENT_MSGS_CHANGED for
DC_CHAT_ID_ARCHIVED_LINK must be generated if the chat had only seen messages previously.
"""
ac1, ac2 = acfactory.get_online_accounts(2)
chat = acfactory.get_accepted_chat(ac1, ac2)
lp.sec("ac1: send message to ac2")
chat.send_text("message0")
lp.sec("wait for ac2 to receive message")
msg2 = ac2._evtracker.wait_next_incoming_message()
assert msg2.text == "message0"
msg2.mark_seen()
chat2 = msg2.chat
chat2.archive()
chat2.mute()
lp.sec("ac1: send another message to ac2")
chat.send_text("message1")
lp.sec("wait for ac2 to receive DC_EVENT_MSGS_CHANGED for DC_CHAT_ID_ARCHIVED_LINK")
while 1:
ev = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
if ev.data1 == const.DC_CHAT_ID_ARCHIVED_LINK:
assert ev.data2 == 0
archive = ac2.get_chat_by_id(const.DC_CHAT_ID_ARCHIVED_LINK)
assert archive.count_fresh_messages() == 1
assert chat2.count_fresh_messages() == 1
break
class TestOnlineConfigureFails:
def test_invalid_password(self, acfactory):
configdict = acfactory.get_next_liveconfig()
ac1 = acfactory.get_unconfigured_account()
ac1.update_config({"addr": configdict["addr"], "mail_pw": "123"})
ac1.update_config(dict(addr=configdict["addr"], mail_pw="123"))
configtracker = ac1.configure()
configtracker.wait_progress(500)
configtracker.wait_progress(0)

View File

@@ -1,3 +1,5 @@
from __future__ import print_function
import os.path
import shutil
from filecmp import cmp
@@ -15,7 +17,7 @@ def wait_msg_delivered(account, msg_list):
def wait_msgs_changed(account, msgs_list):
"""wait for one or more MSGS_CHANGED events to match msgs_list contents."""
account.log(f"waiting for msgs_list={msgs_list}")
account.log("waiting for msgs_list={}".format(msgs_list))
msgs_list = list(msgs_list)
while msgs_list:
ev = account._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
@@ -25,7 +27,7 @@ def wait_msgs_changed(account, msgs_list):
del msgs_list[i]
break
else:
account.log(f"waiting mismatch data1={data1} data2={data2}")
account.log("waiting mismatch data1={} data2={}".format(data1, data2))
return ev.data1, ev.data2

View File

@@ -1,3 +1,5 @@
from __future__ import print_function
import os
import time
from datetime import datetime, timedelta, timezone
@@ -13,7 +15,7 @@ from deltachat.tracker import ImexFailed
@pytest.mark.parametrize(
("msgtext", "res"),
"msgtext,res",
[
(
"Member Me (tmp1@x.org) removed by tmp2@x.org.",
@@ -106,7 +108,7 @@ class TestOfflineAccountBasic:
def test_update_config(self, acfactory):
ac1 = acfactory.get_unconfigured_account()
ac1.update_config({"mvbox_move": False})
ac1.update_config(dict(mvbox_move=False))
assert ac1.get_config("mvbox_move") == "0"
def test_has_savemime(self, acfactory):
@@ -227,11 +229,11 @@ class TestOfflineContact:
class TestOfflineChat:
@pytest.fixture()
@pytest.fixture
def ac1(self, acfactory):
return acfactory.get_pseudo_configured_account()
@pytest.fixture()
@pytest.fixture
def chat1(self, ac1):
return ac1.create_contact("some1@example.org", name="some1").create_chat()
@@ -255,7 +257,7 @@ class TestOfflineChat:
assert chat2.id == chat1.id
assert chat2.get_name() == chat1.get_name()
assert chat1 == chat2
assert not chat1.__ne__(chat2)
assert not (chat1 != chat2)
assert chat1 != chat3
for ichat in ac1.get_chats():
@@ -448,7 +450,7 @@ class TestOfflineChat:
assert msg.filemime == "image/png"
@pytest.mark.parametrize(
("fn", "typein", "typeout"),
"fn,typein,typeout",
[
("r", None, "application/octet-stream"),
("r.txt", None, "text/plain"),
@@ -456,7 +458,7 @@ class TestOfflineChat:
("r.txt", "image/png", "image/png"),
],
)
def test_message_file(self, chat1, data, lp, fn, typein, typeout):
def test_message_file(self, ac1, chat1, data, lp, fn, typein, typeout):
lp.sec("sending file")
fp = data.get_path(fn)
msg = chat1.send_file(fp, typein)
@@ -692,7 +694,7 @@ class TestOfflineChat:
chat1.set_draft(None)
assert chat1.get_draft() is None
def test_qr_setup_contact(self, acfactory):
def test_qr_setup_contact(self, acfactory, lp):
ac1 = acfactory.get_pseudo_configured_account()
ac2 = acfactory.get_pseudo_configured_account()
qr = ac1.get_setup_contact_qr()
@@ -742,7 +744,7 @@ class TestOfflineChat:
contacts = []
for i in range(10):
lp.sec("create contact")
contact = ac1.create_contact(f"some{i}@example.org")
contact = ac1.create_contact("some{}@example.org".format(i))
contacts.append(contact)
lp.sec("add contact")
chat.add_contact(contact)

View File

@@ -93,7 +93,7 @@ def test_empty_context():
capi.lib.dc_context_unref(ctx)
def test_dc_close_events(acfactory):
def test_dc_close_events(tmpdir, acfactory):
ac1 = acfactory.get_unconfigured_account()
# register after_shutdown function

View File

@@ -50,14 +50,18 @@ commands =
skipsdist = True
skip_install = True
deps =
ruff
flake8
# isort 5.11.0 is broken: https://github.com/PyCQA/isort/issues/2031
isort<5.11.0
black
# pygments required by rst-lint
pygments
restructuredtext_lint
commands =
black --check --diff setup.py install_python_bindings.py src/deltachat examples/ tests/
ruff src/deltachat tests/ examples/
isort --check setup.py install_python_bindings.py src/deltachat examples/ tests/
black --check setup.py install_python_bindings.py src/deltachat examples/ tests/
flake8 src/deltachat
flake8 tests/ examples/
rst-lint --encoding 'utf-8' README.rst
[testenv:mypy]
@@ -98,3 +102,7 @@ timeout = 150
timeout_func_only = True
markers =
ignored: ignore this test in default test runs, use --ignored to run.
[flake8]
max-line-length = 120
ignore = E203, E266, E501, W503

View File

@@ -6,8 +6,6 @@ and an own build machine.
## Description of scripts
- `clippy.sh` runs `cargo clippy` for all Rust code in the project.
- `../.github/workflows` contains jobs run by GitHub Actions.
- `remote_tests_python.sh` rsyncs to a build machine and runs

View File

@@ -2,13 +2,12 @@
Remove old "dc" indices except for master which always stays.
"""
import datetime
import subprocess
import sys
from requests import Session
import datetime
import sys
import subprocess
MAXDAYS = 7
MAXDAYS=7
session = Session()
session.headers["Accept"] = "application/json"
@@ -55,8 +54,7 @@ def run():
if not dates:
print(
"%s has no releases" % (baseurl + username + "/" + indexname),
file=sys.stderr,
)
file=sys.stderr)
date = datetime.datetime.now()
else:
date = datetime.datetime(*max(dates))
@@ -69,5 +67,6 @@ def run():
subprocess.check_call(["devpi", "index", "-y", "--delete", url])
if __name__ == "__main__":
if __name__ == '__main__':
run()

View File

@@ -1,3 +0,0 @@
#!/bin/sh
# Run clippy for all Rust code in the project.
cargo clippy --workspace --tests --examples --benches -- -D warnings

View File

@@ -31,7 +31,7 @@ unset DCC_NEW_TMP_EMAIL
# Try to build wheels for a range of interpreters, but don't fail if they are not available.
# E.g. musllinux_1_1 does not have PyPy interpreters as of 2022-07-10
tox --workdir "$TOXWORKDIR" -e py37,py38,py39,py310,py311,pypy37,pypy38,pypy39,auditwheels --skip-missing-interpreters true
tox --workdir "$TOXWORKDIR" -e py37,py38,py39,py310,pypy37,pypy38,pypy39,auditwheels --skip-missing-interpreters true
echo -----------------------

View File

@@ -1,9 +1,9 @@
#!/usr/bin/env python3
import json
import os
import pathlib
import json
import re
import pathlib
import subprocess
from argparse import ArgumentParser
@@ -23,7 +23,7 @@ def read_toml_version(relpath):
res = regex_matches(relpath, rex)
if res is not None:
return res.group(1)
raise ValueError(f"no version found in {relpath}")
raise ValueError("no version found in {}".format(relpath))
def replace_toml_version(relpath, newversion):
@@ -34,8 +34,8 @@ def replace_toml_version(relpath, newversion):
for line in open(str(p)):
m = rex.match(line)
if m is not None:
print(f"{relpath}: set version={newversion}")
f.write(f'version = "{newversion}"\n')
print("{}: set version={}".format(relpath, newversion))
f.write('version = "{}"\n'.format(newversion))
else:
f.write(line)
os.rename(tmp_path, str(p))
@@ -44,7 +44,7 @@ def replace_toml_version(relpath, newversion):
def read_json_version(relpath):
p = pathlib.Path(relpath)
assert p.exists()
with open(p) as f:
with open(p, "r") as f:
json_data = json.loads(f.read())
return json_data["version"]
@@ -52,7 +52,7 @@ def read_json_version(relpath):
def update_package_json(relpath, newversion):
p = pathlib.Path(relpath)
assert p.exists()
with open(p) as f:
with open(p, "r") as f:
json_data = json.loads(f.read())
json_data["version"] = newversion
with open(p, "w") as f:
@@ -63,22 +63,21 @@ def main():
parser = ArgumentParser(prog="set_core_version")
parser.add_argument("newversion")
json_list = ["package.json", "deltachat-jsonrpc/typescript/package.json"]
json_list = ["package.json", "deltachat-jsonrpc/typescript/package.json"]
toml_list = [
"Cargo.toml",
"deltachat-ffi/Cargo.toml",
"deltachat-jsonrpc/Cargo.toml",
"deltachat-rpc-server/Cargo.toml",
"deltachat-repl/Cargo.toml",
]
try:
opts = parser.parse_args()
except SystemExit:
print()
for x in toml_list:
print(f"{x}: {read_toml_version(x)}")
print("{}: {}".format(x, read_toml_version(x)))
for x in json_list:
print(f"{x}: {read_json_version(x)}")
print("{}: {}".format(x, read_json_version(x)))
print()
raise SystemExit("need argument: new version, example: 1.25.0")
@@ -93,19 +92,19 @@ def main():
if "alpha" not in newversion:
for line in open("CHANGELOG.md"):
## 1.25.0
if line.startswith("## ") and line[2:].strip().startswith(newversion):
break
if line.startswith("## "):
if line[2:].strip().startswith(newversion):
break
else:
raise SystemExit(
f"CHANGELOG.md contains no entry for version: {newversion}"
)
raise SystemExit("CHANGELOG.md contains no entry for version: {}".format(newversion))
for toml_filename in toml_list:
replace_toml_version(toml_filename, newversion)
for json_filename in json_list:
update_package_json(json_filename, newversion)
print("running cargo check")
subprocess.call(["cargo", "check"])
@@ -115,12 +114,13 @@ def main():
print("after commit, on master make sure to: ")
print("")
print(f" git tag -a {newversion}")
print(f" git push origin {newversion}")
print(f" git tag -a py-{newversion}")
print(f" git push origin py-{newversion}")
print(" git tag -a {}".format(newversion))
print(" git push origin {}".format(newversion))
print(" git tag -a py-{}".format(newversion))
print(" git push origin py-{}".format(newversion))
print("")
if __name__ == "__main__":
main()

View File

@@ -1,7 +1,6 @@
//! # Account manager module.
use std::collections::BTreeMap;
use std::future::Future;
use std::path::{Path, PathBuf};
use anyhow::{ensure, Context as _, Result};
@@ -144,16 +143,34 @@ impl Accounts {
let ctx = self
.accounts
.remove(&id)
.with_context(|| format!("no account with id {id}"))?;
.with_context(|| format!("no account with id {}", id))?;
ctx.stop_io().await;
drop(ctx);
if let Some(cfg) = self.config.get_account(id) {
let account_path = self.dir.join(cfg.dir);
try_many_times(|| fs::remove_dir_all(&account_path))
.await
.context("failed to remove account data")?;
// Spend up to 1 minute trying to remove the files.
// Files may remain locked up to 30 seconds due to r2d2 bug:
// https://github.com/sfackler/r2d2/issues/99
let mut counter = 0;
loop {
counter += 1;
if let Err(err) = fs::remove_dir_all(&account_path)
.await
.context("failed to remove account data")
{
if counter > 60 {
return Err(err);
}
// Wait 1 second and try again.
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
} else {
break;
}
}
}
self.config.remove_account(id).await?;
@@ -161,8 +178,6 @@ impl Accounts {
}
/// Migrate an existing account into this structure.
///
/// Returns the ID of new account.
pub async fn migrate_account(&mut self, dbfile: PathBuf) -> Result<u32> {
let blobdir = Context::derive_blobdir(&dbfile);
let walfile = Context::derive_walfile(&dbfile);
@@ -187,10 +202,10 @@ impl Accounts {
fs::create_dir_all(self.dir.join(&account_config.dir))
.await
.context("failed to create dir")?;
try_many_times(|| fs::rename(&dbfile, &new_dbfile))
fs::rename(&dbfile, &new_dbfile)
.await
.context("failed to rename dbfile")?;
try_many_times(|| fs::rename(&blobdir, &new_blobdir))
fs::rename(&blobdir, &new_blobdir)
.await
.context("failed to rename blobdir")?;
if walfile.exists() {
@@ -214,10 +229,11 @@ impl Accounts {
Ok(account_config.id)
}
Err(err) => {
let account_path = std::path::PathBuf::from(&account_config.dir);
try_many_times(|| fs::remove_dir_all(&account_path))
// remove temp account
fs::remove_dir_all(std::path::PathBuf::from(&account_config.dir))
.await
.context("failed to remove account data")?;
self.config.remove_account(account_config.id).await?;
// set selection back
@@ -347,8 +363,7 @@ impl Config {
pub async fn from_file(file: PathBuf) -> Result<Self> {
let dir = file.parent().context("can't get config file directory")?;
let bytes = fs::read(&file).await.context("failed to read file")?;
let s = std::str::from_utf8(&bytes)?;
let mut inner: InnerConfig = toml::from_str(s).context("failed to parse config")?;
let mut inner: InnerConfig = toml::from_slice(&bytes).context("failed to parse config")?;
// Previous versions of the core stored absolute paths in account config.
// Convert them to relative paths.
@@ -472,33 +487,6 @@ impl Config {
}
}
/// Spend up to 1 minute trying to do the operation.
///
/// Files may remain locked up to 30 seconds due to r2d2 bug:
/// <https://github.com/sfackler/r2d2/issues/99>
async fn try_many_times<F, Fut, T>(f: F) -> std::result::Result<(), T>
where
F: Fn() -> Fut,
Fut: Future<Output = std::result::Result<(), T>>,
{
let mut counter = 0;
loop {
counter += 1;
if let Err(err) = f().await {
if counter > 60 {
return Err(err);
}
// Wait 1 second and try again.
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
} else {
break;
}
}
Ok(())
}
/// Configuration of a single account.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
struct AccountConfig {
@@ -521,6 +509,7 @@ impl AccountConfig {
#[cfg(test)]
mod tests {
use super::*;
use crate::stock_str::{self, StockMessage};
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]

View File

@@ -2,24 +2,28 @@
//!
//! Parse and create [Autocrypt-headers](https://autocrypt.org/en/latest/level1.html#the-autocrypt-header).
use anyhow::{bail, Context as _, Error, Result};
use std::collections::BTreeMap;
use std::fmt;
use std::str::FromStr;
use anyhow::{bail, Context as _, Error, Result};
use crate::key::{DcKey, SignedPublicKey};
/// Possible values for encryption preference
#[derive(PartialEq, Eq, Debug, Default, Clone, Copy, FromPrimitive, ToPrimitive)]
#[derive(PartialEq, Eq, Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
#[repr(u8)]
pub enum EncryptPreference {
#[default]
NoPreference = 0,
Mutual = 1,
Reset = 20,
}
impl Default for EncryptPreference {
fn default() -> Self {
EncryptPreference::NoPreference
}
}
impl fmt::Display for EncryptPreference {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
match *self {
@@ -85,7 +89,7 @@ impl fmt::Display for Aheader {
res
},
);
write!(fmt, " keydata={keydata}")
write!(fmt, " keydata={}", keydata)
}
}
@@ -147,8 +151,11 @@ mod tests {
#[test]
fn test_from_str() -> Result<()> {
let h: Aheader =
format!("addr=me@mail.com; prefer-encrypt=mutual; keydata={RAWKEY}").parse()?;
let h: Aheader = format!(
"addr=me@mail.com; prefer-encrypt=mutual; keydata={}",
RAWKEY
)
.parse()?;
assert_eq!(h.addr, "me@mail.com");
assert_eq!(h.prefer_encrypt, EncryptPreference::Mutual);
@@ -158,7 +165,10 @@ mod tests {
// EncryptPreference::Reset is an internal value, parser should never return it
#[test]
fn test_from_str_reset() -> Result<()> {
let raw = format!("addr=reset@example.com; prefer-encrypt=reset; keydata={RAWKEY}");
let raw = format!(
"addr=reset@example.com; prefer-encrypt=reset; keydata={}",
RAWKEY
);
let h: Aheader = raw.parse()?;
assert_eq!(h.addr, "reset@example.com");
@@ -168,7 +178,7 @@ mod tests {
#[test]
fn test_from_str_non_critical() -> Result<()> {
let raw = format!("addr=me@mail.com; _foo=one; _bar=two; keydata={RAWKEY}");
let raw = format!("addr=me@mail.com; _foo=one; _bar=two; keydata={}", RAWKEY);
let h: Aheader = raw.parse()?;
assert_eq!(h.addr, "me@mail.com");
@@ -178,7 +188,10 @@ mod tests {
#[test]
fn test_from_str_superflous_critical() {
let raw = format!("addr=me@mail.com; _foo=one; _bar=two; other=me; keydata={RAWKEY}");
let raw = format!(
"addr=me@mail.com; _foo=one; _bar=two; other=me; keydata={}",
RAWKEY
);
assert!(raw.parse::<Aheader>().is_err());
}
@@ -212,20 +225,21 @@ mod tests {
let ah = Aheader::from_str(fixed_header)?;
assert_eq!(ah.addr, "a@b.example.org");
assert_eq!(ah.prefer_encrypt, EncryptPreference::Mutual);
assert_eq!(format!("{ah}"), fixed_header);
assert_eq!(format!("{}", ah), fixed_header);
let rendered = ah.to_string();
assert_eq!(rendered, fixed_header);
let ah = Aheader::from_str(&format!(" _foo; __FOO=BAR ;;; addr = a@b.example.org ;\r\n prefer-encrypt = mutual ; keydata = {RAWKEY}"))?;
let ah = Aheader::from_str(&format!(" _foo; __FOO=BAR ;;; addr = a@b.example.org ;\r\n prefer-encrypt = mutual ; keydata = {}", RAWKEY))?;
assert_eq!(ah.addr, "a@b.example.org");
assert_eq!(ah.prefer_encrypt, EncryptPreference::Mutual);
Aheader::from_str(&format!(
"addr=a@b.example.org; prefer-encrypt=ignoreUnknownValues; keydata={RAWKEY}"
"addr=a@b.example.org; prefer-encrypt=ignoreUnknownValues; keydata={}",
RAWKEY
))?;
Aheader::from_str(&format!("addr=a@b.example.org; keydata={RAWKEY}"))?;
Aheader::from_str(&format!("addr=a@b.example.org; keydata={}", RAWKEY))?;
Ok(())
}

View File

@@ -355,6 +355,7 @@ mod tests {
use tokio::io::AsyncReadExt;
use super::*;
use crate::aheader::EncryptPreference;
use crate::e2ee;
use crate::message;
@@ -644,6 +645,7 @@ Authentication-Results: dkim=";
.unwrap();
}
#[ignore = "Disallowing keychanges is disabled for now"]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_handle_authres_fails() -> Result<()> {
let mut tcm = TestContextManager::new();
@@ -821,7 +823,8 @@ Authentication-Results: dkim=";
.insert_str(0, "Authentication-Results: example.net; dkim=fail\n");
let rcvd = bob.recv_msg(&sent).await;
assert!(rcvd.error.unwrap().contains("DKIM failed"));
// Disallowing keychanges is disabled for now:
// assert!(rcvd.error.unwrap().contains("DKIM failed"));
// The message info should contain a warning:
assert!(message::get_msg_info(&bob, rcvd.id)
.await

Some files were not shown because too many files have changed in this diff Show More