mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 13:36:30 +03:00
Compare commits
5 Commits
v1.147.0
...
link2xt/sq
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5820c4ce95 | ||
|
|
12ba33d9d4 | ||
|
|
60a7bbc9b5 | ||
|
|
e9f434b562 | ||
|
|
2423cb8175 |
7
.github/dependabot.yml
vendored
7
.github/dependabot.yml
vendored
@@ -7,10 +7,3 @@ updates:
|
|||||||
commit-message:
|
commit-message:
|
||||||
prefix: "chore(cargo)"
|
prefix: "chore(cargo)"
|
||||||
open-pull-requests-limit: 50
|
open-pull-requests-limit: 50
|
||||||
|
|
||||||
# Keep GitHub Actions up to date.
|
|
||||||
# <https://docs.github.com/en/code-security/dependabot/working-with-dependabot/keeping-your-actions-up-to-date-with-dependabot>
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
|
|||||||
34
.github/workflows/ci.yml
vendored
34
.github/workflows/ci.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
|||||||
name: Lint Rust
|
name: Lint Rust
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
RUSTUP_TOOLCHAIN: 1.81.0
|
RUSTUP_TOOLCHAIN: 1.77.1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
@@ -40,18 +40,6 @@ jobs:
|
|||||||
- name: Check
|
- name: Check
|
||||||
run: cargo check --workspace --all-targets --all-features
|
run: cargo check --workspace --all-targets --all-features
|
||||||
|
|
||||||
npm_constants:
|
|
||||||
name: Check if node constants are up to date
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
show-progress: false
|
|
||||||
- name: Rebuild constants
|
|
||||||
run: npm run build:core:constants
|
|
||||||
- name: Check that constants are not changed
|
|
||||||
run: git diff --exit-code
|
|
||||||
|
|
||||||
cargo_deny:
|
cargo_deny:
|
||||||
name: cargo deny
|
name: cargo deny
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -59,7 +47,7 @@ jobs:
|
|||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
show-progress: false
|
show-progress: false
|
||||||
- uses: EmbarkStudios/cargo-deny-action@v2
|
- uses: EmbarkStudios/cargo-deny-action@v1
|
||||||
with:
|
with:
|
||||||
arguments: --all-features --workspace
|
arguments: --all-features --workspace
|
||||||
command: check
|
command: check
|
||||||
@@ -95,11 +83,11 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
rust: 1.81.0
|
rust: 1.77.1
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
rust: 1.81.0
|
rust: 1.77.1
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
rust: 1.81.0
|
rust: 1.77.1
|
||||||
|
|
||||||
# Minimum Supported Rust Version = 1.77.0
|
# Minimum Supported Rust Version = 1.77.0
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
@@ -117,20 +105,10 @@ jobs:
|
|||||||
- name: Cache rust cargo artifacts
|
- name: Cache rust cargo artifacts
|
||||||
uses: swatinem/rust-cache@v2
|
uses: swatinem/rust-cache@v2
|
||||||
|
|
||||||
- name: Install nextest
|
|
||||||
uses: taiki-e/install-action@v2
|
|
||||||
with:
|
|
||||||
tool: nextest
|
|
||||||
|
|
||||||
- name: Tests
|
- name: Tests
|
||||||
env:
|
env:
|
||||||
RUST_BACKTRACE: 1
|
RUST_BACKTRACE: 1
|
||||||
run: cargo nextest run --workspace
|
run: cargo test --workspace
|
||||||
|
|
||||||
- name: Doc-Tests
|
|
||||||
env:
|
|
||||||
RUST_BACKTRACE: 1
|
|
||||||
run: cargo test --workspace --doc
|
|
||||||
|
|
||||||
- name: Test cargo vendor
|
- name: Test cargo vendor
|
||||||
run: cargo vendor
|
run: cargo vendor
|
||||||
|
|||||||
138
.github/workflows/deltachat-rpc-server.yml
vendored
138
.github/workflows/deltachat-rpc-server.yml
vendored
@@ -266,141 +266,3 @@ jobs:
|
|||||||
- name: Publish deltachat-rpc-client to PyPI
|
- name: Publish deltachat-rpc-client to PyPI
|
||||||
if: github.event_name == 'release'
|
if: github.event_name == 'release'
|
||||||
uses: pypa/gh-action-pypi-publish@release/v1
|
uses: pypa/gh-action-pypi-publish@release/v1
|
||||||
|
|
||||||
publish_npm_package:
|
|
||||||
name: Build & Publish npm prebuilds and deltachat-rpc-server
|
|
||||||
needs: ["build_linux", "build_windows", "build_macos"]
|
|
||||||
runs-on: "ubuntu-latest"
|
|
||||||
permissions:
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
# Needed to publish the binaries to the release.
|
|
||||||
contents: write
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
show-progress: false
|
|
||||||
- uses: actions/setup-python@v5
|
|
||||||
with:
|
|
||||||
python-version: "3.11"
|
|
||||||
|
|
||||||
- name: Download Linux aarch64 binary
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-aarch64-linux
|
|
||||||
path: deltachat-rpc-server-aarch64-linux.d
|
|
||||||
|
|
||||||
- name: Download Linux armv7l binary
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-armv7l-linux
|
|
||||||
path: deltachat-rpc-server-armv7l-linux.d
|
|
||||||
|
|
||||||
- name: Download Linux armv6l binary
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-armv6l-linux
|
|
||||||
path: deltachat-rpc-server-armv6l-linux.d
|
|
||||||
|
|
||||||
- name: Download Linux i686 binary
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-i686-linux
|
|
||||||
path: deltachat-rpc-server-i686-linux.d
|
|
||||||
|
|
||||||
- name: Download Linux x86_64 binary
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-x86_64-linux
|
|
||||||
path: deltachat-rpc-server-x86_64-linux.d
|
|
||||||
|
|
||||||
- name: Download Win32 binary
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-win32
|
|
||||||
path: deltachat-rpc-server-win32.d
|
|
||||||
|
|
||||||
- name: Download Win64 binary
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-win64
|
|
||||||
path: deltachat-rpc-server-win64.d
|
|
||||||
|
|
||||||
- name: Download macOS binary for x86_64
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-x86_64-macos
|
|
||||||
path: deltachat-rpc-server-x86_64-macos.d
|
|
||||||
|
|
||||||
- name: Download macOS binary for aarch64
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-aarch64-macos
|
|
||||||
path: deltachat-rpc-server-aarch64-macos.d
|
|
||||||
|
|
||||||
- name: Download Android binary for arm64-v8a
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-arm64-v8a-android
|
|
||||||
path: deltachat-rpc-server-arm64-v8a-android.d
|
|
||||||
|
|
||||||
- name: Download Android binary for armeabi-v7a
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-armeabi-v7a-android
|
|
||||||
path: deltachat-rpc-server-armeabi-v7a-android.d
|
|
||||||
|
|
||||||
- name: make npm packets for prebuilds and `@deltachat/stdio-rpc-server`
|
|
||||||
run: |
|
|
||||||
cd deltachat-rpc-server/npm-package
|
|
||||||
|
|
||||||
python --version
|
|
||||||
|
|
||||||
python scripts/pack_binary_for_platform.py aarch64-unknown-linux-musl ../../deltachat-rpc-server-aarch64-linux.d/deltachat-rpc-server
|
|
||||||
python scripts/pack_binary_for_platform.py armv7-unknown-linux-musleabihf ../../deltachat-rpc-server-armv7l-linux.d/deltachat-rpc-server
|
|
||||||
python scripts/pack_binary_for_platform.py arm-unknown-linux-musleabihf ../../deltachat-rpc-server-armv6l-linux.d/deltachat-rpc-server
|
|
||||||
python scripts/pack_binary_for_platform.py i686-unknown-linux-musl ../../deltachat-rpc-server-i686-linux.d/deltachat-rpc-server
|
|
||||||
python scripts/pack_binary_for_platform.py x86_64-unknown-linux-musl ../../deltachat-rpc-server-x86_64-linux.d/deltachat-rpc-server
|
|
||||||
python scripts/pack_binary_for_platform.py i686-pc-windows-gnu ../../deltachat-rpc-server-win32.d/deltachat-rpc-server.exe
|
|
||||||
python scripts/pack_binary_for_platform.py x86_64-pc-windows-gnu ../../deltachat-rpc-server-win64.d/deltachat-rpc-server.exe
|
|
||||||
python scripts/pack_binary_for_platform.py x86_64-apple-darwin ../../deltachat-rpc-server-x86_64-macos.d/deltachat-rpc-server
|
|
||||||
python scripts/pack_binary_for_platform.py aarch64-apple-darwin ../../deltachat-rpc-server-aarch64-macos.d/deltachat-rpc-server
|
|
||||||
python scripts/pack_binary_for_platform.py aarch64-linux-android ../../deltachat-rpc-server-arm64-v8a-android.d/deltachat-rpc-server
|
|
||||||
python scripts/pack_binary_for_platform.py armv7-linux-androideabi ../../deltachat-rpc-server-armeabi-v7a-android.d/deltachat-rpc-server
|
|
||||||
|
|
||||||
ls -lah platform_package
|
|
||||||
|
|
||||||
for platform in ./platform_package/*; do npm pack "$platform"; done
|
|
||||||
npm pack
|
|
||||||
ls -lah
|
|
||||||
|
|
||||||
- name: Upload to artifacts
|
|
||||||
uses: actions/upload-artifact@v4
|
|
||||||
with:
|
|
||||||
name: deltachat-rpc-server-npm-package
|
|
||||||
path: deltachat-rpc-server/npm-package/*.tgz
|
|
||||||
if-no-files-found: error
|
|
||||||
|
|
||||||
- name: Upload npm packets to the GitHub release
|
|
||||||
if: github.event_name == 'release'
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
|
|
||||||
run: |
|
|
||||||
gh release upload ${{ github.ref_name }} \
|
|
||||||
--repo ${{ github.repository }} \
|
|
||||||
deltachat-rpc-server/npm-package/*.tgz
|
|
||||||
|
|
||||||
# Configure Node.js for publishing.
|
|
||||||
- uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: 20
|
|
||||||
registry-url: "https://registry.npmjs.org"
|
|
||||||
|
|
||||||
- name: Publish npm packets for prebuilds and `@deltachat/stdio-rpc-server`
|
|
||||||
if: github.event_name == 'release'
|
|
||||||
working-directory: deltachat-rpc-server/npm-package
|
|
||||||
run: |
|
|
||||||
ls -lah platform_package
|
|
||||||
for platform in *.tgz; do npm publish --provenance "$platform" --access public; done
|
|
||||||
env:
|
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
||||||
|
|||||||
2
.github/workflows/dependabot.yml
vendored
2
.github/workflows/dependabot.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Dependabot metadata
|
- name: Dependabot metadata
|
||||||
id: metadata
|
id: metadata
|
||||||
uses: dependabot/fetch-metadata@v2.2.0
|
uses: dependabot/fetch-metadata@v1.1.1
|
||||||
with:
|
with:
|
||||||
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
github-token: "${{ secrets.GITHUB_TOKEN }}"
|
||||||
- name: Approve a PR
|
- name: Approve a PR
|
||||||
|
|||||||
80
.github/workflows/jsonrpc-client-npm-package.yml
vendored
80
.github/workflows/jsonrpc-client-npm-package.yml
vendored
@@ -1,38 +1,82 @@
|
|||||||
name: "Publish @deltachat/jsonrpc-client"
|
name: "jsonrpc js client build"
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
pull_request:
|
||||||
release:
|
push:
|
||||||
types: [published]
|
tags:
|
||||||
|
- "*"
|
||||||
|
- "!py-*"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pack-module:
|
pack-module:
|
||||||
name: "Publish @deltachat/jsonrpc-client"
|
name: "Package @deltachat/jsonrpc-client and upload to download.delta.chat"
|
||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
permissions:
|
|
||||||
id-token: write
|
|
||||||
contents: read
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Install tree
|
||||||
|
run: sudo apt install tree
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
show-progress: false
|
show-progress: false
|
||||||
|
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 20
|
node-version: "18"
|
||||||
registry-url: "https://registry.npmjs.org"
|
- name: Get tag
|
||||||
|
id: tag
|
||||||
|
uses: dawidd6/action-get-tag@v1
|
||||||
|
continue-on-error: true
|
||||||
|
- name: Get Pull Request ID
|
||||||
|
id: prepare
|
||||||
|
run: |
|
||||||
|
tag=${{ steps.tag.outputs.tag }}
|
||||||
|
if [ -z "$tag" ]; then
|
||||||
|
node -e "console.log('DELTACHAT_JSONRPC_TAR_GZ=deltachat-jsonrpc-client-' + '${{ github.ref }}'.split('/')[2] + '.tar.gz')" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "DELTACHAT_JSONRPC_TAR_GZ=deltachat-jsonrpc-client-${{ steps.tag.outputs.tag }}.tar.gz" >> $GITHUB_ENV
|
||||||
|
echo "No preview will be uploaded this time, but the $tag release"
|
||||||
|
fi
|
||||||
|
- name: System info
|
||||||
|
run: |
|
||||||
|
npm --version
|
||||||
|
node --version
|
||||||
|
echo $DELTACHAT_JSONRPC_TAR_GZ
|
||||||
- name: Install dependencies without running scripts
|
- name: Install dependencies without running scripts
|
||||||
working-directory: deltachat-jsonrpc/typescript
|
working-directory: deltachat-jsonrpc/typescript
|
||||||
run: npm install --ignore-scripts
|
run: npm install --ignore-scripts
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
|
shell: bash
|
||||||
working-directory: deltachat-jsonrpc/typescript
|
working-directory: deltachat-jsonrpc/typescript
|
||||||
run: |
|
run: |
|
||||||
npm run build
|
npm run build
|
||||||
npm pack .
|
npm pack .
|
||||||
|
ls -lah
|
||||||
- name: Publish
|
mv $(find deltachat-jsonrpc-client-*) $DELTACHAT_JSONRPC_TAR_GZ
|
||||||
working-directory: deltachat-jsonrpc/typescript
|
- name: Upload Prebuild
|
||||||
run: npm publish --provenance deltachat-jsonrpc-client-* --access public
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: deltachat-jsonrpc-client.tgz
|
||||||
|
path: deltachat-jsonrpc/typescript/${{ env.DELTACHAT_JSONRPC_TAR_GZ }}
|
||||||
|
# Upload to download.delta.chat/node/preview/
|
||||||
|
- name: Upload deltachat-jsonrpc-client preview to download.delta.chat/node/preview/
|
||||||
|
if: ${{ ! steps.tag.outputs.tag }}
|
||||||
|
id: upload-preview
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo -e "${{ secrets.SSH_KEY }}" >__TEMP_INPUT_KEY_FILE
|
||||||
|
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
|
||||||
|
if: steps.upload-preview.outcome == 'success'
|
||||||
|
run: node ./node/scripts/postLinksToDetails.js
|
||||||
env:
|
env:
|
||||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
URL: preview/${{ env.DELTACHAT_JSONRPC_TAR_GZ }}
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
MSG_CONTEXT: Download the deltachat-jsonrpc-client.tgz
|
||||||
|
# Upload to download.delta.chat/node/
|
||||||
|
- name: Upload deltachat-jsonrpc-client build to download.delta.chat/node/
|
||||||
|
if: ${{ steps.tag.outputs.tag }}
|
||||||
|
id: upload
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
echo -e "${{ secrets.SSH_KEY }}" >__TEMP_INPUT_KEY_FILE
|
||||||
|
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/"
|
||||||
|
|||||||
2
.github/workflows/node-docs.yml
vendored
2
.github/workflows/node-docs.yml
vendored
@@ -31,7 +31,7 @@ jobs:
|
|||||||
mv docs js
|
mv docs js
|
||||||
|
|
||||||
- name: Upload
|
- name: Upload
|
||||||
uses: horochx/deploy-via-scp@1.1.0
|
uses: horochx/deploy-via-scp@v1.0.1
|
||||||
with:
|
with:
|
||||||
user: ${{ secrets.USERNAME }}
|
user: ${{ secrets.USERNAME }}
|
||||||
key: ${{ secrets.KEY }}
|
key: ${{ secrets.KEY }}
|
||||||
|
|||||||
45
.github/workflows/upload-docs.yml
vendored
45
.github/workflows/upload-docs.yml
vendored
@@ -1,10 +1,9 @@
|
|||||||
name: Build & deploy documentation on rs.delta.chat, c.delta.chat, and py.delta.chat
|
name: Build & Deploy Documentation on rs.delta.chat, c.delta.chat, py.delta.chat
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
- build_jsonrpc_docs_ci
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-rs:
|
build-rs:
|
||||||
@@ -18,11 +17,13 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
cargo doc --package deltachat --no-deps --document-private-items
|
cargo doc --package deltachat --no-deps --document-private-items
|
||||||
- name: Upload to rs.delta.chat
|
- name: Upload to rs.delta.chat
|
||||||
run: |
|
uses: up9cloud/action-rsync@v1.3
|
||||||
mkdir -p "$HOME/.ssh"
|
env:
|
||||||
echo "${{ secrets.KEY }}" > "$HOME/.ssh/key"
|
USER: ${{ secrets.USERNAME }}
|
||||||
chmod 600 "$HOME/.ssh/key"
|
KEY: ${{ secrets.KEY }}
|
||||||
rsync -avzh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/target/doc "${{ secrets.USERNAME }}@rs.delta.chat:/var/www/html/rs/"
|
HOST: "delta.chat"
|
||||||
|
SOURCE: "target/doc"
|
||||||
|
TARGET: "/var/www/html/rs/"
|
||||||
|
|
||||||
build-python:
|
build-python:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -55,37 +56,9 @@ jobs:
|
|||||||
- uses: DeterminateSystems/magic-nix-cache-action@main
|
- uses: DeterminateSystems/magic-nix-cache-action@main
|
||||||
- name: Build C documentation
|
- name: Build C documentation
|
||||||
run: nix build .#docs
|
run: nix build .#docs
|
||||||
- name: Upload to c.delta.chat
|
- name: Upload to py.delta.chat
|
||||||
run: |
|
run: |
|
||||||
mkdir -p "$HOME/.ssh"
|
mkdir -p "$HOME/.ssh"
|
||||||
echo "${{ secrets.CODESPEAK_KEY }}" > "$HOME/.ssh/key"
|
echo "${{ secrets.CODESPEAK_KEY }}" > "$HOME/.ssh/key"
|
||||||
chmod 600 "$HOME/.ssh/key"
|
chmod 600 "$HOME/.ssh/key"
|
||||||
rsync -avzh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/result/html/ "delta@c.delta.chat:/home/delta/build-c/master"
|
rsync -avzh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/result/html/ "delta@c.delta.chat:/home/delta/build-c/master"
|
||||||
|
|
||||||
build-ts:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
working-directory: ./deltachat-jsonrpc/typescript
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
with:
|
|
||||||
show-progress: false
|
|
||||||
fetch-depth: 0 # Fetch history to calculate VCS version number.
|
|
||||||
- name: Use Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: '18'
|
|
||||||
- name: npm install
|
|
||||||
run: npm install
|
|
||||||
- name: npm run build
|
|
||||||
run: npm run build
|
|
||||||
- name: Run docs script
|
|
||||||
run: npm run docs
|
|
||||||
- name: Upload to js.jsonrpc.delta.chat
|
|
||||||
run: |
|
|
||||||
mkdir -p "$HOME/.ssh"
|
|
||||||
echo "${{ secrets.KEY }}" > "$HOME/.ssh/key"
|
|
||||||
chmod 600 "$HOME/.ssh/key"
|
|
||||||
rsync -avzh -e "ssh -i $HOME/.ssh/key -o StrictHostKeyChecking=no" $GITHUB_WORKSPACE/deltachat-jsonrpc/typescript/docs/ "${{ secrets.USERNAME }}@js.jsonrpc.delta.chat:/var/www/html/js-jsonrpc/"
|
|
||||||
|
|||||||
2
.github/workflows/upload-ffi-docs.yml
vendored
2
.github/workflows/upload-ffi-docs.yml
vendored
@@ -1,5 +1,5 @@
|
|||||||
# GitHub Actions workflow
|
# GitHub Actions workflow
|
||||||
# to build `deltachat_ffi` crate documentation
|
# to build `deltachat_fii` crate documentation
|
||||||
# and upload it to <https://cffi.delta.chat/>
|
# and upload it to <https://cffi.delta.chat/>
|
||||||
|
|
||||||
name: Build & Deploy Documentation on cffi.delta.chat
|
name: Build & Deploy Documentation on cffi.delta.chat
|
||||||
|
|||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -33,7 +33,7 @@ deltachat-ffi/xml
|
|||||||
|
|
||||||
coverage/
|
coverage/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
.vscode
|
.vscode/launch.json
|
||||||
python/accounts.txt
|
python/accounts.txt
|
||||||
python/all-testaccounts.txt
|
python/all-testaccounts.txt
|
||||||
tmp/
|
tmp/
|
||||||
@@ -50,4 +50,4 @@ result
|
|||||||
|
|
||||||
# direnv
|
# direnv
|
||||||
.envrc
|
.envrc
|
||||||
.direnv
|
.direnv
|
||||||
1104
CHANGELOG.md
1104
CHANGELOG.md
File diff suppressed because it is too large
Load Diff
@@ -12,12 +12,6 @@ else()
|
|||||||
set(DYNAMIC_EXT "dll")
|
set(DYNAMIC_EXT "dll")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(DEFINED ENV{CARGO_BUILD_TARGET})
|
|
||||||
set(ARCH_DIR "$ENV{CARGO_BUILD_TARGET}")
|
|
||||||
else()
|
|
||||||
set(ARCH_DIR "./")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT
|
OUTPUT
|
||||||
"${CMAKE_BINARY_DIR}/target/release/libdeltachat.a"
|
"${CMAKE_BINARY_DIR}/target/release/libdeltachat.a"
|
||||||
@@ -41,6 +35,6 @@ add_custom_target(
|
|||||||
)
|
)
|
||||||
|
|
||||||
install(FILES "deltachat-ffi/deltachat.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
install(FILES "deltachat-ffi/deltachat.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||||
install(FILES "${CMAKE_BINARY_DIR}/target/${ARCH_DIR}/release/libdeltachat.a" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
install(FILES "${CMAKE_BINARY_DIR}/target/release/libdeltachat.a" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
install(FILES "${CMAKE_BINARY_DIR}/target/${ARCH_DIR}/release/libdeltachat.${DYNAMIC_EXT}" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
install(FILES "${CMAKE_BINARY_DIR}/target/release/libdeltachat.${DYNAMIC_EXT}" DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||||
install(FILES "${CMAKE_BINARY_DIR}/target/${ARCH_DIR}/release/pkgconfig/deltachat.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
install(FILES "${CMAKE_BINARY_DIR}/target/release/pkgconfig/deltachat.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
|
|||||||
@@ -32,60 +32,6 @@ on the contributing page: <https://github.com/deltachat/deltachat-core-rust/cont
|
|||||||
We format the code using `rustfmt`. Run `cargo fmt` prior to committing the code.
|
We format the code using `rustfmt`. Run `cargo fmt` prior to committing the code.
|
||||||
Run `scripts/clippy.sh` to check the code for common mistakes with [Clippy].
|
Run `scripts/clippy.sh` to check the code for common mistakes with [Clippy].
|
||||||
|
|
||||||
### SQL
|
|
||||||
|
|
||||||
Multi-line SQL statements should be formatted using string literals,
|
|
||||||
for example
|
|
||||||
```
|
|
||||||
sql.execute(
|
|
||||||
"CREATE TABLE messages (
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
||||||
text TEXT DEFAULT '' NOT NULL -- message text
|
|
||||||
) STRICT",
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
```
|
|
||||||
|
|
||||||
Do not use macros like [`concat!`](https://doc.rust-lang.org/std/macro.concat.html)
|
|
||||||
or [`indoc!](https://docs.rs/indoc).
|
|
||||||
Do not escape newlines like this:
|
|
||||||
```
|
|
||||||
sql.execute(
|
|
||||||
"CREATE TABLE messages ( \
|
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT, \
|
|
||||||
text TEXT DEFAULT '' NOT NULL \
|
|
||||||
) STRICT",
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
```
|
|
||||||
Escaping newlines
|
|
||||||
is prone to errors like this if space before backslash is missing:
|
|
||||||
```
|
|
||||||
"SELECT foo\
|
|
||||||
FROM bar"
|
|
||||||
```
|
|
||||||
Literal above results in `SELECT fooFROM bar` string.
|
|
||||||
This style also does not allow using `--` comments.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Declare new SQL tables with [`STRICT`](https://sqlite.org/stricttables.html) keyword
|
|
||||||
to make SQLite check column types.
|
|
||||||
|
|
||||||
Declare primary keys with [`AUTOINCREMENT`](https://www.sqlite.org/autoinc.html) keyword.
|
|
||||||
This avoids reuse of the row IDs and can avoid dangerous bugs
|
|
||||||
like forwarding wrong message because the message was deleted
|
|
||||||
and another message took its row ID.
|
|
||||||
|
|
||||||
Declare all new columns as `NOT NULL`
|
|
||||||
and set the `DEFAULT` value if it is optional so the column can be skipped in `INSERT` statements.
|
|
||||||
Dealing with `NULL` values both in SQL and in Rust is tricky and we try to avoid it.
|
|
||||||
If column is already declared without `NOT NULL`, use `IFNULL` function to provide default value when selecting it.
|
|
||||||
Use `HAVING COUNT(*) > 0` clause
|
|
||||||
to [prevent aggregate functions such as `MIN` and `MAX` from returning `NULL`](https://stackoverflow.com/questions/66527856/aggregate-functions-max-etc-return-null-instead-of-no-rows).
|
|
||||||
|
|
||||||
### Commit messages
|
|
||||||
|
|
||||||
Commit messages follow the [Conventional Commits] notation.
|
Commit messages follow the [Conventional Commits] notation.
|
||||||
We use [git-cliff] to generate the changelog from commit messages before the release.
|
We use [git-cliff] to generate the changelog from commit messages before the release.
|
||||||
|
|
||||||
|
|||||||
3283
Cargo.lock
generated
3283
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
145
Cargo.toml
145
Cargo.toml
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "deltachat"
|
name = "deltachat"
|
||||||
version = "1.147.0"
|
version = "1.137.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
rust-version = "1.77"
|
rust-version = "1.77"
|
||||||
@@ -34,93 +34,95 @@ strip = true
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
deltachat_derive = { path = "./deltachat_derive" }
|
deltachat_derive = { path = "./deltachat_derive" }
|
||||||
deltachat-time = { path = "./deltachat-time" }
|
deltachat-time = { path = "./deltachat-time" }
|
||||||
deltachat-contact-tools = { workspace = true }
|
|
||||||
format-flowed = { path = "./format-flowed" }
|
format-flowed = { path = "./format-flowed" }
|
||||||
ratelimit = { path = "./deltachat-ratelimit" }
|
ratelimit = { path = "./deltachat-ratelimit" }
|
||||||
|
|
||||||
anyhow = { workspace = true }
|
anyhow = "1"
|
||||||
async-broadcast = "0.7.1"
|
async-channel = "2.0.0"
|
||||||
async-channel = { workspace = true }
|
async-imap = { version = "0.9.7", default-features = false, features = ["runtime-tokio"] }
|
||||||
async-imap = { version = "0.10.1", default-features = false, features = ["runtime-tokio"] }
|
|
||||||
async-native-tls = { version = "0.5", default-features = false, features = ["runtime-tokio"] }
|
async-native-tls = { version = "0.5", default-features = false, features = ["runtime-tokio"] }
|
||||||
async-smtp = { version = "0.9", default-features = false, features = ["runtime-tokio"] }
|
async-smtp = { version = "0.9", default-features = false, features = ["runtime-tokio"] }
|
||||||
async_zip = { version = "0.0.12", default-features = false, features = ["deflate", "fs"] }
|
async_zip = { version = "0.0.12", default-features = false, features = ["deflate", "fs"] }
|
||||||
base64 = { workspace = true }
|
backtrace = "0.3"
|
||||||
brotli = { version = "6", default-features=false, features = ["std"] }
|
base64 = "0.21"
|
||||||
bytes = "1"
|
brotli = { version = "4", default-features=false, features = ["std"] }
|
||||||
chrono = { workspace = true, features = ["alloc", "clock", "std"] }
|
bitflags = "1.3"
|
||||||
|
bstr = { version = "1.4.0", default-features=false, features = ["std", "alloc"] }
|
||||||
|
chrono = { version = "0.4", default-features=false, features = ["clock", "std"] }
|
||||||
email = { git = "https://github.com/deltachat/rust-email", branch = "master" }
|
email = { git = "https://github.com/deltachat/rust-email", branch = "master" }
|
||||||
encoded-words = { git = "https://github.com/async-email/encoded-words", branch = "master" }
|
encoded-words = { git = "https://github.com/async-email/encoded-words", branch = "master" }
|
||||||
escaper = "0.1"
|
escaper = "0.1"
|
||||||
fast-socks5 = "0.9"
|
fast-socks5 = "0.9"
|
||||||
fd-lock = "4"
|
fd-lock = "4"
|
||||||
futures-lite = { workspace = true }
|
futures = "0.3"
|
||||||
futures = { workspace = true }
|
futures-lite = "2.3.0"
|
||||||
hex = "0.4.0"
|
hex = "0.4.0"
|
||||||
hickory-resolver = "=0.25.0-alpha.2"
|
hickory-resolver = "0.24"
|
||||||
http-body-util = "0.1.2"
|
|
||||||
humansize = "2"
|
humansize = "2"
|
||||||
hyper = "1"
|
|
||||||
hyper-util = "0.1.9"
|
|
||||||
image = { version = "0.25.1", default-features=false, features = ["gif", "jpeg", "ico", "png", "pnm", "webp", "bmp"] }
|
image = { version = "0.25.1", default-features=false, features = ["gif", "jpeg", "ico", "png", "pnm", "webp", "bmp"] }
|
||||||
iroh-gossip = { version = "0.25.0", default-features = false, features = ["net"] }
|
iroh = { version = "0.4.2", default-features = false }
|
||||||
iroh-net = { version = "0.25.0", default-features = false }
|
kamadak-exif = "0.5"
|
||||||
kamadak-exif = "0.5.3"
|
|
||||||
lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" }
|
lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" }
|
||||||
libc = { workspace = true }
|
libc = "0.2"
|
||||||
mailparse = "0.15"
|
mailparse = "0.14"
|
||||||
mime = "0.3.17"
|
mime = "0.3.17"
|
||||||
num_cpus = "1.16"
|
num_cpus = "1.16"
|
||||||
num-derive = "0.4"
|
num-derive = "0.4"
|
||||||
num-traits = { workspace = true }
|
num-traits = "0.2"
|
||||||
once_cell = { workspace = true }
|
once_cell = "1.18.0"
|
||||||
parking_lot = "0.12"
|
|
||||||
percent-encoding = "2.3"
|
percent-encoding = "2.3"
|
||||||
pgp = { version = "0.13.2", default-features = false }
|
parking_lot = "0.12"
|
||||||
|
pgp = { version = "0.11", default-features = false }
|
||||||
pin-project = "1"
|
pin-project = "1"
|
||||||
|
pretty_env_logger = { version = "0.5", optional = true }
|
||||||
qrcodegen = "1.7.0"
|
qrcodegen = "1.7.0"
|
||||||
quick-xml = "0.36"
|
quick-xml = "0.31"
|
||||||
quoted_printable = "0.5"
|
quoted_printable = "0.5"
|
||||||
rand = { workspace = true }
|
rand = "0.8"
|
||||||
regex = { workspace = true }
|
regex = "1.10"
|
||||||
rusqlite = { workspace = true, features = ["sqlcipher"] }
|
reqwest = { version = "0.12.2", features = ["json"] }
|
||||||
|
rusqlite = { version = "0.31", features = ["sqlcipher"] }
|
||||||
rust-hsluv = "0.1"
|
rust-hsluv = "0.1"
|
||||||
rustls-pki-types = "1.9.0"
|
sanitize-filename = "0.5"
|
||||||
rustls = { version = "0.23.13", default-features = false }
|
serde_json = "1"
|
||||||
sanitize-filename = { workspace = true }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = { workspace = true }
|
|
||||||
serde_urlencoded = "0.7.1"
|
|
||||||
serde = { workspace = true, features = ["derive"] }
|
|
||||||
sha-1 = "0.10"
|
sha-1 = "0.10"
|
||||||
shadowsocks = { version = "1.21.0", default-features = false, features = ["aead-cipher-2022"] }
|
sha2 = "0.10"
|
||||||
smallvec = "1.13.2"
|
smallvec = "1"
|
||||||
strum = "0.26"
|
strum = "0.26"
|
||||||
strum_macros = "0.26"
|
strum_macros = "0.26"
|
||||||
tagger = "4.3.4"
|
tagger = "4.3.4"
|
||||||
textwrap = "0.16.1"
|
textwrap = "0.16.1"
|
||||||
thiserror = { workspace = true }
|
thiserror = "1"
|
||||||
|
tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] }
|
||||||
tokio-io-timeout = "1.2.0"
|
tokio-io-timeout = "1.2.0"
|
||||||
tokio-rustls = { version = "0.26.0", default-features = false }
|
tokio-stream = { version = "0.1.15", features = ["fs"] }
|
||||||
tokio-stream = { version = "0.1.16", features = ["fs"] }
|
|
||||||
tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar
|
tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar
|
||||||
tokio-util = { workspace = true }
|
tokio-util = "0.7.9"
|
||||||
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "macros"] }
|
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
url = "2"
|
url = "2"
|
||||||
uuid = { version = "1", features = ["serde", "v4"] }
|
uuid = { version = "1", features = ["serde", "v4"] }
|
||||||
webpki-roots = "0.26.6"
|
|
||||||
|
# Pin OpenSSL to 3.1 releases.
|
||||||
|
# OpenSSL 3.2 has a regression tracked at <https://github.com/openssl/openssl/issues/23376>
|
||||||
|
# which results in broken `deltachat-rpc-server` binaries when cross-compiled using Zig toolchain.
|
||||||
|
# See <https://github.com/deltachat/deltachat-core-rust/issues/5206> for Delta Chat issue.
|
||||||
|
# According to <https://www.openssl.org/policies/releasestrat.html>
|
||||||
|
# 3.1 branch will be supported until 2025-03-14.
|
||||||
|
openssl-src = "~300.1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
anyhow = { workspace = true, features = ["backtrace"] } # Enable `backtrace` feature in tests.
|
ansi_term = "0.12.0"
|
||||||
|
anyhow = { version = "1", features = ["backtrace"] } # Enable `backtrace` feature in tests.
|
||||||
criterion = { version = "0.5.1", features = ["async_tokio"] }
|
criterion = { version = "0.5.1", features = ["async_tokio"] }
|
||||||
futures-lite = { workspace = true }
|
futures-lite = "2.3.0"
|
||||||
log = { workspace = true }
|
log = "0.4"
|
||||||
nu-ansi-term = { workspace = true }
|
pretty_env_logger = "0.5"
|
||||||
pretty_assertions = "1.4.1"
|
|
||||||
proptest = { version = "1", default-features = false, features = ["std"] }
|
proptest = { version = "1", default-features = false, features = ["std"] }
|
||||||
tempfile = { workspace = true }
|
tempfile = "3"
|
||||||
testdir = "0.9.0"
|
testdir = "0.9.0"
|
||||||
tokio = { workspace = true, features = ["rt-multi-thread", "macros"] }
|
tokio = { version = "1", features = ["parking_lot", "rt-multi-thread", "macros"] }
|
||||||
|
pretty_assertions = "1.3.0"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
@@ -132,7 +134,6 @@ members = [
|
|||||||
"deltachat-repl",
|
"deltachat-repl",
|
||||||
"deltachat-time",
|
"deltachat-time",
|
||||||
"format-flowed",
|
"format-flowed",
|
||||||
"deltachat-contact-tools",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[bench]]
|
[[bench]]
|
||||||
@@ -163,47 +164,11 @@ harness = false
|
|||||||
name = "send_events"
|
name = "send_events"
|
||||||
harness = false
|
harness = false
|
||||||
|
|
||||||
[workspace.dependencies]
|
|
||||||
anyhow = "1"
|
|
||||||
async-channel = "2.3.1"
|
|
||||||
base64 = "0.22"
|
|
||||||
chrono = { version = "0.4.38", default-features = false }
|
|
||||||
deltachat-contact-tools = { path = "deltachat-contact-tools" }
|
|
||||||
deltachat-jsonrpc = { path = "deltachat-jsonrpc" }
|
|
||||||
deltachat = { path = "." }
|
|
||||||
futures = "0.3.30"
|
|
||||||
futures-lite = "2.3.0"
|
|
||||||
libc = "0.2"
|
|
||||||
log = "0.4"
|
|
||||||
nu-ansi-term = "0.46"
|
|
||||||
num-traits = "0.2"
|
|
||||||
once_cell = "1.18.0"
|
|
||||||
rand = "0.8"
|
|
||||||
regex = "1.10"
|
|
||||||
rusqlite = "0.32"
|
|
||||||
sanitize-filename = "0.5"
|
|
||||||
serde = "1.0"
|
|
||||||
serde_json = "1"
|
|
||||||
tempfile = "3.13.0"
|
|
||||||
thiserror = "1"
|
|
||||||
|
|
||||||
# 1.38 is the latest version before `mio` dependency update
|
|
||||||
# that broke compilation with Android NDK r23c and r24.
|
|
||||||
# Version 1.39.0 cannot be compiled using these NDKs,
|
|
||||||
# see issue <https://github.com/tokio-rs/tokio/issues/6748>
|
|
||||||
# for details.
|
|
||||||
tokio = "~1.38.1"
|
|
||||||
|
|
||||||
tokio-util = "0.7.11"
|
|
||||||
tracing-subscriber = "0.3"
|
|
||||||
yerpc = "0.6.2"
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["vendored"]
|
default = ["vendored"]
|
||||||
internals = []
|
internals = []
|
||||||
vendored = [
|
vendored = [
|
||||||
"rusqlite/bundled-sqlcipher-vendored-openssl"
|
"async-native-tls/vendored",
|
||||||
|
"rusqlite/bundled-sqlcipher-vendored-openssl",
|
||||||
|
"reqwest/native-tls-vendored"
|
||||||
]
|
]
|
||||||
|
|
||||||
[lints.rust]
|
|
||||||
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }
|
|
||||||
|
|||||||
@@ -6,9 +6,6 @@
|
|||||||
<a href="https://github.com/deltachat/deltachat-core-rust/actions/workflows/ci.yml">
|
<a href="https://github.com/deltachat/deltachat-core-rust/actions/workflows/ci.yml">
|
||||||
<img alt="Rust CI" src="https://github.com/deltachat/deltachat-core-rust/actions/workflows/ci.yml/badge.svg">
|
<img alt="Rust CI" src="https://github.com/deltachat/deltachat-core-rust/actions/workflows/ci.yml/badge.svg">
|
||||||
</a>
|
</a>
|
||||||
<a href="https://deps.rs/repo/github/deltachat/deltachat-core-rust">
|
|
||||||
<img alt="dependency status" src="https://deps.rs/repo/github/deltachat/deltachat-core-rust/status.svg">
|
|
||||||
</a>
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
@@ -30,13 +27,13 @@ $ curl https://sh.rustup.rs -sSf | sh
|
|||||||
Compile and run Delta Chat Core command line utility, using `cargo`:
|
Compile and run Delta Chat Core command line utility, using `cargo`:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cargo run --locked -p deltachat-repl -- ~/deltachat-db
|
$ cargo run -p deltachat-repl -- ~/deltachat-db
|
||||||
```
|
```
|
||||||
where ~/deltachat-db is the database file. Delta Chat will create it if it does not exist.
|
where ~/deltachat-db is the database file. Delta Chat will create it if it does not exist.
|
||||||
|
|
||||||
Optionally, install `deltachat-repl` binary with
|
Optionally, install `deltachat-repl` binary with
|
||||||
```
|
```
|
||||||
$ cargo install --locked --path deltachat-repl/
|
$ cargo install --path deltachat-repl/
|
||||||
```
|
```
|
||||||
and run as
|
and run as
|
||||||
```
|
```
|
||||||
@@ -195,7 +192,6 @@ or its language bindings:
|
|||||||
- [Desktop](https://github.com/deltachat/deltachat-desktop)
|
- [Desktop](https://github.com/deltachat/deltachat-desktop)
|
||||||
- [Pidgin](https://code.ur.gs/lupine/purple-plugin-delta/)
|
- [Pidgin](https://code.ur.gs/lupine/purple-plugin-delta/)
|
||||||
- [Telepathy](https://code.ur.gs/lupine/telepathy-padfoot/)
|
- [Telepathy](https://code.ur.gs/lupine/telepathy-padfoot/)
|
||||||
- [Ubuntu Touch](https://codeberg.org/lk108/deltatouch)
|
|
||||||
- several **Bots**
|
- several **Bots**
|
||||||
|
|
||||||
[^1]: Out of date / unmaintained, if you like those languages feel free to start maintaining them. If you have questions we'll help you, please ask in the issues.
|
[^1]: Out of date / unmaintained, if you like those languages feel free to start maintaining them. If you have questions we'll help you, please ask in the issues.
|
||||||
|
|||||||
17
RELEASE.md
17
RELEASE.md
@@ -4,18 +4,21 @@ For example, to release version 1.116.0 of the core, do the following steps.
|
|||||||
|
|
||||||
1. Resolve all [blocker issues](https://github.com/deltachat/deltachat-core-rust/labels/blocker).
|
1. Resolve all [blocker issues](https://github.com/deltachat/deltachat-core-rust/labels/blocker).
|
||||||
|
|
||||||
2. Update the changelog: `git cliff --unreleased --tag 1.116.0 --prepend CHANGELOG.md` or `git cliff -u -t 1.116.0 -p CHANGELOG.md`.
|
2. Run `npm run build:core:constants` in the root of the repository
|
||||||
|
and commit generated `node/constants.js`, `node/events.js` and `node/lib/constants.js`.
|
||||||
|
|
||||||
3. add a link to compare previous with current version to the end of CHANGELOG.md:
|
3. Update the changelog: `git cliff --unreleased --tag 1.116.0 --prepend CHANGELOG.md` or `git cliff -u -t 1.116.0 -p CHANGELOG.md`.
|
||||||
|
|
||||||
|
4. add a link to compare previous with current version to the end of CHANGELOG.md:
|
||||||
`[1.116.0]: https://github.com/deltachat/deltachat-core-rust/compare/v1.115.2...v1.116.0`
|
`[1.116.0]: https://github.com/deltachat/deltachat-core-rust/compare/v1.115.2...v1.116.0`
|
||||||
|
|
||||||
4. Update the version by running `scripts/set_core_version.py 1.116.0`.
|
5. Update the version by running `scripts/set_core_version.py 1.116.0`.
|
||||||
|
|
||||||
5. Commit the changes as `chore(release): prepare for 1.116.0`.
|
6. Commit the changes as `chore(release): prepare for 1.116.0`.
|
||||||
Optionally, use a separate branch like `prep-1.116.0` for this commit and open a PR for review.
|
Optionally, use a separate branch like `prep-1.116.0` for this commit and open a PR for review.
|
||||||
|
|
||||||
6. Tag the release: `git tag -a v1.116.0`.
|
7. Tag the release: `git tag -a v1.116.0`.
|
||||||
|
|
||||||
7. Push the release tag: `git push origin v1.116.0`.
|
8. Push the release tag: `git push origin v1.116.0`.
|
||||||
|
|
||||||
8. Create a GitHub release: `gh release create v1.116.0 -n ''`.
|
9. Create a GitHub release: `gh release create v1.116.0 -n ''`.
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
use deltachat::contact::Contact;
|
use deltachat::contact::Contact;
|
||||||
use deltachat::context::Context;
|
use deltachat::context::Context;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
use criterion::{criterion_group, criterion_main, Criterion};
|
use criterion::{criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
use deltachat::context::Context;
|
use deltachat::context::Context;
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "deltachat-contact-tools"
|
|
||||||
version = "0.0.0" # No semver-stable versioning
|
|
||||||
edition = "2021"
|
|
||||||
description = "Contact-related tools, like parsing vcards and sanitizing name and address. Meant for internal use in the deltachat crate."
|
|
||||||
license = "MPL-2.0"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
anyhow = { workspace = true }
|
|
||||||
once_cell = { workspace = true }
|
|
||||||
regex = { workspace = true }
|
|
||||||
rusqlite = { workspace = true } # Needed in order to `impl rusqlite::types::ToSql for EmailAddress`. Could easily be put behind a feature.
|
|
||||||
chrono = { workspace = true, features = ["alloc", "clock", "std"] }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
anyhow = { workspace = true, features = ["backtrace"] } # Enable `backtrace` feature in tests.
|
|
||||||
@@ -1,810 +0,0 @@
|
|||||||
//! Contact-related tools, like parsing vcards and sanitizing name and address
|
|
||||||
|
|
||||||
#![forbid(unsafe_code)]
|
|
||||||
#![warn(
|
|
||||||
unused,
|
|
||||||
clippy::correctness,
|
|
||||||
missing_debug_implementations,
|
|
||||||
missing_docs,
|
|
||||||
clippy::all,
|
|
||||||
clippy::wildcard_imports,
|
|
||||||
clippy::needless_borrow,
|
|
||||||
clippy::cast_lossless,
|
|
||||||
clippy::unused_async,
|
|
||||||
clippy::explicit_iter_loop,
|
|
||||||
clippy::explicit_into_iter_loop,
|
|
||||||
clippy::cloned_instead_of_copied
|
|
||||||
)]
|
|
||||||
#![cfg_attr(not(test), warn(clippy::indexing_slicing))]
|
|
||||||
#![allow(
|
|
||||||
clippy::match_bool,
|
|
||||||
clippy::mixed_read_write_in_expression,
|
|
||||||
clippy::bool_assert_comparison,
|
|
||||||
clippy::manual_split_once,
|
|
||||||
clippy::format_push_string,
|
|
||||||
clippy::bool_to_int_with_if,
|
|
||||||
clippy::manual_range_contains
|
|
||||||
)]
|
|
||||||
|
|
||||||
use std::fmt;
|
|
||||||
use std::ops::Deref;
|
|
||||||
|
|
||||||
use anyhow::bail;
|
|
||||||
use anyhow::Context as _;
|
|
||||||
use anyhow::Result;
|
|
||||||
use chrono::{DateTime, NaiveDateTime};
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use regex::Regex;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
/// A Contact, as represented in a VCard.
|
|
||||||
pub struct VcardContact {
|
|
||||||
/// The email address, vcard property `email`
|
|
||||||
pub addr: String,
|
|
||||||
/// This must be the name authorized by the contact itself, not a locally given name. Vcard
|
|
||||||
/// property `fn`. Can be empty, one should use `display_name()` to obtain the display name.
|
|
||||||
pub authname: String,
|
|
||||||
/// The contact's public PGP key in Base64, vcard property `key`
|
|
||||||
pub key: Option<String>,
|
|
||||||
/// The contact's profile image (=avatar) in Base64, vcard property `photo`
|
|
||||||
pub profile_image: Option<String>,
|
|
||||||
/// The timestamp when the vcard was created / last updated, vcard property `rev`
|
|
||||||
pub timestamp: Result<i64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VcardContact {
|
|
||||||
/// Returns the contact's display name.
|
|
||||||
pub fn display_name(&self) -> &str {
|
|
||||||
match self.authname.is_empty() {
|
|
||||||
false => &self.authname,
|
|
||||||
true => &self.addr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a vCard containing given contacts.
|
|
||||||
///
|
|
||||||
/// Calling [`parse_vcard()`] on the returned result is a reverse operation.
|
|
||||||
pub fn make_vcard(contacts: &[VcardContact]) -> String {
|
|
||||||
fn format_timestamp(c: &VcardContact) -> Option<String> {
|
|
||||||
let timestamp = *c.timestamp.as_ref().ok()?;
|
|
||||||
let datetime = DateTime::from_timestamp(timestamp, 0)?;
|
|
||||||
Some(datetime.format("%Y%m%dT%H%M%SZ").to_string())
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut res = "".to_string();
|
|
||||||
for c in contacts {
|
|
||||||
let addr = &c.addr;
|
|
||||||
let display_name = c.display_name();
|
|
||||||
res += &format!(
|
|
||||||
"BEGIN:VCARD\n\
|
|
||||||
VERSION:4.0\n\
|
|
||||||
EMAIL:{addr}\n\
|
|
||||||
FN:{display_name}\n"
|
|
||||||
);
|
|
||||||
if let Some(key) = &c.key {
|
|
||||||
res += &format!("KEY:data:application/pgp-keys;base64,{key}\n");
|
|
||||||
}
|
|
||||||
if let Some(profile_image) = &c.profile_image {
|
|
||||||
res += &format!("PHOTO:data:image/jpeg;base64,{profile_image}\n");
|
|
||||||
}
|
|
||||||
if let Some(timestamp) = format_timestamp(c) {
|
|
||||||
res += &format!("REV:{timestamp}\n");
|
|
||||||
}
|
|
||||||
res += "END:VCARD\n";
|
|
||||||
}
|
|
||||||
res
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses `VcardContact`s from a given `&str`.
|
|
||||||
pub fn parse_vcard(vcard: &str) -> Vec<VcardContact> {
|
|
||||||
fn remove_prefix<'a>(s: &'a str, prefix: &str) -> Option<&'a str> {
|
|
||||||
let start_of_s = s.get(..prefix.len())?;
|
|
||||||
|
|
||||||
if start_of_s.eq_ignore_ascii_case(prefix) {
|
|
||||||
s.get(prefix.len()..)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fn vcard_property<'a>(s: &'a str, property: &str) -> Option<&'a str> {
|
|
||||||
let remainder = remove_prefix(s, property)?;
|
|
||||||
// If `s` is `EMAIL;TYPE=work:alice@example.com` and `property` is `EMAIL`,
|
|
||||||
// then `remainder` is now `;TYPE=work:alice@example.com`
|
|
||||||
|
|
||||||
// Note: This doesn't handle the case where there are quotes around a colon,
|
|
||||||
// like `NAME;Foo="Some quoted text: that contains a colon":value`.
|
|
||||||
// This could be improved in the future, but for now, the parsing is good enough.
|
|
||||||
let (params, value) = remainder.split_once(':')?;
|
|
||||||
// In the example from above, `params` is now `;TYPE=work`
|
|
||||||
// and `value` is now `alice@example.com`
|
|
||||||
|
|
||||||
if params
|
|
||||||
.chars()
|
|
||||||
.next()
|
|
||||||
.filter(|c| !c.is_ascii_punctuation() || *c == '_')
|
|
||||||
.is_some()
|
|
||||||
{
|
|
||||||
// `s` started with `property`, but the next character after it was not punctuation,
|
|
||||||
// so this line's property is actually something else
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
Some(value)
|
|
||||||
}
|
|
||||||
fn parse_datetime(datetime: &str) -> Result<i64> {
|
|
||||||
// According to https://www.rfc-editor.org/rfc/rfc6350#section-4.3.5, the timestamp
|
|
||||||
// is in ISO.8601.2004 format. DateTime::parse_from_rfc3339() apparently parses
|
|
||||||
// ISO.8601, but fails to parse any of the examples given.
|
|
||||||
// So, instead just parse using a format string.
|
|
||||||
|
|
||||||
// Parses 19961022T140000Z, 19961022T140000-05, or 19961022T140000-0500.
|
|
||||||
let timestamp = match DateTime::parse_from_str(datetime, "%Y%m%dT%H%M%S%#z") {
|
|
||||||
Ok(datetime) => datetime.timestamp(),
|
|
||||||
// Parses 19961022T140000.
|
|
||||||
Err(e) => match NaiveDateTime::parse_from_str(datetime, "%Y%m%dT%H%M%S") {
|
|
||||||
Ok(datetime) => datetime
|
|
||||||
.and_local_timezone(chrono::offset::Local)
|
|
||||||
.single()
|
|
||||||
.context("Could not apply local timezone to parsed date and time")?
|
|
||||||
.timestamp(),
|
|
||||||
Err(_) => return Err(e.into()),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
Ok(timestamp)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove line folding, see https://datatracker.ietf.org/doc/html/rfc6350#section-3.2
|
|
||||||
static NEWLINE_AND_SPACE_OR_TAB: Lazy<Regex> = Lazy::new(|| Regex::new("\r?\n[\t ]").unwrap());
|
|
||||||
let unfolded_lines = NEWLINE_AND_SPACE_OR_TAB.replace_all(vcard, "");
|
|
||||||
|
|
||||||
let mut lines = unfolded_lines.lines().peekable();
|
|
||||||
let mut contacts = Vec::new();
|
|
||||||
|
|
||||||
while lines.peek().is_some() {
|
|
||||||
// Skip to the start of the vcard:
|
|
||||||
for line in lines.by_ref() {
|
|
||||||
if line.eq_ignore_ascii_case("BEGIN:VCARD") {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut display_name = None;
|
|
||||||
let mut addr = None;
|
|
||||||
let mut key = None;
|
|
||||||
let mut photo = None;
|
|
||||||
let mut datetime = None;
|
|
||||||
|
|
||||||
for mut line in lines.by_ref() {
|
|
||||||
if let Some(remainder) = remove_prefix(line, "item1.") {
|
|
||||||
// Remove the group name, if the group is called "item1".
|
|
||||||
// If necessary, we can improve this to also remove groups that are called something different that "item1".
|
|
||||||
//
|
|
||||||
// Search "group name" at https://datatracker.ietf.org/doc/html/rfc6350 for more infos.
|
|
||||||
line = remainder;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(email) = vcard_property(line, "email") {
|
|
||||||
addr.get_or_insert(email);
|
|
||||||
} else if let Some(name) = vcard_property(line, "fn") {
|
|
||||||
display_name.get_or_insert(name);
|
|
||||||
} else if let Some(k) = remove_prefix(line, "KEY;PGP;ENCODING=BASE64:")
|
|
||||||
.or_else(|| remove_prefix(line, "KEY;TYPE=PGP;ENCODING=b:"))
|
|
||||||
.or_else(|| remove_prefix(line, "KEY:data:application/pgp-keys;base64,"))
|
|
||||||
.or_else(|| remove_prefix(line, "KEY;PREF=1:data:application/pgp-keys;base64,"))
|
|
||||||
{
|
|
||||||
key.get_or_insert(k);
|
|
||||||
} else if let Some(p) = remove_prefix(line, "PHOTO;JPEG;ENCODING=BASE64:")
|
|
||||||
.or_else(|| remove_prefix(line, "PHOTO;ENCODING=BASE64;JPEG:"))
|
|
||||||
.or_else(|| remove_prefix(line, "PHOTO;TYPE=JPEG;ENCODING=b:"))
|
|
||||||
.or_else(|| remove_prefix(line, "PHOTO;ENCODING=b;TYPE=JPEG:"))
|
|
||||||
.or_else(|| remove_prefix(line, "PHOTO;ENCODING=BASE64;TYPE=JPEG:"))
|
|
||||||
.or_else(|| remove_prefix(line, "PHOTO;TYPE=JPEG;ENCODING=BASE64:"))
|
|
||||||
.or_else(|| remove_prefix(line, "PHOTO:data:image/jpeg;base64,"))
|
|
||||||
{
|
|
||||||
photo.get_or_insert(p);
|
|
||||||
} else if let Some(rev) = vcard_property(line, "rev") {
|
|
||||||
datetime.get_or_insert(rev);
|
|
||||||
} else if line.eq_ignore_ascii_case("END:VCARD") {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let (authname, addr) =
|
|
||||||
sanitize_name_and_addr(display_name.unwrap_or(""), addr.unwrap_or(""));
|
|
||||||
|
|
||||||
contacts.push(VcardContact {
|
|
||||||
authname,
|
|
||||||
addr,
|
|
||||||
key: key.map(|s| s.to_string()),
|
|
||||||
profile_image: photo.map(|s| s.to_string()),
|
|
||||||
timestamp: datetime
|
|
||||||
.context("No timestamp in vcard")
|
|
||||||
.and_then(parse_datetime),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
contacts
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Valid contact address.
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub struct ContactAddress(String);
|
|
||||||
|
|
||||||
impl Deref for ContactAddress {
|
|
||||||
type Target = str;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsRef<str> for ContactAddress {
|
|
||||||
fn as_ref(&self) -> &str {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for ContactAddress {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{}", self.0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ContactAddress {
|
|
||||||
/// Constructs a new contact address from string,
|
|
||||||
/// normalizing and validating it.
|
|
||||||
pub fn new(s: &str) -> Result<Self> {
|
|
||||||
let addr = addr_normalize(s);
|
|
||||||
if !may_be_valid_addr(&addr) {
|
|
||||||
bail!("invalid address {:?}", s);
|
|
||||||
}
|
|
||||||
Ok(Self(addr.to_string()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Allow converting [`ContactAddress`] to an SQLite type.
|
|
||||||
impl rusqlite::types::ToSql for ContactAddress {
|
|
||||||
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
|
|
||||||
let val = rusqlite::types::Value::Text(self.0.to_string());
|
|
||||||
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
|
||||||
Ok(out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Takes a name and an address and sanitizes them:
|
|
||||||
/// - Extracts a name from the addr if the addr is in form "Alice <alice@example.org>"
|
|
||||||
/// - Removes special characters from the name, see [`sanitize_name()`]
|
|
||||||
/// - Removes the name if it is equal to the address by setting it to ""
|
|
||||||
pub fn sanitize_name_and_addr(name: &str, addr: &str) -> (String, String) {
|
|
||||||
static ADDR_WITH_NAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new("(.*)<(.*)>").unwrap());
|
|
||||||
let (name, addr) = if let Some(captures) = ADDR_WITH_NAME_REGEX.captures(addr.as_ref()) {
|
|
||||||
(
|
|
||||||
if name.is_empty() {
|
|
||||||
captures.get(1).map_or("", |m| m.as_str())
|
|
||||||
} else {
|
|
||||||
name
|
|
||||||
},
|
|
||||||
captures
|
|
||||||
.get(2)
|
|
||||||
.map_or("".to_string(), |m| m.as_str().to_string()),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
(name, addr.to_string())
|
|
||||||
};
|
|
||||||
let mut name = sanitize_name(name);
|
|
||||||
|
|
||||||
// If the 'display name' is just the address, remove it:
|
|
||||||
// Otherwise, the contact would sometimes be shown as "alice@example.com (alice@example.com)" (see `get_name_n_addr()`).
|
|
||||||
// If the display name is empty, DC will just show the address when it needs a display name.
|
|
||||||
if name == addr {
|
|
||||||
name = "".to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
(name, addr)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sanitizes a name.
|
|
||||||
///
|
|
||||||
/// - Removes newlines and trims the string
|
|
||||||
/// - Removes quotes (come from some bad MUA implementations)
|
|
||||||
/// - Removes potentially-malicious bidi characters
|
|
||||||
pub fn sanitize_name(name: &str) -> String {
|
|
||||||
let name = sanitize_single_line(name);
|
|
||||||
|
|
||||||
match name.as_bytes() {
|
|
||||||
[b'\'', .., b'\''] | [b'\"', .., b'\"'] | [b'<', .., b'>'] => name
|
|
||||||
.get(1..name.len() - 1)
|
|
||||||
.map_or("".to_string(), |s| s.trim().to_string()),
|
|
||||||
_ => name.to_string(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sanitizes user input
|
|
||||||
///
|
|
||||||
/// - Removes newlines and trims the string
|
|
||||||
/// - Removes potentially-malicious bidi characters
|
|
||||||
pub fn sanitize_single_line(input: &str) -> String {
|
|
||||||
sanitize_bidi_characters(input.replace(['\n', '\r'], " ").trim())
|
|
||||||
}
|
|
||||||
|
|
||||||
const RTLO_CHARACTERS: [char; 5] = ['\u{202A}', '\u{202B}', '\u{202C}', '\u{202D}', '\u{202E}'];
|
|
||||||
const ISOLATE_CHARACTERS: [char; 3] = ['\u{2066}', '\u{2067}', '\u{2068}'];
|
|
||||||
const POP_ISOLATE_CHARACTER: char = '\u{2069}';
|
|
||||||
/// Some control unicode characters can influence whether adjacent text is shown from
|
|
||||||
/// left to right or from right to left.
|
|
||||||
///
|
|
||||||
/// Since user input is not supposed to influence how adjacent text looks,
|
|
||||||
/// this function removes some of these characters.
|
|
||||||
///
|
|
||||||
/// Also see https://github.com/deltachat/deltachat-core-rust/issues/3479.
|
|
||||||
pub fn sanitize_bidi_characters(input_str: &str) -> String {
|
|
||||||
// RTLO_CHARACTERS are apparently rarely used in practice.
|
|
||||||
// They can impact all following text, so, better remove them all:
|
|
||||||
let input_str = input_str.replace(|char| RTLO_CHARACTERS.contains(&char), "");
|
|
||||||
|
|
||||||
// If the ISOLATE characters are not ended with a POP DIRECTIONAL ISOLATE character,
|
|
||||||
// we regard the input as potentially malicious and simply remove all ISOLATE characters.
|
|
||||||
// See https://en.wikipedia.org/wiki/Bidirectional_text#Unicode_bidi_support
|
|
||||||
// and https://www.w3.org/International/questions/qa-bidi-unicode-controls.en
|
|
||||||
// for an explanation about ISOLATE characters.
|
|
||||||
fn isolate_characters_are_valid(input_str: &str) -> bool {
|
|
||||||
let mut isolate_character_nesting: i32 = 0;
|
|
||||||
for char in input_str.chars() {
|
|
||||||
if ISOLATE_CHARACTERS.contains(&char) {
|
|
||||||
isolate_character_nesting += 1;
|
|
||||||
} else if char == POP_ISOLATE_CHARACTER {
|
|
||||||
isolate_character_nesting -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// According to Wikipedia, 125 levels are allowed:
|
|
||||||
// https://en.wikipedia.org/wiki/Unicode_control_characters
|
|
||||||
// (although, in practice, we could also significantly lower this number)
|
|
||||||
if isolate_character_nesting < 0 || isolate_character_nesting > 125 {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isolate_character_nesting == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if isolate_characters_are_valid(&input_str) {
|
|
||||||
input_str
|
|
||||||
} else {
|
|
||||||
input_str.replace(
|
|
||||||
|char| ISOLATE_CHARACTERS.contains(&char) || POP_ISOLATE_CHARACTER == char,
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns false if addr is an invalid address, otherwise true.
|
|
||||||
pub fn may_be_valid_addr(addr: &str) -> bool {
|
|
||||||
let res = EmailAddress::new(addr);
|
|
||||||
res.is_ok()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns address lowercased,
|
|
||||||
/// with whitespace trimmed and `mailto:` prefix removed.
|
|
||||||
pub fn addr_normalize(addr: &str) -> String {
|
|
||||||
let norm = addr.trim().to_lowercase();
|
|
||||||
|
|
||||||
if norm.starts_with("mailto:") {
|
|
||||||
norm.get(7..).unwrap_or(&norm).to_string()
|
|
||||||
} else {
|
|
||||||
norm
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Compares two email addresses, normalizing them beforehand.
|
|
||||||
pub fn addr_cmp(addr1: &str, addr2: &str) -> bool {
|
|
||||||
let norm1 = addr_normalize(addr1);
|
|
||||||
let norm2 = addr_normalize(addr2);
|
|
||||||
|
|
||||||
norm1 == norm2
|
|
||||||
}
|
|
||||||
|
|
||||||
///
|
|
||||||
/// Represents an email address, right now just the `name@domain` portion.
|
|
||||||
///
|
|
||||||
/// # Example
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// use deltachat_contact_tools::EmailAddress;
|
|
||||||
/// let email = match EmailAddress::new("someone@example.com") {
|
|
||||||
/// Ok(addr) => addr,
|
|
||||||
/// Err(e) => panic!("Error parsing address, error was {}", e),
|
|
||||||
/// };
|
|
||||||
/// assert_eq!(&email.local, "someone");
|
|
||||||
/// assert_eq!(&email.domain, "example.com");
|
|
||||||
/// assert_eq!(email.to_string(), "someone@example.com");
|
|
||||||
/// ```
|
|
||||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
|
||||||
pub struct EmailAddress {
|
|
||||||
/// Local part of the email address.
|
|
||||||
pub local: String,
|
|
||||||
|
|
||||||
/// Email address domain.
|
|
||||||
pub domain: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for EmailAddress {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
write!(f, "{}@{}", self.local, self.domain)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl EmailAddress {
|
|
||||||
/// Performs a dead-simple parse of an email address.
|
|
||||||
pub fn new(input: &str) -> Result<EmailAddress> {
|
|
||||||
if input.is_empty() {
|
|
||||||
bail!("empty string is not valid");
|
|
||||||
}
|
|
||||||
let parts: Vec<&str> = input.rsplitn(2, '@').collect();
|
|
||||||
|
|
||||||
if input
|
|
||||||
.chars()
|
|
||||||
.any(|c| c.is_whitespace() || c == '<' || c == '>')
|
|
||||||
{
|
|
||||||
bail!("Email {:?} must not contain whitespaces, '>' or '<'", input);
|
|
||||||
}
|
|
||||||
|
|
||||||
match &parts[..] {
|
|
||||||
[domain, local] => {
|
|
||||||
if local.is_empty() {
|
|
||||||
bail!("empty string is not valid for local part in {:?}", input);
|
|
||||||
}
|
|
||||||
if domain.is_empty() {
|
|
||||||
bail!("missing domain after '@' in {:?}", input);
|
|
||||||
}
|
|
||||||
if domain.ends_with('.') {
|
|
||||||
bail!("Domain {domain:?} should not contain the dot in the end");
|
|
||||||
}
|
|
||||||
Ok(EmailAddress {
|
|
||||||
local: (*local).to_string(),
|
|
||||||
domain: (*domain).to_string(),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => bail!("Email {:?} must contain '@' character", input),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl rusqlite::types::ToSql for EmailAddress {
|
|
||||||
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
|
|
||||||
let val = rusqlite::types::Value::Text(self.to_string());
|
|
||||||
let out = rusqlite::types::ToSqlOutput::Owned(val);
|
|
||||||
Ok(out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use chrono::TimeZone;
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_vcard_thunderbird() {
|
|
||||||
let contacts = parse_vcard(
|
|
||||||
"BEGIN:VCARD
|
|
||||||
VERSION:4.0
|
|
||||||
FN:'Alice Mueller'
|
|
||||||
EMAIL;PREF=1:alice.mueller@posteo.de
|
|
||||||
UID:a8083264-ca47-4be7-98a8-8ec3db1447ca
|
|
||||||
END:VCARD
|
|
||||||
BEGIN:VCARD
|
|
||||||
VERSION:4.0
|
|
||||||
FN:'bobzzz@freenet.de'
|
|
||||||
EMAIL;PREF=1:bobzzz@freenet.de
|
|
||||||
UID:cac4fef4-6351-4854-bbe4-9b6df857eaed
|
|
||||||
END:VCARD
|
|
||||||
",
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(contacts[0].addr, "alice.mueller@posteo.de".to_string());
|
|
||||||
assert_eq!(contacts[0].authname, "Alice Mueller".to_string());
|
|
||||||
assert_eq!(contacts[0].key, None);
|
|
||||||
assert_eq!(contacts[0].profile_image, None);
|
|
||||||
assert!(contacts[0].timestamp.is_err());
|
|
||||||
|
|
||||||
assert_eq!(contacts[1].addr, "bobzzz@freenet.de".to_string());
|
|
||||||
assert_eq!(contacts[1].authname, "".to_string());
|
|
||||||
assert_eq!(contacts[1].key, None);
|
|
||||||
assert_eq!(contacts[1].profile_image, None);
|
|
||||||
assert!(contacts[1].timestamp.is_err());
|
|
||||||
|
|
||||||
assert_eq!(contacts.len(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_vcard_simple_example() {
|
|
||||||
let contacts = parse_vcard(
|
|
||||||
"BEGIN:VCARD
|
|
||||||
VERSION:4.0
|
|
||||||
FN:Alice Wonderland
|
|
||||||
N:Wonderland;Alice;;;Ms.
|
|
||||||
GENDER:W
|
|
||||||
EMAIL;TYPE=work:alice@example.com
|
|
||||||
KEY;TYPE=PGP;ENCODING=b:[base64-data]
|
|
||||||
REV:20240418T184242Z
|
|
||||||
|
|
||||||
END:VCARD",
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(contacts[0].addr, "alice@example.com".to_string());
|
|
||||||
assert_eq!(contacts[0].authname, "Alice Wonderland".to_string());
|
|
||||||
assert_eq!(contacts[0].key, Some("[base64-data]".to_string()));
|
|
||||||
assert_eq!(contacts[0].profile_image, None);
|
|
||||||
assert_eq!(*contacts[0].timestamp.as_ref().unwrap(), 1713465762);
|
|
||||||
|
|
||||||
assert_eq!(contacts.len(), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_make_and_parse_vcard() {
|
|
||||||
let contacts = [
|
|
||||||
VcardContact {
|
|
||||||
addr: "alice@example.org".to_string(),
|
|
||||||
authname: "Alice Wonderland".to_string(),
|
|
||||||
key: Some("[base64-data]".to_string()),
|
|
||||||
profile_image: Some("image in Base64".to_string()),
|
|
||||||
timestamp: Ok(1713465762),
|
|
||||||
},
|
|
||||||
VcardContact {
|
|
||||||
addr: "bob@example.com".to_string(),
|
|
||||||
authname: "".to_string(),
|
|
||||||
key: None,
|
|
||||||
profile_image: None,
|
|
||||||
timestamp: Ok(0),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
let items = [
|
|
||||||
"BEGIN:VCARD\n\
|
|
||||||
VERSION:4.0\n\
|
|
||||||
EMAIL:alice@example.org\n\
|
|
||||||
FN:Alice Wonderland\n\
|
|
||||||
KEY:data:application/pgp-keys;base64,[base64-data]\n\
|
|
||||||
PHOTO:data:image/jpeg;base64,image in Base64\n\
|
|
||||||
REV:20240418T184242Z\n\
|
|
||||||
END:VCARD\n",
|
|
||||||
"BEGIN:VCARD\n\
|
|
||||||
VERSION:4.0\n\
|
|
||||||
EMAIL:bob@example.com\n\
|
|
||||||
FN:bob@example.com\n\
|
|
||||||
REV:19700101T000000Z\n\
|
|
||||||
END:VCARD\n",
|
|
||||||
];
|
|
||||||
let mut expected = "".to_string();
|
|
||||||
for len in 0..=contacts.len() {
|
|
||||||
let contacts = &contacts[0..len];
|
|
||||||
let vcard = make_vcard(contacts);
|
|
||||||
if len > 0 {
|
|
||||||
expected += items[len - 1];
|
|
||||||
}
|
|
||||||
assert_eq!(vcard, expected);
|
|
||||||
let parsed = parse_vcard(&vcard);
|
|
||||||
assert_eq!(parsed.len(), contacts.len());
|
|
||||||
for i in 0..parsed.len() {
|
|
||||||
assert_eq!(parsed[i].addr, contacts[i].addr);
|
|
||||||
assert_eq!(parsed[i].authname, contacts[i].authname);
|
|
||||||
assert_eq!(parsed[i].key, contacts[i].key);
|
|
||||||
assert_eq!(parsed[i].profile_image, contacts[i].profile_image);
|
|
||||||
assert_eq!(
|
|
||||||
parsed[i].timestamp.as_ref().unwrap(),
|
|
||||||
contacts[i].timestamp.as_ref().unwrap()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_contact_address() -> Result<()> {
|
|
||||||
let alice_addr = "alice@example.org";
|
|
||||||
let contact_address = ContactAddress::new(alice_addr)?;
|
|
||||||
assert_eq!(contact_address.as_ref(), alice_addr);
|
|
||||||
|
|
||||||
let invalid_addr = "<> foobar";
|
|
||||||
assert!(ContactAddress::new(invalid_addr).is_err());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_emailaddress_parse() {
|
|
||||||
assert_eq!(EmailAddress::new("").is_ok(), false);
|
|
||||||
assert_eq!(
|
|
||||||
EmailAddress::new("user@domain.tld").unwrap(),
|
|
||||||
EmailAddress {
|
|
||||||
local: "user".into(),
|
|
||||||
domain: "domain.tld".into(),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
EmailAddress::new("user@localhost").unwrap(),
|
|
||||||
EmailAddress {
|
|
||||||
local: "user".into(),
|
|
||||||
domain: "localhost".into()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert_eq!(EmailAddress::new("uuu").is_ok(), false);
|
|
||||||
assert_eq!(EmailAddress::new("dd.tt").is_ok(), false);
|
|
||||||
assert!(EmailAddress::new("tt.dd@uu").is_ok());
|
|
||||||
assert!(EmailAddress::new("u@d").is_ok());
|
|
||||||
assert!(EmailAddress::new("u@d.").is_err());
|
|
||||||
assert!(EmailAddress::new("u@d.t").is_ok());
|
|
||||||
assert_eq!(
|
|
||||||
EmailAddress::new("u@d.tt").unwrap(),
|
|
||||||
EmailAddress {
|
|
||||||
local: "u".into(),
|
|
||||||
domain: "d.tt".into(),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
assert!(EmailAddress::new("u@tt").is_ok());
|
|
||||||
assert_eq!(EmailAddress::new("@d.tt").is_ok(), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_vcard_android() {
|
|
||||||
let contacts = parse_vcard(
|
|
||||||
"BEGIN:VCARD
|
|
||||||
VERSION:2.1
|
|
||||||
N:;Bob;;;
|
|
||||||
FN:Bob
|
|
||||||
TEL;CELL:+1-234-567-890
|
|
||||||
EMAIL;HOME:bob@example.org
|
|
||||||
END:VCARD
|
|
||||||
BEGIN:VCARD
|
|
||||||
VERSION:2.1
|
|
||||||
N:;Alice;;;
|
|
||||||
FN:Alice
|
|
||||||
EMAIL;HOME:alice@example.org
|
|
||||||
END:VCARD
|
|
||||||
",
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(contacts[0].addr, "bob@example.org".to_string());
|
|
||||||
assert_eq!(contacts[0].authname, "Bob".to_string());
|
|
||||||
assert_eq!(contacts[0].key, None);
|
|
||||||
assert_eq!(contacts[0].profile_image, None);
|
|
||||||
|
|
||||||
assert_eq!(contacts[1].addr, "alice@example.org".to_string());
|
|
||||||
assert_eq!(contacts[1].authname, "Alice".to_string());
|
|
||||||
assert_eq!(contacts[1].key, None);
|
|
||||||
assert_eq!(contacts[1].profile_image, None);
|
|
||||||
|
|
||||||
assert_eq!(contacts.len(), 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_vcard_local_datetime() {
|
|
||||||
let contacts = parse_vcard(
|
|
||||||
"BEGIN:VCARD\n\
|
|
||||||
VERSION:4.0\n\
|
|
||||||
FN:Alice Wonderland\n\
|
|
||||||
EMAIL;TYPE=work:alice@example.org\n\
|
|
||||||
REV:20240418T184242\n\
|
|
||||||
END:VCARD",
|
|
||||||
);
|
|
||||||
assert_eq!(contacts.len(), 1);
|
|
||||||
assert_eq!(contacts[0].addr, "alice@example.org".to_string());
|
|
||||||
assert_eq!(contacts[0].authname, "Alice Wonderland".to_string());
|
|
||||||
assert_eq!(
|
|
||||||
*contacts[0].timestamp.as_ref().unwrap(),
|
|
||||||
chrono::offset::Local
|
|
||||||
.with_ymd_and_hms(2024, 4, 18, 18, 42, 42)
|
|
||||||
.unwrap()
|
|
||||||
.timestamp()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_vcard_with_base64_avatar() {
|
|
||||||
// This is not an actual base64-encoded avatar, it's just to test the parsing.
|
|
||||||
// This one is Android-like.
|
|
||||||
let vcard0 = "BEGIN:VCARD
|
|
||||||
VERSION:2.1
|
|
||||||
N:;Bob;;;
|
|
||||||
FN:Bob
|
|
||||||
EMAIL;HOME:bob@example.org
|
|
||||||
PHOTO;ENCODING=BASE64;JPEG:/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEU
|
|
||||||
AAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAA
|
|
||||||
L8bRuAJYoZUYrI4ZY3VWwxw4Ay28AAGBISScmf/2Q==
|
|
||||||
|
|
||||||
END:VCARD
|
|
||||||
";
|
|
||||||
// This one is DOS-like.
|
|
||||||
let vcard1 = vcard0.replace('\n', "\r\n");
|
|
||||||
for vcard in [vcard0, vcard1.as_str()] {
|
|
||||||
let contacts = parse_vcard(vcard);
|
|
||||||
assert_eq!(contacts.len(), 1);
|
|
||||||
assert_eq!(contacts[0].addr, "bob@example.org".to_string());
|
|
||||||
assert_eq!(contacts[0].authname, "Bob".to_string());
|
|
||||||
assert_eq!(contacts[0].key, None);
|
|
||||||
assert_eq!(contacts[0].profile_image.as_deref().unwrap(), "/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAL8bRuAJYoZUYrI4ZY3VWwxw4Ay28AAGBISScmf/2Q==");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_protonmail_vcard() {
|
|
||||||
let contacts = parse_vcard(
|
|
||||||
"BEGIN:VCARD
|
|
||||||
VERSION:4.0
|
|
||||||
FN;PREF=1:Alice Wonderland
|
|
||||||
UID:proton-web-03747582-328d-38dc-5ddd-000000000000
|
|
||||||
ITEM1.EMAIL;PREF=1:alice@example.org
|
|
||||||
ITEM1.KEY;PREF=1:data:application/pgp-keys;base64,aaaaaaaaaaaaaaaaaaaaaaaaa
|
|
||||||
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
|
||||||
ITEM1.KEY;PREF=2:data:application/pgp-keys;base64,bbbbbbbbbbbbbbbbbbbbbbbbb
|
|
||||||
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
|
|
||||||
ITEM1.X-PM-ENCRYPT:true
|
|
||||||
ITEM1.X-PM-SIGN:true
|
|
||||||
END:VCARD",
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(contacts.len(), 1);
|
|
||||||
assert_eq!(&contacts[0].addr, "alice@example.org");
|
|
||||||
assert_eq!(&contacts[0].authname, "Alice Wonderland");
|
|
||||||
assert_eq!(contacts[0].key.as_ref().unwrap(), "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
|
|
||||||
assert!(contacts[0].timestamp.is_err());
|
|
||||||
assert_eq!(contacts[0].profile_image, None);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_sanitize_name() {
|
|
||||||
assert_eq!(&sanitize_name(" hello world "), "hello world");
|
|
||||||
assert_eq!(&sanitize_name("<"), "<");
|
|
||||||
assert_eq!(&sanitize_name(">"), ">");
|
|
||||||
assert_eq!(&sanitize_name("'"), "'");
|
|
||||||
assert_eq!(&sanitize_name("\""), "\"");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_sanitize_single_line() {
|
|
||||||
assert_eq!(sanitize_single_line("Hi\naiae "), "Hi aiae");
|
|
||||||
assert_eq!(sanitize_single_line("\r\nahte\n\r"), "ahte");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_sanitize_bidi_characters() {
|
|
||||||
// Legit inputs:
|
|
||||||
assert_eq!(
|
|
||||||
&sanitize_bidi_characters("Tes\u{2067}ting Delta Chat\u{2069}"),
|
|
||||||
"Tes\u{2067}ting Delta Chat\u{2069}"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
&sanitize_bidi_characters("Tes\u{2067}ting \u{2068} Delta Chat\u{2069}\u{2069}"),
|
|
||||||
"Tes\u{2067}ting \u{2068} Delta Chat\u{2069}\u{2069}"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
&sanitize_bidi_characters("Tes\u{2067}ting\u{2069} Delta Chat\u{2067}\u{2069}"),
|
|
||||||
"Tes\u{2067}ting\u{2069} Delta Chat\u{2067}\u{2069}"
|
|
||||||
);
|
|
||||||
|
|
||||||
// Potentially-malicious inputs:
|
|
||||||
assert_eq!(
|
|
||||||
&sanitize_bidi_characters("Tes\u{202C}ting Delta Chat"),
|
|
||||||
"Testing Delta Chat"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
&sanitize_bidi_characters("Testing Delta Chat\u{2069}"),
|
|
||||||
"Testing Delta Chat"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
&sanitize_bidi_characters("Tes\u{2067}ting Delta Chat"),
|
|
||||||
"Testing Delta Chat"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
&sanitize_bidi_characters("Tes\u{2069}ting Delta Chat\u{2067}"),
|
|
||||||
"Testing Delta Chat"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
|
||||||
&sanitize_bidi_characters("Tes\u{2068}ting Delta Chat"),
|
|
||||||
"Testing Delta Chat"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "deltachat_ffi"
|
name = "deltachat_ffi"
|
||||||
version = "1.147.0"
|
version = "1.137.2"
|
||||||
description = "Deltachat FFI"
|
description = "Deltachat FFI"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@@ -14,21 +14,21 @@ name = "deltachat"
|
|||||||
crate-type = ["cdylib", "staticlib"]
|
crate-type = ["cdylib", "staticlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
deltachat = { workspace = true, default-features = false }
|
deltachat = { path = "../", default-features = false }
|
||||||
deltachat-jsonrpc = { workspace = true, optional = true }
|
deltachat-jsonrpc = { path = "../deltachat-jsonrpc", optional = true }
|
||||||
libc = { workspace = true }
|
libc = "0.2"
|
||||||
human-panic = { version = "2", default-features = false }
|
human-panic = { version = "1", default-features = false }
|
||||||
num-traits = { workspace = true }
|
num-traits = "0.2"
|
||||||
serde_json = { workspace = true }
|
serde_json = "1.0"
|
||||||
tokio = { workspace = true, features = ["rt-multi-thread"] }
|
tokio = { version = "1", features = ["rt-multi-thread"] }
|
||||||
anyhow = { workspace = true }
|
anyhow = "1"
|
||||||
thiserror = { workspace = true }
|
thiserror = "1"
|
||||||
rand = { workspace = true }
|
rand = "0.8"
|
||||||
once_cell = { workspace = true }
|
once_cell = "1.18.0"
|
||||||
yerpc = { workspace = true, features = ["anyhow_expose"] }
|
yerpc = { version = "0.5.1", features = ["anyhow_expose"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["vendored"]
|
default = ["vendored"]
|
||||||
vendored = ["deltachat/vendored", "deltachat-jsonrpc/vendored"]
|
vendored = ["deltachat/vendored"]
|
||||||
jsonrpc = ["dep:deltachat-jsonrpc"]
|
jsonrpc = ["dep:deltachat-jsonrpc"]
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ typedef struct _dc_array dc_array_t;
|
|||||||
typedef struct _dc_chatlist dc_chatlist_t;
|
typedef struct _dc_chatlist dc_chatlist_t;
|
||||||
typedef struct _dc_chat dc_chat_t;
|
typedef struct _dc_chat dc_chat_t;
|
||||||
typedef struct _dc_msg dc_msg_t;
|
typedef struct _dc_msg dc_msg_t;
|
||||||
|
typedef struct _dc_reactions dc_reactions_t;
|
||||||
typedef struct _dc_contact dc_contact_t;
|
typedef struct _dc_contact dc_contact_t;
|
||||||
typedef struct _dc_lot dc_lot_t;
|
typedef struct _dc_lot dc_lot_t;
|
||||||
typedef struct _dc_provider dc_provider_t;
|
typedef struct _dc_provider dc_provider_t;
|
||||||
@@ -362,12 +363,8 @@ uint32_t dc_get_id (dc_context_t* context);
|
|||||||
* Must be freed using dc_event_emitter_unref() after usage.
|
* Must be freed using dc_event_emitter_unref() after usage.
|
||||||
*
|
*
|
||||||
* Note: Use only one event emitter per context.
|
* Note: Use only one event emitter per context.
|
||||||
* The result of having multiple event emitters is unspecified.
|
* Having more than one event emitter running at the same time on the same context
|
||||||
* Currently events are broadcasted to all existing event emitters,
|
* will result in events being randomly delivered to one of the emitters.
|
||||||
* but previous versions delivered events to only one event emitter
|
|
||||||
* and this behavior may change again in the future.
|
|
||||||
* Events emitted before creation of event emitter
|
|
||||||
* may or may not be available to event emitter.
|
|
||||||
*/
|
*/
|
||||||
dc_event_emitter_t* dc_get_event_emitter(dc_context_t* context);
|
dc_event_emitter_t* dc_get_event_emitter(dc_context_t* context);
|
||||||
|
|
||||||
@@ -403,10 +400,13 @@ char* dc_get_blobdir (const dc_context_t* context);
|
|||||||
* - `send_port` = SMTP-port, guessed if left out
|
* - `send_port` = SMTP-port, guessed if left out
|
||||||
* - `send_security`= SMTP-socket, one of @ref DC_SOCKET, defaults to #DC_SOCKET_AUTO
|
* - `send_security`= SMTP-socket, one of @ref DC_SOCKET, defaults to #DC_SOCKET_AUTO
|
||||||
* - `server_flags` = IMAP-/SMTP-flags as a combination of @ref DC_LP flags, guessed if left out
|
* - `server_flags` = IMAP-/SMTP-flags as a combination of @ref DC_LP flags, guessed if left out
|
||||||
* - `proxy_enabled` = Proxy enabled. Disabled by default.
|
* - `socks5_enabled` = SOCKS5 enabled
|
||||||
* - `proxy_url` = Proxy URL. May contain multiple URLs separated by newline, but only the first one is used.
|
* - `socks5_host` = SOCKS5 proxy server host
|
||||||
|
* - `socks5_port` = SOCKS5 proxy server port
|
||||||
|
* - `socks5_user` = SOCKS5 proxy username
|
||||||
|
* - `socks5_password` = SOCKS5 proxy password
|
||||||
* - `imap_certificate_checks` = how to check IMAP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
|
* - `imap_certificate_checks` = how to check IMAP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
|
||||||
* - `smtp_certificate_checks` = deprecated option, should be set to the same value as `imap_certificate_checks` but ignored by the new core
|
* - `smtp_certificate_checks` = how to check SMTP certificates, one of the @ref DC_CERTCK flags, defaults to #DC_CERTCK_AUTO (0)
|
||||||
* - `displayname` = Own name to use when sending messages. MUAs are allowed to spread this way e.g. using CC, defaults to empty
|
* - `displayname` = Own name to use when sending messages. MUAs are allowed to spread this way e.g. using CC, defaults to empty
|
||||||
* - `selfstatus` = Own status to display, e.g. in e-mail footers, defaults to empty
|
* - `selfstatus` = Own status to display, e.g. in e-mail footers, defaults to empty
|
||||||
* - `selfavatar` = File containing avatar. Will immediately be copied to the
|
* - `selfavatar` = File containing avatar. Will immediately be copied to the
|
||||||
@@ -417,10 +417,9 @@ char* dc_get_blobdir (const dc_context_t* context);
|
|||||||
* and also recoded to a reasonable size.
|
* and also recoded to a reasonable size.
|
||||||
* - `e2ee_enabled` = 0=no end-to-end-encryption, 1=prefer end-to-end-encryption (default)
|
* - `e2ee_enabled` = 0=no end-to-end-encryption, 1=prefer end-to-end-encryption (default)
|
||||||
* - `mdns_enabled` = 0=do not send or request read receipts,
|
* - `mdns_enabled` = 0=do not send or request read receipts,
|
||||||
* 1=send and request read receipts
|
* 1=send and request read receipts (default)
|
||||||
* default=send and request read receipts, only send but not reuqest if `bot` is set
|
* - `bcc_self` = 0=do not send a copy of outgoing messages to self (default),
|
||||||
* - `bcc_self` = 0=do not send a copy of outgoing messages to self,
|
* 1=send a copy of outgoing messages to self.
|
||||||
* 1=send a copy of outgoing messages to self (default).
|
|
||||||
* Sending messages to self is needed for a proper multi-account setup,
|
* Sending messages to self is needed for a proper multi-account setup,
|
||||||
* however, on the other hand, may lead to unwanted notifications in non-delta clients.
|
* however, on the other hand, may lead to unwanted notifications in non-delta clients.
|
||||||
* - `sentbox_watch`= 1=watch `Sent`-folder for changes,
|
* - `sentbox_watch`= 1=watch `Sent`-folder for changes,
|
||||||
@@ -479,9 +478,8 @@ char* dc_get_blobdir (const dc_context_t* context);
|
|||||||
* - `bot` = Set to "1" if this is a bot.
|
* - `bot` = Set to "1" if this is a bot.
|
||||||
* Prevents adding the "Device messages" and "Saved messages" chats,
|
* Prevents adding the "Device messages" and "Saved messages" chats,
|
||||||
* adds Auto-Submitted header to outgoing messages,
|
* adds Auto-Submitted header to outgoing messages,
|
||||||
* accepts contact requests automatically (calling dc_accept_chat() is not needed),
|
* accepts contact requests automatically (calling dc_accept_chat() is not needed for bots)
|
||||||
* does not cut large incoming text messages,
|
* and does not cut large incoming text messages.
|
||||||
* handles existing messages the same way as new ones if `fetch_existing_msgs=1`.
|
|
||||||
* - `last_msg_id` = database ID of the last message processed by the bot.
|
* - `last_msg_id` = database ID of the last message processed by the bot.
|
||||||
* This ID and IDs below it are guaranteed not to be returned
|
* This ID and IDs below it are guaranteed not to be returned
|
||||||
* by dc_get_next_msgs() and dc_wait_next_msgs().
|
* by dc_get_next_msgs() and dc_wait_next_msgs().
|
||||||
@@ -492,8 +490,8 @@ char* dc_get_blobdir (const dc_context_t* context);
|
|||||||
* For most bots calling `dc_markseen_msgs()` is the
|
* For most bots calling `dc_markseen_msgs()` is the
|
||||||
* recommended way to update this value
|
* recommended way to update this value
|
||||||
* even for self-sent messages.
|
* even for self-sent messages.
|
||||||
* - `fetch_existing_msgs` = 0=do not fetch existing messages on configure (default),
|
* - `fetch_existing_msgs` = 1=fetch most recent existing messages on configure (default),
|
||||||
* 1=fetch most recent existing messages on configure.
|
* 0=do not fetch existing messages on configure.
|
||||||
* In both cases, existing recipients are added to the contact database.
|
* In both cases, existing recipients are added to the contact database.
|
||||||
* - `disable_idle` = 1=disable IMAP IDLE even if the server supports it,
|
* - `disable_idle` = 1=disable IMAP IDLE even if the server supports it,
|
||||||
* 0=use IMAP IDLE if the server supports it.
|
* 0=use IMAP IDLE if the server supports it.
|
||||||
@@ -516,20 +514,11 @@ char* dc_get_blobdir (const dc_context_t* context);
|
|||||||
* 0=Nothing else happens when the key changes.
|
* 0=Nothing else happens when the key changes.
|
||||||
* 1=After the key changed, `dc_chat_can_send()` returns false and `dc_chat_is_protection_broken()` returns true
|
* 1=After the key changed, `dc_chat_can_send()` returns false and `dc_chat_is_protection_broken()` returns true
|
||||||
* until `dc_accept_chat()` is called.
|
* until `dc_accept_chat()` is called.
|
||||||
* - `is_chatmail` = 1 if the the server is a chatmail server, 0 otherwise.
|
|
||||||
* - `is_muted` = Whether a context is muted by the user.
|
|
||||||
* Muted contexts should not sound, vibrate or show notifications.
|
|
||||||
* In contrast to `dc_set_chat_mute_duration()`,
|
|
||||||
* fresh message and badge counters are not changed by this setting,
|
|
||||||
* but should be tuned down where appropriate.
|
|
||||||
* - `ui.*` = All keys prefixed by `ui.` can be used by the user-interfaces for system-specific purposes.
|
* - `ui.*` = All keys prefixed by `ui.` can be used by the user-interfaces for system-specific purposes.
|
||||||
* The prefix should be followed by the system and maybe subsystem,
|
* The prefix should be followed by the system and maybe subsystem,
|
||||||
* e.g. `ui.desktop.foo`, `ui.desktop.linux.bar`, `ui.android.foo`, `ui.dc40.bar`, `ui.bot.simplebot.baz`.
|
* e.g. `ui.desktop.foo`, `ui.desktop.linux.bar`, `ui.android.foo`, `ui.dc40.bar`, `ui.bot.simplebot.baz`.
|
||||||
* These keys go to backups and allow easy per-account settings when using @ref dc_accounts_t,
|
* These keys go to backups and allow easy per-account settings when using @ref dc_accounts_t,
|
||||||
* however, are not handled by the core otherwise.
|
* however, are not handled by the core otherwise.
|
||||||
* - `webxdc_realtime_enabled` = Whether the realtime APIs should be enabled.
|
|
||||||
* 0 = WebXDC realtime API is disabled and behaves as noop (default).
|
|
||||||
* 1 = WebXDC realtime API is enabled.
|
|
||||||
*
|
*
|
||||||
* If you want to retrieve a value, use dc_get_config().
|
* If you want to retrieve a value, use dc_get_config().
|
||||||
*
|
*
|
||||||
@@ -864,10 +853,13 @@ void dc_maybe_network (dc_context_t* context);
|
|||||||
*
|
*
|
||||||
* @memberof dc_context_t
|
* @memberof dc_context_t
|
||||||
* @param context The context as created by dc_context_new().
|
* @param context The context as created by dc_context_new().
|
||||||
|
* @param addr The e-mail address of the user. This must match the
|
||||||
|
* configured_addr setting of the context as well as the UID of the key.
|
||||||
|
* @param public_data Ignored, actual public key is extracted from secret_data.
|
||||||
* @param secret_data ASCII armored secret key.
|
* @param secret_data ASCII armored secret key.
|
||||||
* @return 1 on success, 0 on failure.
|
* @return 1 on success, 0 on failure.
|
||||||
*/
|
*/
|
||||||
int dc_preconfigure_keypair (dc_context_t* context, const char *secret_data);
|
int dc_preconfigure_keypair (dc_context_t* context, const char *addr, const char *public_data, const char *secret_data);
|
||||||
|
|
||||||
|
|
||||||
// handle chatlists
|
// handle chatlists
|
||||||
@@ -1125,6 +1117,36 @@ uint32_t dc_send_text_msg (dc_context_t* context, uint32_t ch
|
|||||||
uint32_t dc_send_videochat_invitation (dc_context_t* context, uint32_t chat_id);
|
uint32_t dc_send_videochat_invitation (dc_context_t* context, uint32_t chat_id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send a reaction to message.
|
||||||
|
*
|
||||||
|
* Reaction is a string of emojis separated by spaces. Reaction to a
|
||||||
|
* single message can be sent multiple times. The last reaction
|
||||||
|
* received overrides all previously received reactions. It is
|
||||||
|
* possible to remove all reactions by sending an empty string.
|
||||||
|
*
|
||||||
|
* @deprecated 2023-11-27, use jsonrpc method `send_reaction` instead
|
||||||
|
* @memberof dc_context_t
|
||||||
|
* @param context The context object.
|
||||||
|
* @param msg_id ID of the message you react to.
|
||||||
|
* @param reaction A string consisting of emojis separated by spaces.
|
||||||
|
* @return The ID of the message sent out or 0 for errors.
|
||||||
|
*/
|
||||||
|
uint32_t dc_send_reaction (dc_context_t* context, uint32_t msg_id, char *reaction);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a structure with reactions to the message.
|
||||||
|
*
|
||||||
|
* @deprecated 2023-11-27, use jsonrpc method `get_message_reactions` instead
|
||||||
|
* @memberof dc_context_t
|
||||||
|
* @param context The context object.
|
||||||
|
* @param msg_id The message ID to get reactions for.
|
||||||
|
* @return A structure with all reactions to the message.
|
||||||
|
*/
|
||||||
|
dc_reactions_t* dc_get_msg_reactions (dc_context_t *context, int msg_id);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A webxdc instance sends a status update to its other members.
|
* A webxdc instance sends a status update to its other members.
|
||||||
*
|
*
|
||||||
@@ -1187,65 +1209,6 @@ 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);
|
char* dc_get_webxdc_status_updates (dc_context_t* context, uint32_t msg_id, uint32_t serial);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set Webxdc file as integration.
|
|
||||||
* see dc_init_webxdc_integration() for more details about Webxdc integrations.
|
|
||||||
*
|
|
||||||
* @warning This is an experimental API which may change in the future
|
|
||||||
*
|
|
||||||
* @memberof dc_context_t
|
|
||||||
* @param context The context object.
|
|
||||||
* @param file The .xdc file to use as Webxdc integration.
|
|
||||||
*/
|
|
||||||
void dc_set_webxdc_integration (dc_context_t* context, const char* file);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Init a Webxdc integration.
|
|
||||||
*
|
|
||||||
* A Webxdc integration is
|
|
||||||
* a Webxdc showing a map, getting locations via setUpdateListener(), setting POIs via sendUpdate();
|
|
||||||
* core takes eg. care of feeding locations to the Webxdc or sending the data out.
|
|
||||||
*
|
|
||||||
* @warning This is an experimental API, esp. support of integration types (eg. image editor, tools) is left out for simplicity
|
|
||||||
*
|
|
||||||
* Currently, Webxdc integrations are .xdc files shipped together with the main app.
|
|
||||||
* Before dc_init_webxdc_integration() can be called,
|
|
||||||
* UI has to call dc_set_webxdc_integration() to define a .xdc file to be used as integration.
|
|
||||||
*
|
|
||||||
* dc_init_webxdc_integration() returns a Webxdc message ID that
|
|
||||||
* UI can open and use mostly as usual.
|
|
||||||
*
|
|
||||||
* Concrete behaviour and status updates depend on the integration, driven by UI needs.
|
|
||||||
*
|
|
||||||
* There is no need to de-initialize the integration,
|
|
||||||
* however, unless documented otherwise,
|
|
||||||
* the integration is valid only as long as not re-initialized
|
|
||||||
* In other words, UI must not have a Webxdc with the same integration open twice.
|
|
||||||
*
|
|
||||||
* Example:
|
|
||||||
*
|
|
||||||
* ~~~
|
|
||||||
* // Define a .xdc file to be used as maps integration
|
|
||||||
* dc_set_webxdc_integration(context, path_to_maps_xdc);
|
|
||||||
*
|
|
||||||
* // Integrate the map to a chat, the map will show locations for this chat then:
|
|
||||||
* uint32_t webxdc_instance = dc_init_webxdc_integration(context, any_chat_id);
|
|
||||||
*
|
|
||||||
* // Or use the Webxdc as a global map, showing locations of all chats:
|
|
||||||
* uint32_t webxdc_instance = dc_init_webxdc_integration(context, 0);
|
|
||||||
* ~~~
|
|
||||||
*
|
|
||||||
* @memberof dc_context_t
|
|
||||||
* @param context The context object.
|
|
||||||
* @param chat_id The chat to get the integration for.
|
|
||||||
* @return ID of the message that refers to the Webxdc instance.
|
|
||||||
* UI can open a Webxdc as usual with this instance.
|
|
||||||
*/
|
|
||||||
uint32_t dc_init_webxdc_integration (dc_context_t* context, uint32_t chat_id);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save a draft for a chat in the database.
|
* Save a draft for a chat in the database.
|
||||||
*
|
*
|
||||||
@@ -1547,6 +1510,30 @@ void dc_marknoticed_chat (dc_context_t* context, uint32_t ch
|
|||||||
dc_array_t* dc_get_chat_media (dc_context_t* context, uint32_t chat_id, int msg_type, int msg_type2, int msg_type3);
|
dc_array_t* dc_get_chat_media (dc_context_t* context, uint32_t chat_id, int msg_type, int msg_type2, int msg_type3);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search next/previous message based on a given message and a list of types.
|
||||||
|
* Typically used to implement the "next" and "previous" buttons
|
||||||
|
* in a gallery or in a media player.
|
||||||
|
*
|
||||||
|
* @deprecated Deprecated 2023-10-03, use dc_get_chat_media() and navigate the returned array instead.
|
||||||
|
* @memberof dc_context_t
|
||||||
|
* @param context The context object as returned from dc_context_new().
|
||||||
|
* @param msg_id The ID of the current message from which the next or previous message should be searched.
|
||||||
|
* @param dir 1=get the next message, -1=get the previous one.
|
||||||
|
* @param msg_type The message type to search for.
|
||||||
|
* If 0, the message type from curr_msg_id is used.
|
||||||
|
* @param msg_type2 Alternative message type to search for. 0 to skip.
|
||||||
|
* @param msg_type3 Alternative message type to search for. 0 to skip.
|
||||||
|
* @return Returns the message ID that should be played next.
|
||||||
|
* The returned message is in the same chat as the given one
|
||||||
|
* and has one of the given types.
|
||||||
|
* Typically, this result is passed again to dc_get_next_media()
|
||||||
|
* later on the next swipe.
|
||||||
|
* If there is not next/previous message, the function returns 0.
|
||||||
|
*/
|
||||||
|
uint32_t dc_get_next_media (dc_context_t* context, uint32_t msg_id, int dir, int msg_type, int msg_type2, int msg_type3);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set chat visibility to pinned, archived or normal.
|
* Set chat visibility to pinned, archived or normal.
|
||||||
*
|
*
|
||||||
@@ -2475,9 +2462,7 @@ void dc_stop_ongoing_process (dc_context_t* context);
|
|||||||
#define DC_QR_FPR_WITHOUT_ADDR 230 // test1=formatted fingerprint
|
#define DC_QR_FPR_WITHOUT_ADDR 230 // test1=formatted fingerprint
|
||||||
#define DC_QR_ACCOUNT 250 // text1=domain
|
#define DC_QR_ACCOUNT 250 // text1=domain
|
||||||
#define DC_QR_BACKUP 251
|
#define DC_QR_BACKUP 251
|
||||||
#define DC_QR_BACKUP2 252
|
|
||||||
#define DC_QR_WEBRTC_INSTANCE 260 // text1=domain, text2=instance pattern
|
#define DC_QR_WEBRTC_INSTANCE 260 // text1=domain, text2=instance pattern
|
||||||
#define DC_QR_PROXY 271 // text1=address (e.g. "127.0.0.1:9050")
|
|
||||||
#define DC_QR_ADDR 320 // id=contact
|
#define DC_QR_ADDR 320 // id=contact
|
||||||
#define DC_QR_TEXT 330 // text1=text
|
#define DC_QR_TEXT 330 // text1=text
|
||||||
#define DC_QR_URL 332 // text1=URL
|
#define DC_QR_URL 332 // text1=URL
|
||||||
@@ -2523,7 +2508,6 @@ void dc_stop_ongoing_process (dc_context_t* context);
|
|||||||
* if so, call dc_set_config_from_qr() and then dc_configure().
|
* if so, call dc_set_config_from_qr() and then dc_configure().
|
||||||
*
|
*
|
||||||
* - DC_QR_BACKUP:
|
* - DC_QR_BACKUP:
|
||||||
* - DC_QR_BACKUP2:
|
|
||||||
* ask the user if they want to set up a new device.
|
* ask the user if they want to set up a new device.
|
||||||
* If so, pass the qr-code to dc_receive_backup().
|
* If so, pass the qr-code to dc_receive_backup().
|
||||||
*
|
*
|
||||||
@@ -2531,10 +2515,6 @@ void dc_stop_ongoing_process (dc_context_t* context);
|
|||||||
* ask the user if they want to use the given service for video chats;
|
* ask the user if they want to use the given service for video chats;
|
||||||
* if so, call dc_set_config_from_qr().
|
* if so, call dc_set_config_from_qr().
|
||||||
*
|
*
|
||||||
* - DC_QR_SOCKS5_PROXY with dc_lot_t::text1=host, dc_lot_t::text2=port:
|
|
||||||
* ask the user if they want to use the given proxy and overwrite the previous one, if any.
|
|
||||||
* if so, call dc_set_config_from_qr() and restart I/O.
|
|
||||||
*
|
|
||||||
* - DC_QR_ADDR with dc_lot_t::id=Contact ID:
|
* - DC_QR_ADDR with dc_lot_t::id=Contact ID:
|
||||||
* e-mail address scanned, optionally, a draft message could be set in
|
* e-mail address scanned, optionally, a draft message could be set in
|
||||||
* dc_lot_t::text1 in which case dc_lot_t::text1_meaning will be DC_TEXT1_DRAFT;
|
* dc_lot_t::text1 in which case dc_lot_t::text1_meaning will be DC_TEXT1_DRAFT;
|
||||||
@@ -2596,7 +2576,7 @@ dc_lot_t* dc_check_qr (dc_context_t* context, const char*
|
|||||||
* the Verified-Group-Invite protocol is offered in the QR code;
|
* the Verified-Group-Invite protocol is offered in the QR code;
|
||||||
* works for protected groups as well as for normal groups.
|
* works for protected groups as well as for normal groups.
|
||||||
* If set to 0, the Setup-Contact protocol is offered in the QR code.
|
* If set to 0, the Setup-Contact protocol is offered in the QR code.
|
||||||
* See https://securejoin.delta.chat/
|
* See https://securejoin.readthedocs.io/en/latest/new.html
|
||||||
* for details about both protocols.
|
* for details about both protocols.
|
||||||
* @return The text that should go to the QR code,
|
* @return The text that should go to the QR code,
|
||||||
* On errors, an empty QR code is returned, NULL is never returned.
|
* On errors, an empty QR code is returned, NULL is never returned.
|
||||||
@@ -2632,7 +2612,8 @@ char* dc_get_securejoin_qr_svg (dc_context_t* context, uint32_
|
|||||||
*
|
*
|
||||||
* Subsequent calls of dc_join_securejoin() will abort previous, unfinished handshakes.
|
* Subsequent calls of dc_join_securejoin() will abort previous, unfinished handshakes.
|
||||||
*
|
*
|
||||||
* See https://securejoin.delta.chat/ for details about both protocols.
|
* See https://securejoin.readthedocs.io/en/latest/new.html
|
||||||
|
* for details about both protocols.
|
||||||
*
|
*
|
||||||
* @memberof dc_context_t
|
* @memberof dc_context_t
|
||||||
* @param context The context object.
|
* @param context The context object.
|
||||||
@@ -4093,19 +4074,6 @@ char* dc_msg_get_subject (const dc_msg_t* msg);
|
|||||||
char* dc_msg_get_file (const dc_msg_t* msg);
|
char* dc_msg_get_file (const dc_msg_t* msg);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Save file copy at the user-provided path.
|
|
||||||
*
|
|
||||||
* Fails if file already exists at the provided path.
|
|
||||||
*
|
|
||||||
* @memberof dc_msg_t
|
|
||||||
* @param msg The message object.
|
|
||||||
* @param path Destination file path with filename and extension.
|
|
||||||
* @return 0 on failure, 1 on success.
|
|
||||||
*/
|
|
||||||
int dc_msg_save_file (const dc_msg_t* msg, const char* path);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an original attachment filename, with extension but without the path. To get the full path,
|
* Get an original attachment filename, with extension but without the path. To get the full path,
|
||||||
* use dc_msg_get_file().
|
* use dc_msg_get_file().
|
||||||
@@ -4170,6 +4138,7 @@ char* dc_msg_get_webxdc_blob (const dc_msg_t* msg, const char*
|
|||||||
* true if the Webxdc should get full internet access, including Webrtc.
|
* true if the Webxdc should get full internet access, including Webrtc.
|
||||||
* currently, this is only true for encrypted Webxdc's in the self chat
|
* currently, this is only true for encrypted Webxdc's in the self chat
|
||||||
* that have requested internet access in the manifest.
|
* that have requested internet access in the manifest.
|
||||||
|
* this is useful for development and maybe for internal integrations at some point.
|
||||||
*
|
*
|
||||||
* @memberof dc_msg_t
|
* @memberof dc_msg_t
|
||||||
* @param msg The webxdc instance.
|
* @param msg The webxdc instance.
|
||||||
@@ -4378,9 +4347,9 @@ int dc_msg_has_deviating_timestamp(const dc_msg_t* msg);
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a message has a POI location bound to it.
|
* Check if a message has a location bound to it.
|
||||||
* These locations are also returned by dc_get_locations()
|
* These messages are also returned by dc_get_locations()
|
||||||
* The UI may decide to display a special icon beside such messages.
|
* and the UI may decide to display a special icon beside such messages,
|
||||||
*
|
*
|
||||||
* @memberof dc_msg_t
|
* @memberof dc_msg_t
|
||||||
* @param msg The message object.
|
* @param msg The message object.
|
||||||
@@ -5351,6 +5320,52 @@ uint32_t dc_lot_get_id (const dc_lot_t* lot);
|
|||||||
int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
|
int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class dc_reactions_t
|
||||||
|
* @deprecated 2023-11-27, use jsonrpc method `get_message_reactions` instead
|
||||||
|
*
|
||||||
|
* An object representing all reactions for a single message.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns array of contacts which reacted to the given message.
|
||||||
|
*
|
||||||
|
* @deprecated 2023-11-27, use jsonrpc method `get_message_reactions` instead
|
||||||
|
* @memberof dc_reactions_t
|
||||||
|
* @param reactions The object containing message reactions.
|
||||||
|
* @return array of contact IDs. Use dc_array_get_cnt() to get array length and
|
||||||
|
* dc_array_get_id() to get the IDs. Should be freed using `dc_array_unref()` after usage.
|
||||||
|
*/
|
||||||
|
dc_array_t* dc_reactions_get_contacts(dc_reactions_t* reactions);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a string containing space-separated reactions of a single contact.
|
||||||
|
*
|
||||||
|
* @deprecated 2023-11-27, use jsonrpc method `get_message_reactions` instead
|
||||||
|
* @memberof dc_reactions_t
|
||||||
|
* @param reactions The object containing message reactions.
|
||||||
|
* @param contact_id ID of the contact.
|
||||||
|
* @return Space-separated list of emoji sequences, which could be empty.
|
||||||
|
* Returned string should not be modified and should be freed
|
||||||
|
* with dc_str_unref() after usage.
|
||||||
|
*/
|
||||||
|
char* dc_reactions_get_by_contact_id(dc_reactions_t* reactions, uint32_t contact_id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees an object containing message reactions.
|
||||||
|
*
|
||||||
|
* Reactions objects are created by dc_get_msg_reactions().
|
||||||
|
*
|
||||||
|
* @deprecated 2023-11-27
|
||||||
|
* @memberof dc_reactions_t
|
||||||
|
* @param reactions The object to free.
|
||||||
|
* If NULL is given, nothing is done.
|
||||||
|
*/
|
||||||
|
void dc_reactions_unref (dc_reactions_t* reactions);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup DC_MSG DC_MSG
|
* @defgroup DC_MSG DC_MSG
|
||||||
*
|
*
|
||||||
@@ -5467,11 +5482,6 @@ int64_t dc_lot_get_timestamp (const dc_lot_t* lot);
|
|||||||
*/
|
*/
|
||||||
#define DC_MSG_WEBXDC 80
|
#define DC_MSG_WEBXDC 80
|
||||||
|
|
||||||
/**
|
|
||||||
* Message containing shared contacts represented as a vCard (virtual contact file)
|
|
||||||
* with email addresses and possibly other fields.
|
|
||||||
*/
|
|
||||||
#define DC_MSG_VCARD 90
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -6271,18 +6281,6 @@ void dc_event_unref(dc_event_t* event);
|
|||||||
|
|
||||||
#define DC_EVENT_WEBXDC_INSTANCE_DELETED 2121
|
#define DC_EVENT_WEBXDC_INSTANCE_DELETED 2121
|
||||||
|
|
||||||
/**
|
|
||||||
* Data received over an ephemeral peer channel.
|
|
||||||
*
|
|
||||||
* @param data1 (int) msg_id
|
|
||||||
* @param data2 (int) + (char*) binary data.
|
|
||||||
* length is returned as integer with dc_event_get_data2_int()
|
|
||||||
* and binary data is returned as dc_event_get_data2_str().
|
|
||||||
* Binary data must be passed to dc_str_unref() afterwards.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define DC_EVENT_WEBXDC_REALTIME_DATA 2150
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tells that the Background fetch was completed (or timed out).
|
* Tells that the Background fetch was completed (or timed out).
|
||||||
*
|
*
|
||||||
@@ -6292,32 +6290,7 @@ void dc_event_unref(dc_event_t* event);
|
|||||||
* This event is only emitted by the account manager
|
* This event is only emitted by the account manager
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE 2200
|
#define DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE 2200
|
||||||
|
|
||||||
/**
|
|
||||||
* Inform that set of chats or the order of the chats in the chatlist has changed.
|
|
||||||
*
|
|
||||||
* Sometimes this is emitted together with `DC_EVENT_CHATLIST_ITEM_CHANGED`.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define DC_EVENT_CHATLIST_CHANGED 2300
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inform that all or a single chat list item changed and needs to be rerendered
|
|
||||||
* If `chat_id` is set to 0, then all currently visible chats need to be rerendered, and all not-visible items need to be cleared from cache if the UI has a cache.
|
|
||||||
*
|
|
||||||
* @param data1 (int) chat_id chat id of chatlist item to be rerendered, if chat_id = 0 all (cached & visible) items need to be rerendered
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define DC_EVENT_CHATLIST_ITEM_CHANGED 2301
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Inform that some events have been skipped due to event channel overflow.
|
|
||||||
*
|
|
||||||
* @param data1 (int) number of events that have been skipped
|
|
||||||
*/
|
|
||||||
#define DC_EVENT_CHANNEL_OVERFLOW 2400
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
@@ -6626,16 +6599,12 @@ void dc_event_unref(dc_event_t* event);
|
|||||||
/// "Message opened"
|
/// "Message opened"
|
||||||
///
|
///
|
||||||
/// Used in subjects of outgoing read receipts.
|
/// Used in subjects of outgoing read receipts.
|
||||||
///
|
|
||||||
/// @deprecated Deprecated 2024-07-26
|
|
||||||
#define DC_STR_READRCPT 31
|
#define DC_STR_READRCPT 31
|
||||||
|
|
||||||
/// "The message '%1$s' you sent was displayed on the screen of the recipient."
|
/// "The message '%1$s' you sent was displayed on the screen of the recipient."
|
||||||
///
|
///
|
||||||
/// Used as message text of outgoing read receipts.
|
/// Used as message text of outgoing read receipts.
|
||||||
/// - %1$s will be replaced by the subject of the displayed message
|
/// - %1$s will be replaced by the subject of the displayed message
|
||||||
///
|
|
||||||
/// @deprecated Deprecated 2024-06-23
|
|
||||||
#define DC_STR_READRCPT_MAILBODY 32
|
#define DC_STR_READRCPT_MAILBODY 32
|
||||||
|
|
||||||
/// @deprecated Deprecated, this string is no longer needed.
|
/// @deprecated Deprecated, this string is no longer needed.
|
||||||
@@ -7344,19 +7313,6 @@ void dc_event_unref(dc_event_t* event);
|
|||||||
/// Used in summaries.
|
/// Used in summaries.
|
||||||
#define DC_STR_REACTED_BY 177
|
#define DC_STR_REACTED_BY 177
|
||||||
|
|
||||||
/// "Establishing guaranteed end-to-end encryption, please wait…"
|
|
||||||
///
|
|
||||||
/// Used as info message.
|
|
||||||
#define DC_STR_SECUREJOIN_WAIT 190
|
|
||||||
|
|
||||||
/// "Could not yet establish guaranteed end-to-end encryption, but you may already send a message."
|
|
||||||
///
|
|
||||||
/// Used as info message.
|
|
||||||
#define DC_STR_SECUREJOIN_WAIT_TIMEOUT 191
|
|
||||||
|
|
||||||
/// "Contact". Deprecated, currently unused.
|
|
||||||
#define DC_STR_CONTACT 200
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
#![warn(unused, clippy::all)]
|
#![warn(unused, clippy::all)]
|
||||||
#![allow(
|
#![allow(
|
||||||
non_camel_case_types,
|
non_camel_case_types,
|
||||||
non_snake_case,
|
non_snake_case,
|
||||||
non_upper_case_globals,
|
non_upper_case_globals,
|
||||||
|
non_upper_case_globals,
|
||||||
|
non_camel_case_types,
|
||||||
clippy::missing_safety_doc,
|
clippy::missing_safety_doc,
|
||||||
clippy::expect_fun_call
|
clippy::expect_fun_call
|
||||||
)]
|
)]
|
||||||
@@ -31,6 +32,7 @@ use deltachat::imex::BackupProvider;
|
|||||||
use deltachat::key::preconfigure_keypair;
|
use deltachat::key::preconfigure_keypair;
|
||||||
use deltachat::message::MsgId;
|
use deltachat::message::MsgId;
|
||||||
use deltachat::qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg};
|
use deltachat::qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg};
|
||||||
|
use deltachat::reaction::{get_msg_reactions, send_reaction, Reactions};
|
||||||
use deltachat::stock_str::StockMessage;
|
use deltachat::stock_str::StockMessage;
|
||||||
use deltachat::webxdc::StatusUpdateSerial;
|
use deltachat::webxdc::StatusUpdateSerial;
|
||||||
use deltachat::*;
|
use deltachat::*;
|
||||||
@@ -66,6 +68,8 @@ const DC_GCM_INFO_ONLY: u32 = 0x02;
|
|||||||
/// Struct representing the deltachat context.
|
/// Struct representing the deltachat context.
|
||||||
pub type dc_context_t = Context;
|
pub type dc_context_t = Context;
|
||||||
|
|
||||||
|
pub type dc_reactions_t = Reactions;
|
||||||
|
|
||||||
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("unable to create tokio runtime"));
|
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("unable to create tokio runtime"));
|
||||||
|
|
||||||
fn block_on<T>(fut: T) -> T::Output
|
fn block_on<T>(fut: T) -> T::Output
|
||||||
@@ -562,11 +566,7 @@ pub unsafe extern "C" fn dc_event_get_id(event: *mut dc_event_t) -> libc::c_int
|
|||||||
EventType::ConfigSynced { .. } => 2111,
|
EventType::ConfigSynced { .. } => 2111,
|
||||||
EventType::WebxdcStatusUpdate { .. } => 2120,
|
EventType::WebxdcStatusUpdate { .. } => 2120,
|
||||||
EventType::WebxdcInstanceDeleted { .. } => 2121,
|
EventType::WebxdcInstanceDeleted { .. } => 2121,
|
||||||
EventType::WebxdcRealtimeData { .. } => 2150,
|
|
||||||
EventType::AccountsBackgroundFetchDone => 2200,
|
EventType::AccountsBackgroundFetchDone => 2200,
|
||||||
EventType::ChatlistChanged => 2300,
|
|
||||||
EventType::ChatlistItemChanged { .. } => 2301,
|
|
||||||
EventType::EventChannelOverflow { .. } => 2400,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -596,7 +596,6 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
|
|||||||
| EventType::IncomingMsgBunch { .. }
|
| EventType::IncomingMsgBunch { .. }
|
||||||
| EventType::ErrorSelfNotInGroup(_)
|
| EventType::ErrorSelfNotInGroup(_)
|
||||||
| EventType::AccountsBackgroundFetchDone => 0,
|
| EventType::AccountsBackgroundFetchDone => 0,
|
||||||
EventType::ChatlistChanged => 0,
|
|
||||||
EventType::MsgsChanged { chat_id, .. }
|
EventType::MsgsChanged { chat_id, .. }
|
||||||
| EventType::ReactionsChanged { chat_id, .. }
|
| EventType::ReactionsChanged { chat_id, .. }
|
||||||
| EventType::IncomingMsg { chat_id, .. }
|
| EventType::IncomingMsg { chat_id, .. }
|
||||||
@@ -619,13 +618,8 @@ pub unsafe extern "C" fn dc_event_get_data1_int(event: *mut dc_event_t) -> libc:
|
|||||||
| EventType::SecurejoinJoinerProgress { contact_id, .. } => {
|
| EventType::SecurejoinJoinerProgress { contact_id, .. } => {
|
||||||
contact_id.to_u32() as libc::c_int
|
contact_id.to_u32() as libc::c_int
|
||||||
}
|
}
|
||||||
EventType::WebxdcRealtimeData { msg_id, .. }
|
EventType::WebxdcStatusUpdate { msg_id, .. } => msg_id.to_u32() as libc::c_int,
|
||||||
| EventType::WebxdcStatusUpdate { msg_id, .. }
|
EventType::WebxdcInstanceDeleted { msg_id, .. } => msg_id.to_u32() as libc::c_int,
|
||||||
| EventType::WebxdcInstanceDeleted { msg_id, .. } => msg_id.to_u32() as libc::c_int,
|
|
||||||
EventType::ChatlistItemChanged { chat_id } => {
|
|
||||||
chat_id.unwrap_or_default().to_u32() as libc::c_int
|
|
||||||
}
|
|
||||||
EventType::EventChannelOverflow { n } => *n as libc::c_int,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -662,11 +656,8 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
|
|||||||
| EventType::IncomingMsgBunch { .. }
|
| EventType::IncomingMsgBunch { .. }
|
||||||
| EventType::SelfavatarChanged
|
| EventType::SelfavatarChanged
|
||||||
| EventType::AccountsBackgroundFetchDone
|
| EventType::AccountsBackgroundFetchDone
|
||||||
| EventType::ChatlistChanged
|
| EventType::ConfigSynced { .. } => 0,
|
||||||
| EventType::ChatlistItemChanged { .. }
|
EventType::ChatModified(_) => 0,
|
||||||
| EventType::ConfigSynced { .. }
|
|
||||||
| EventType::ChatModified(_)
|
|
||||||
| EventType::EventChannelOverflow { .. } => 0,
|
|
||||||
EventType::MsgsChanged { msg_id, .. }
|
EventType::MsgsChanged { msg_id, .. }
|
||||||
| EventType::ReactionsChanged { msg_id, .. }
|
| EventType::ReactionsChanged { msg_id, .. }
|
||||||
| EventType::IncomingMsg { msg_id, .. }
|
| EventType::IncomingMsg { msg_id, .. }
|
||||||
@@ -681,7 +672,6 @@ pub unsafe extern "C" fn dc_event_get_data2_int(event: *mut dc_event_t) -> libc:
|
|||||||
status_update_serial,
|
status_update_serial,
|
||||||
..
|
..
|
||||||
} => status_update_serial.to_u32() as libc::c_int,
|
} => status_update_serial.to_u32() as libc::c_int,
|
||||||
EventType::WebxdcRealtimeData { data, .. } => data.len() as libc::c_int,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -730,10 +720,7 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
|
|||||||
| EventType::WebxdcInstanceDeleted { .. }
|
| EventType::WebxdcInstanceDeleted { .. }
|
||||||
| EventType::AccountsBackgroundFetchDone
|
| EventType::AccountsBackgroundFetchDone
|
||||||
| EventType::ChatEphemeralTimerModified { .. }
|
| EventType::ChatEphemeralTimerModified { .. }
|
||||||
| EventType::IncomingMsgBunch { .. }
|
| EventType::IncomingMsgBunch { .. } => ptr::null_mut(),
|
||||||
| EventType::ChatlistItemChanged { .. }
|
|
||||||
| EventType::ChatlistChanged
|
|
||||||
| EventType::EventChannelOverflow { .. } => ptr::null_mut(),
|
|
||||||
EventType::ConfigureProgress { comment, .. } => {
|
EventType::ConfigureProgress { comment, .. } => {
|
||||||
if let Some(comment) = comment {
|
if let Some(comment) = comment {
|
||||||
comment.to_c_string().unwrap_or_default().into_raw()
|
comment.to_c_string().unwrap_or_default().into_raw()
|
||||||
@@ -749,11 +736,6 @@ pub unsafe extern "C" fn dc_event_get_data2_str(event: *mut dc_event_t) -> *mut
|
|||||||
let data2 = key.to_string().to_c_string().unwrap_or_default();
|
let data2 = key.to_string().to_c_string().unwrap_or_default();
|
||||||
data2.into_raw()
|
data2.into_raw()
|
||||||
}
|
}
|
||||||
EventType::WebxdcRealtimeData { data, .. } => {
|
|
||||||
let ptr = libc::malloc(data.len());
|
|
||||||
libc::memcpy(ptr, data.as_ptr() as *mut libc::c_void, data.len());
|
|
||||||
ptr as *mut libc::c_char
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -835,6 +817,8 @@ pub unsafe extern "C" fn dc_maybe_network(context: *mut dc_context_t) {
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_preconfigure_keypair(
|
pub unsafe extern "C" fn dc_preconfigure_keypair(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
|
addr: *const libc::c_char,
|
||||||
|
_public_data: *const libc::c_char,
|
||||||
secret_data: *const libc::c_char,
|
secret_data: *const libc::c_char,
|
||||||
) -> i32 {
|
) -> i32 {
|
||||||
if context.is_null() {
|
if context.is_null() {
|
||||||
@@ -842,8 +826,9 @@ pub unsafe extern "C" fn dc_preconfigure_keypair(
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
let ctx = &*context;
|
let ctx = &*context;
|
||||||
|
let addr = to_string_lossy(addr);
|
||||||
let secret_data = to_string_lossy(secret_data);
|
let secret_data = to_string_lossy(secret_data);
|
||||||
block_on(preconfigure_keypair(ctx, &secret_data))
|
block_on(preconfigure_keypair(ctx, &addr, &secret_data))
|
||||||
.context("Failed to save keypair")
|
.context("Failed to save keypair")
|
||||||
.log_err(ctx)
|
.log_err(ctx)
|
||||||
.is_ok() as libc::c_int
|
.is_ok() as libc::c_int
|
||||||
@@ -1030,6 +1015,49 @@ pub unsafe extern "C" fn dc_send_videochat_invitation(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn dc_send_reaction(
|
||||||
|
context: *mut dc_context_t,
|
||||||
|
msg_id: u32,
|
||||||
|
reaction: *const libc::c_char,
|
||||||
|
) -> u32 {
|
||||||
|
if context.is_null() {
|
||||||
|
eprintln!("ignoring careless call to dc_send_reaction()");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
let ctx = &*context;
|
||||||
|
|
||||||
|
block_on(async move {
|
||||||
|
send_reaction(ctx, MsgId::new(msg_id), &to_string_lossy(reaction))
|
||||||
|
.await
|
||||||
|
.map(|msg_id| msg_id.to_u32())
|
||||||
|
.unwrap_or_log_default(ctx, "Failed to send reaction")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn dc_get_msg_reactions(
|
||||||
|
context: *mut dc_context_t,
|
||||||
|
msg_id: u32,
|
||||||
|
) -> *mut dc_reactions_t {
|
||||||
|
if context.is_null() {
|
||||||
|
eprintln!("ignoring careless call to dc_get_msg_reactions()");
|
||||||
|
return ptr::null_mut();
|
||||||
|
}
|
||||||
|
let ctx = &*context;
|
||||||
|
|
||||||
|
let reactions = if let Ok(reactions) = block_on(get_msg_reactions(ctx, MsgId::new(msg_id)))
|
||||||
|
.context("failed dc_get_msg_reactions() call")
|
||||||
|
.log_err(ctx)
|
||||||
|
{
|
||||||
|
reactions
|
||||||
|
} else {
|
||||||
|
return ptr::null_mut();
|
||||||
|
};
|
||||||
|
|
||||||
|
Box::into_raw(Box::new(reactions))
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_send_webxdc_status_update(
|
pub unsafe extern "C" fn dc_send_webxdc_status_update(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
@@ -1073,43 +1101,6 @@ pub unsafe extern "C" fn dc_get_webxdc_status_updates(
|
|||||||
.strdup()
|
.strdup()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn dc_set_webxdc_integration(
|
|
||||||
context: *mut dc_context_t,
|
|
||||||
file: *const libc::c_char,
|
|
||||||
) {
|
|
||||||
if context.is_null() || file.is_null() {
|
|
||||||
eprintln!("ignoring careless call to dc_set_webxdc_integration()");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let ctx = &*context;
|
|
||||||
block_on(ctx.set_webxdc_integration(&to_string_lossy(file)))
|
|
||||||
.log_err(ctx)
|
|
||||||
.unwrap_or_default();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn dc_init_webxdc_integration(
|
|
||||||
context: *mut dc_context_t,
|
|
||||||
chat_id: u32,
|
|
||||||
) -> u32 {
|
|
||||||
if context.is_null() {
|
|
||||||
eprintln!("ignoring careless call to dc_init_webxdc_integration()");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
let ctx = &*context;
|
|
||||||
let chat_id = if chat_id == 0 {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(ChatId::new(chat_id))
|
|
||||||
};
|
|
||||||
|
|
||||||
block_on(ctx.init_webxdc_integration(chat_id))
|
|
||||||
.log_err(ctx)
|
|
||||||
.map(|msg_id| msg_id.map(|id| id.to_u32()).unwrap_or_default())
|
|
||||||
.unwrap_or(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_set_draft(
|
pub unsafe extern "C" fn dc_set_draft(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
@@ -1443,6 +1434,48 @@ pub unsafe extern "C" fn dc_get_chat_media(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
#[allow(deprecated)]
|
||||||
|
pub unsafe extern "C" fn dc_get_next_media(
|
||||||
|
context: *mut dc_context_t,
|
||||||
|
msg_id: u32,
|
||||||
|
dir: libc::c_int,
|
||||||
|
msg_type: libc::c_int,
|
||||||
|
or_msg_type2: libc::c_int,
|
||||||
|
or_msg_type3: libc::c_int,
|
||||||
|
) -> u32 {
|
||||||
|
if context.is_null() {
|
||||||
|
eprintln!("ignoring careless call to dc_get_next_media()");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
let direction = if dir < 0 {
|
||||||
|
chat::Direction::Backward
|
||||||
|
} else {
|
||||||
|
chat::Direction::Forward
|
||||||
|
};
|
||||||
|
|
||||||
|
let ctx = &*context;
|
||||||
|
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}"));
|
||||||
|
let 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(
|
||||||
|
ctx,
|
||||||
|
MsgId::new(msg_id),
|
||||||
|
direction,
|
||||||
|
msg_type,
|
||||||
|
or_msg_type2,
|
||||||
|
or_msg_type3,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(|msg_id| msg_id.map(|id| id.to_u32()).unwrap_or_default())
|
||||||
|
.unwrap_or(0)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_set_chat_visibility(
|
pub unsafe extern "C" fn dc_set_chat_visibility(
|
||||||
context: *mut dc_context_t,
|
context: *mut dc_context_t,
|
||||||
@@ -2013,7 +2046,7 @@ pub unsafe extern "C" fn dc_get_msg(context: *mut dc_context_t, msg_id: u32) ->
|
|||||||
);
|
);
|
||||||
message::Message::default()
|
message::Message::default()
|
||||||
} else {
|
} else {
|
||||||
warn!(ctx, "dc_get_msg could not retrieve msg_id {msg_id}: {e:#}");
|
error!(ctx, "dc_get_msg could not retrieve msg_id {msg_id}: {e:#}");
|
||||||
return ptr::null_mut();
|
return ptr::null_mut();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3336,34 +3369,6 @@ pub unsafe extern "C" fn dc_msg_get_file(msg: *mut dc_msg_t) -> *mut libc::c_cha
|
|||||||
.unwrap_or_else(|| "".strdup())
|
.unwrap_or_else(|| "".strdup())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
|
||||||
pub unsafe extern "C" fn dc_msg_save_file(
|
|
||||||
msg: *mut dc_msg_t,
|
|
||||||
path: *const libc::c_char,
|
|
||||||
) -> libc::c_int {
|
|
||||||
if msg.is_null() || path.is_null() {
|
|
||||||
eprintln!("ignoring careless call to dc_msg_save_file()");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
let ffi_msg = &*msg;
|
|
||||||
let ctx = &*ffi_msg.context;
|
|
||||||
let path = to_string_lossy(path);
|
|
||||||
let r = block_on(
|
|
||||||
ffi_msg
|
|
||||||
.message
|
|
||||||
.save_file(ctx, &std::path::PathBuf::from(path)),
|
|
||||||
);
|
|
||||||
match r {
|
|
||||||
Ok(()) => 1,
|
|
||||||
Err(_) => {
|
|
||||||
r.context("Failed to save file from message")
|
|
||||||
.log_err(ctx)
|
|
||||||
.unwrap_or_default();
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||||
if msg.is_null() {
|
if msg.is_null() {
|
||||||
@@ -4239,6 +4244,45 @@ pub unsafe extern "C" fn dc_lot_get_timestamp(lot: *mut dc_lot_t) -> i64 {
|
|||||||
lot.get_timestamp()
|
lot.get_timestamp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn dc_reactions_get_contacts(
|
||||||
|
reactions: *mut dc_reactions_t,
|
||||||
|
) -> *mut dc_array::dc_array_t {
|
||||||
|
if reactions.is_null() {
|
||||||
|
eprintln!("ignoring careless call to dc_reactions_get_contacts()");
|
||||||
|
return ptr::null_mut();
|
||||||
|
}
|
||||||
|
|
||||||
|
let reactions = &*reactions;
|
||||||
|
let array: dc_array_t = reactions.contacts().into();
|
||||||
|
|
||||||
|
Box::into_raw(Box::new(array))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn dc_reactions_get_by_contact_id(
|
||||||
|
reactions: *mut dc_reactions_t,
|
||||||
|
contact_id: u32,
|
||||||
|
) -> *mut libc::c_char {
|
||||||
|
if reactions.is_null() {
|
||||||
|
eprintln!("ignoring careless call to dc_reactions_get_by_contact_id()");
|
||||||
|
return ptr::null_mut();
|
||||||
|
}
|
||||||
|
|
||||||
|
let reactions = &*reactions;
|
||||||
|
reactions.get(ContactId::new(contact_id)).as_str().strdup()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn dc_reactions_unref(reactions: *mut dc_reactions_t) {
|
||||||
|
if reactions.is_null() {
|
||||||
|
eprintln!("ignoring careless call to dc_reactions_unref()");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
drop(Box::from_raw(reactions));
|
||||||
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn dc_str_unref(s: *mut libc::c_char) {
|
pub unsafe extern "C" fn dc_str_unref(s: *mut libc::c_char) {
|
||||||
libc::free(s as *mut _)
|
libc::free(s as *mut _)
|
||||||
@@ -4319,7 +4363,7 @@ pub unsafe extern "C" fn dc_backup_provider_wait(provider: *mut dc_backup_provid
|
|||||||
let ctx = &*ffi_provider.context;
|
let ctx = &*ffi_provider.context;
|
||||||
let provider = &mut ffi_provider.provider;
|
let provider = &mut ffi_provider.provider;
|
||||||
block_on(provider)
|
block_on(provider)
|
||||||
.context("Failed to await backup provider")
|
.context("Failed to await BackupProvider")
|
||||||
.log_err(ctx)
|
.log_err(ctx)
|
||||||
.set_last_error(ctx)
|
.set_last_error(ctx)
|
||||||
.ok();
|
.ok();
|
||||||
@@ -4373,7 +4417,7 @@ trait ResultExt<T, E> {
|
|||||||
/// Like `log_err()`, but:
|
/// Like `log_err()`, but:
|
||||||
/// - returns the default value instead of an Err value.
|
/// - returns the default value instead of an Err value.
|
||||||
/// - emits an error instead of a warning for an [Err] result. This means
|
/// - emits an error instead of a warning for an [Err] result. This means
|
||||||
/// that the error will be shown to the user in a small pop-up.
|
/// that the error will be shown to the user in a small pop-up.
|
||||||
fn unwrap_or_log_default(self, context: &context::Context, message: &str) -> T;
|
fn unwrap_or_log_default(self, context: &context::Context, message: &str) -> T;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4439,6 +4483,19 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait ResultNullableExt<T> {
|
||||||
|
fn into_raw(self) -> *mut T;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, E> ResultNullableExt<T> for Result<T, E> {
|
||||||
|
fn into_raw(self) -> *mut T {
|
||||||
|
match self {
|
||||||
|
Ok(t) => Box::into_raw(Box::new(t)),
|
||||||
|
Err(_) => ptr::null_mut(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn convert_and_prune_message_ids(msg_ids: *const u32, msg_cnt: libc::c_int) -> Vec<MsgId> {
|
fn convert_and_prune_message_ids(msg_ids: *const u32, msg_cnt: libc::c_int) -> Vec<MsgId> {
|
||||||
let ids = unsafe { std::slice::from_raw_parts(msg_ids, msg_cnt as usize) };
|
let ids = unsafe { std::slice::from_raw_parts(msg_ids, msg_cnt as usize) };
|
||||||
let msg_ids: Vec<MsgId> = ids
|
let msg_ids: Vec<MsgId> = ids
|
||||||
@@ -4492,16 +4549,19 @@ pub unsafe extern "C" fn dc_provider_new_from_email_with_dns(
|
|||||||
let addr = to_string_lossy(addr);
|
let addr = to_string_lossy(addr);
|
||||||
|
|
||||||
let ctx = &*context;
|
let ctx = &*context;
|
||||||
let proxy_enabled = block_on(ctx.get_config_bool(config::Config::ProxyEnabled))
|
let socks5_enabled = block_on(async move {
|
||||||
.context("Can't get config")
|
ctx.get_config_bool(config::Config::Socks5Enabled)
|
||||||
.log_err(ctx);
|
.await
|
||||||
|
.context("Can't get config")
|
||||||
|
.log_err(ctx)
|
||||||
|
});
|
||||||
|
|
||||||
match proxy_enabled {
|
match socks5_enabled {
|
||||||
Ok(proxy_enabled) => {
|
Ok(socks5_enabled) => {
|
||||||
match block_on(provider::get_provider_info_by_addr(
|
match block_on(provider::get_provider_info_by_addr(
|
||||||
ctx,
|
ctx,
|
||||||
addr.as_str(),
|
addr.as_str(),
|
||||||
proxy_enabled,
|
socks5_enabled,
|
||||||
))
|
))
|
||||||
.log_err(ctx)
|
.log_err(ctx)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
@@ -4915,9 +4975,7 @@ mod jsonrpc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let account_manager = &*account_manager;
|
let account_manager = &*account_manager;
|
||||||
let cmd_api = block_on(deltachat_jsonrpc::api::CommandApi::from_arc(
|
let cmd_api = deltachat_jsonrpc::api::CommandApi::from_arc(account_manager.inner.clone());
|
||||||
account_manager.inner.clone(),
|
|
||||||
));
|
|
||||||
|
|
||||||
let (request_handle, receiver) = RpcClient::new();
|
let (request_handle, receiver) = RpcClient::new();
|
||||||
let handle = RpcSession::new(request_handle, cmd_api);
|
let handle = RpcSession::new(request_handle, cmd_api);
|
||||||
|
|||||||
@@ -34,34 +34,33 @@ pub enum Meaning {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Lot {
|
impl Lot {
|
||||||
pub fn get_text1(&self) -> Option<Cow<str>> {
|
pub fn get_text1(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
Self::Summary(summary) => match &summary.prefix {
|
Self::Summary(summary) => match &summary.prefix {
|
||||||
None => None,
|
None => None,
|
||||||
Some(SummaryPrefix::Draft(text)) => Some(Cow::Borrowed(text)),
|
Some(SummaryPrefix::Draft(text)) => Some(text),
|
||||||
Some(SummaryPrefix::Username(username)) => Some(Cow::Borrowed(username)),
|
Some(SummaryPrefix::Username(username)) => Some(username),
|
||||||
Some(SummaryPrefix::Me(text)) => Some(Cow::Borrowed(text)),
|
Some(SummaryPrefix::Me(text)) => Some(text),
|
||||||
},
|
},
|
||||||
Self::Qr(qr) => match qr {
|
Self::Qr(qr) => match qr {
|
||||||
Qr::AskVerifyContact { .. } => None,
|
Qr::AskVerifyContact { .. } => None,
|
||||||
Qr::AskVerifyGroup { grpname, .. } => Some(Cow::Borrowed(grpname)),
|
Qr::AskVerifyGroup { grpname, .. } => Some(grpname),
|
||||||
Qr::FprOk { .. } => None,
|
Qr::FprOk { .. } => None,
|
||||||
Qr::FprMismatch { .. } => None,
|
Qr::FprMismatch { .. } => None,
|
||||||
Qr::FprWithoutAddr { fingerprint, .. } => Some(Cow::Borrowed(fingerprint)),
|
Qr::FprWithoutAddr { fingerprint, .. } => Some(fingerprint),
|
||||||
Qr::Account { domain } => Some(Cow::Borrowed(domain)),
|
Qr::Account { domain } => Some(domain),
|
||||||
Qr::Backup2 { .. } => None,
|
Qr::Backup { .. } => None,
|
||||||
Qr::WebrtcInstance { domain, .. } => Some(Cow::Borrowed(domain)),
|
Qr::WebrtcInstance { domain, .. } => Some(domain),
|
||||||
Qr::Proxy { host, port, .. } => Some(Cow::Owned(format!("{host}:{port}"))),
|
Qr::Addr { draft, .. } => draft.as_deref(),
|
||||||
Qr::Addr { draft, .. } => draft.as_deref().map(Cow::Borrowed),
|
Qr::Url { url } => Some(url),
|
||||||
Qr::Url { url } => Some(Cow::Borrowed(url)),
|
Qr::Text { text } => Some(text),
|
||||||
Qr::Text { text } => Some(Cow::Borrowed(text)),
|
|
||||||
Qr::WithdrawVerifyContact { .. } => None,
|
Qr::WithdrawVerifyContact { .. } => None,
|
||||||
Qr::WithdrawVerifyGroup { grpname, .. } => Some(Cow::Borrowed(grpname)),
|
Qr::WithdrawVerifyGroup { grpname, .. } => Some(grpname),
|
||||||
Qr::ReviveVerifyContact { .. } => None,
|
Qr::ReviveVerifyContact { .. } => None,
|
||||||
Qr::ReviveVerifyGroup { grpname, .. } => Some(Cow::Borrowed(grpname)),
|
Qr::ReviveVerifyGroup { grpname, .. } => Some(grpname),
|
||||||
Qr::Login { address, .. } => Some(Cow::Borrowed(address)),
|
Qr::Login { address, .. } => Some(address),
|
||||||
},
|
},
|
||||||
Self::Error(err) => Some(Cow::Borrowed(err)),
|
Self::Error(err) => Some(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,9 +101,8 @@ impl Lot {
|
|||||||
Qr::FprMismatch { .. } => LotState::QrFprMismatch,
|
Qr::FprMismatch { .. } => LotState::QrFprMismatch,
|
||||||
Qr::FprWithoutAddr { .. } => LotState::QrFprWithoutAddr,
|
Qr::FprWithoutAddr { .. } => LotState::QrFprWithoutAddr,
|
||||||
Qr::Account { .. } => LotState::QrAccount,
|
Qr::Account { .. } => LotState::QrAccount,
|
||||||
Qr::Backup2 { .. } => LotState::QrBackup2,
|
Qr::Backup { .. } => LotState::QrBackup,
|
||||||
Qr::WebrtcInstance { .. } => LotState::QrWebrtcInstance,
|
Qr::WebrtcInstance { .. } => LotState::QrWebrtcInstance,
|
||||||
Qr::Proxy { .. } => LotState::QrProxy,
|
|
||||||
Qr::Addr { .. } => LotState::QrAddr,
|
Qr::Addr { .. } => LotState::QrAddr,
|
||||||
Qr::Url { .. } => LotState::QrUrl,
|
Qr::Url { .. } => LotState::QrUrl,
|
||||||
Qr::Text { .. } => LotState::QrText,
|
Qr::Text { .. } => LotState::QrText,
|
||||||
@@ -128,9 +126,8 @@ impl Lot {
|
|||||||
Qr::FprMismatch { contact_id } => contact_id.unwrap_or_default().to_u32(),
|
Qr::FprMismatch { contact_id } => contact_id.unwrap_or_default().to_u32(),
|
||||||
Qr::FprWithoutAddr { .. } => Default::default(),
|
Qr::FprWithoutAddr { .. } => Default::default(),
|
||||||
Qr::Account { .. } => Default::default(),
|
Qr::Account { .. } => Default::default(),
|
||||||
Qr::Backup2 { .. } => Default::default(),
|
Qr::Backup { .. } => Default::default(),
|
||||||
Qr::WebrtcInstance { .. } => Default::default(),
|
Qr::WebrtcInstance { .. } => Default::default(),
|
||||||
Qr::Proxy { .. } => Default::default(),
|
|
||||||
Qr::Addr { contact_id, .. } => contact_id.to_u32(),
|
Qr::Addr { contact_id, .. } => contact_id.to_u32(),
|
||||||
Qr::Url { .. } => Default::default(),
|
Qr::Url { .. } => Default::default(),
|
||||||
Qr::Text { .. } => Default::default(),
|
Qr::Text { .. } => Default::default(),
|
||||||
@@ -180,14 +177,9 @@ pub enum LotState {
|
|||||||
|
|
||||||
QrBackup = 251,
|
QrBackup = 251,
|
||||||
|
|
||||||
QrBackup2 = 252,
|
|
||||||
|
|
||||||
/// text1=domain, text2=instance pattern
|
/// text1=domain, text2=instance pattern
|
||||||
QrWebrtcInstance = 260,
|
QrWebrtcInstance = 260,
|
||||||
|
|
||||||
/// text1=address, text2=protocol
|
|
||||||
QrProxy = 271,
|
|
||||||
|
|
||||||
/// id=contact
|
/// id=contact
|
||||||
QrAddr = 320,
|
QrAddr = 320,
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "deltachat-jsonrpc"
|
name = "deltachat-jsonrpc"
|
||||||
version = "1.147.0"
|
version = "1.137.2"
|
||||||
description = "DeltaChat JSON-RPC API"
|
description = "DeltaChat JSON-RPC API"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
default-run = "deltachat-jsonrpc-server"
|
default-run = "deltachat-jsonrpc-server"
|
||||||
@@ -13,30 +13,29 @@ path = "src/webserver.rs"
|
|||||||
required-features = ["webserver"]
|
required-features = ["webserver"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = "1"
|
||||||
deltachat = { workspace = true }
|
deltachat = { path = ".." }
|
||||||
deltachat-contact-tools = { workspace = true }
|
num-traits = "0.2"
|
||||||
num-traits = { workspace = true }
|
schemars = "0.8.13"
|
||||||
schemars = "0.8.21"
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde = { workspace = true, features = ["derive"] }
|
tempfile = "3.10.1"
|
||||||
tempfile = { workspace = true }
|
log = "0.4"
|
||||||
log = { workspace = true }
|
async-channel = { version = "2.0.0" }
|
||||||
async-channel = { workspace = true }
|
futures = { version = "0.3.30" }
|
||||||
futures = { workspace = true }
|
serde_json = "1"
|
||||||
serde_json = { workspace = true }
|
yerpc = { version = "0.5.2", features = ["anyhow_expose", "openrpc"] }
|
||||||
yerpc = { workspace = true, features = ["anyhow_expose", "openrpc"] }
|
typescript-type-def = { version = "0.5.8", features = ["json_value"] }
|
||||||
typescript-type-def = { version = "0.5.12", features = ["json_value"] }
|
tokio = { version = "1.37.0" }
|
||||||
tokio = { workspace = true }
|
sanitize-filename = "0.5"
|
||||||
sanitize-filename = { workspace = true }
|
|
||||||
walkdir = "2.5.0"
|
walkdir = "2.5.0"
|
||||||
base64 = { workspace = true }
|
base64 = "0.21"
|
||||||
|
|
||||||
# optional dependencies
|
# optional dependencies
|
||||||
axum = { version = "0.7", optional = true, features = ["ws"] }
|
axum = { version = "0.7", optional = true, features = ["ws"] }
|
||||||
env_logger = { version = "0.11.5", optional = true }
|
env_logger = { version = "0.10.0", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tokio = { workspace = true, features = ["full", "rt-multi-thread"] }
|
tokio = { version = "1.37.0", features = ["full", "rt-multi-thread"] }
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::path::Path;
|
|
||||||
use std::str;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Duration;
|
|
||||||
use std::{collections::HashMap, str::FromStr};
|
use std::{collections::HashMap, str::FromStr};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, ensure, Context, Result};
|
use anyhow::{anyhow, bail, ensure, Context, Result};
|
||||||
@@ -18,14 +15,12 @@ use deltachat::constants::DC_MSG_ID_DAYMARKER;
|
|||||||
use deltachat::contact::{may_be_valid_addr, Contact, ContactId, Origin};
|
use deltachat::contact::{may_be_valid_addr, Contact, ContactId, Origin};
|
||||||
use deltachat::context::get_info;
|
use deltachat::context::get_info;
|
||||||
use deltachat::ephemeral::Timer;
|
use deltachat::ephemeral::Timer;
|
||||||
|
use deltachat::imex;
|
||||||
use deltachat::location;
|
use deltachat::location;
|
||||||
use deltachat::message::get_msg_read_receipts;
|
use deltachat::message::get_msg_read_receipts;
|
||||||
use deltachat::message::{
|
use deltachat::message::{
|
||||||
self, delete_msgs, markseen_msgs, Message, MessageState, MsgId, Viewtype,
|
self, delete_msgs, markseen_msgs, Message, MessageState, MsgId, Viewtype,
|
||||||
};
|
};
|
||||||
use deltachat::peer_channels::{
|
|
||||||
leave_webxdc_realtime, send_webxdc_realtime_advertisement, send_webxdc_realtime_data,
|
|
||||||
};
|
|
||||||
use deltachat::provider::get_provider_info;
|
use deltachat::provider::get_provider_info;
|
||||||
use deltachat::qr::{self, Qr};
|
use deltachat::qr::{self, Qr};
|
||||||
use deltachat::qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg};
|
use deltachat::qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg};
|
||||||
@@ -33,8 +28,6 @@ use deltachat::reaction::{get_msg_reactions, send_reaction};
|
|||||||
use deltachat::securejoin;
|
use deltachat::securejoin;
|
||||||
use deltachat::stock_str::StockMessage;
|
use deltachat::stock_str::StockMessage;
|
||||||
use deltachat::webxdc::StatusUpdateSerial;
|
use deltachat::webxdc::StatusUpdateSerial;
|
||||||
use deltachat::EventEmitter;
|
|
||||||
use deltachat::{imex, info};
|
|
||||||
use sanitize_filename::is_sanitized;
|
use sanitize_filename::is_sanitized;
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::sync::{watch, Mutex, RwLock};
|
use tokio::sync::{watch, Mutex, RwLock};
|
||||||
@@ -46,7 +39,7 @@ pub mod types;
|
|||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use types::account::Account;
|
use types::account::Account;
|
||||||
use types::chat::FullChat;
|
use types::chat::FullChat;
|
||||||
use types::contact::{ContactObject, VcardContact};
|
use types::contact::ContactObject;
|
||||||
use types::events::Event;
|
use types::events::Event;
|
||||||
use types::http::HttpResponse;
|
use types::http::HttpResponse;
|
||||||
use types::message::{MessageData, MessageObject, MessageReadReceipt};
|
use types::message::{MessageData, MessageObject, MessageReadReceipt};
|
||||||
@@ -69,14 +62,14 @@ use crate::api::types::qr::QrObject;
|
|||||||
struct AccountState {
|
struct AccountState {
|
||||||
/// The Qr code for current [`CommandApi::provide_backup`] call.
|
/// The Qr code for current [`CommandApi::provide_backup`] call.
|
||||||
///
|
///
|
||||||
/// If there is currently is a call to [`CommandApi::provide_backup`] this will be
|
/// If there currently is a call to [`CommandApi::provide_backup`] this will be
|
||||||
/// `Some`, otherwise `None`.
|
/// `Pending` or `Ready`, otherwise `NoProvider`.
|
||||||
backup_provider_qr: watch::Sender<Option<Qr>>,
|
backup_provider_qr: watch::Sender<ProviderQr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for AccountState {
|
impl Default for AccountState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let tx = watch::Sender::new(None);
|
let (tx, _rx) = watch::channel(ProviderQr::NoProvider);
|
||||||
Self {
|
Self {
|
||||||
backup_provider_qr: tx,
|
backup_provider_qr: tx,
|
||||||
}
|
}
|
||||||
@@ -87,30 +80,21 @@ impl Default for AccountState {
|
|||||||
pub struct CommandApi {
|
pub struct CommandApi {
|
||||||
pub(crate) accounts: Arc<RwLock<Accounts>>,
|
pub(crate) accounts: Arc<RwLock<Accounts>>,
|
||||||
|
|
||||||
/// Receiver side of the event channel.
|
|
||||||
///
|
|
||||||
/// Events from it can be received by calling `get_next_event` method.
|
|
||||||
event_emitter: Arc<EventEmitter>,
|
|
||||||
|
|
||||||
states: Arc<Mutex<BTreeMap<u32, AccountState>>>,
|
states: Arc<Mutex<BTreeMap<u32, AccountState>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommandApi {
|
impl CommandApi {
|
||||||
pub fn new(accounts: Accounts) -> Self {
|
pub fn new(accounts: Accounts) -> Self {
|
||||||
let event_emitter = Arc::new(accounts.get_event_emitter());
|
|
||||||
CommandApi {
|
CommandApi {
|
||||||
accounts: Arc::new(RwLock::new(accounts)),
|
accounts: Arc::new(RwLock::new(accounts)),
|
||||||
event_emitter,
|
|
||||||
states: Arc::new(Mutex::new(BTreeMap::new())),
|
states: Arc::new(Mutex::new(BTreeMap::new())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub async fn from_arc(accounts: Arc<RwLock<Accounts>>) -> Self {
|
pub fn from_arc(accounts: Arc<RwLock<Accounts>>) -> Self {
|
||||||
let event_emitter = Arc::new(accounts.read().await.get_event_emitter());
|
|
||||||
CommandApi {
|
CommandApi {
|
||||||
accounts,
|
accounts,
|
||||||
event_emitter,
|
|
||||||
states: Arc::new(Mutex::new(BTreeMap::new())),
|
states: Arc::new(Mutex::new(BTreeMap::new())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,13 +123,21 @@ impl CommandApi {
|
|||||||
.with_state(account_id, |state| state.backup_provider_qr.subscribe())
|
.with_state(account_id, |state| state.backup_provider_qr.subscribe())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
loop {
|
let val: ProviderQr = receiver.borrow_and_update().clone();
|
||||||
if let Some(qr) = receiver.borrow_and_update().clone() {
|
match val {
|
||||||
return Ok(qr);
|
ProviderQr::NoProvider => bail!("No backup being provided"),
|
||||||
}
|
ProviderQr::Pending => loop {
|
||||||
if receiver.changed().await.is_err() {
|
if receiver.changed().await.is_err() {
|
||||||
bail!("No backup being provided (account state dropped)");
|
bail!("No backup being provided (account state dropped)");
|
||||||
}
|
}
|
||||||
|
let val: ProviderQr = receiver.borrow().clone();
|
||||||
|
match val {
|
||||||
|
ProviderQr::NoProvider => bail!("No backup being provided"),
|
||||||
|
ProviderQr::Pending => continue,
|
||||||
|
ProviderQr::Ready(qr) => break Ok(qr),
|
||||||
|
};
|
||||||
|
},
|
||||||
|
ProviderQr::Ready(qr) => Ok(qr),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,7 +165,8 @@ impl CommandApi {
|
|||||||
|
|
||||||
/// Get the next event.
|
/// Get the next event.
|
||||||
async fn get_next_event(&self) -> Result<Event> {
|
async fn get_next_event(&self) -> Result<Event> {
|
||||||
self.event_emitter
|
let event_emitter = self.accounts.read().await.get_event_emitter();
|
||||||
|
event_emitter
|
||||||
.recv()
|
.recv()
|
||||||
.await
|
.await
|
||||||
.map(|event| event.into())
|
.map(|event| event.into())
|
||||||
@@ -188,16 +181,6 @@ impl CommandApi {
|
|||||||
self.accounts.write().await.add_account().await
|
self.accounts.write().await.add_account().await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Imports/migrated an existing account from a database path into this account manager.
|
|
||||||
/// Returns the ID of new account.
|
|
||||||
async fn migrate_account(&self, path_to_db: String) -> Result<u32> {
|
|
||||||
self.accounts
|
|
||||||
.write()
|
|
||||||
.await
|
|
||||||
.migrate_account(std::path::PathBuf::from(path_to_db))
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn remove_account(&self, account_id: u32) -> Result<()> {
|
async fn remove_account(&self, account_id: u32) -> Result<()> {
|
||||||
self.accounts
|
self.accounts
|
||||||
.write()
|
.write()
|
||||||
@@ -321,12 +304,12 @@ impl CommandApi {
|
|||||||
) -> Result<Option<ProviderInfo>> {
|
) -> Result<Option<ProviderInfo>> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
|
|
||||||
let proxy_enabled = ctx
|
let socks5_enabled = ctx
|
||||||
.get_config_bool(deltachat::config::Config::ProxyEnabled)
|
.get_config_bool(deltachat::config::Config::Socks5Enabled)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let provider_info =
|
let provider_info =
|
||||||
get_provider_info(&ctx, email.split('@').last().unwrap_or(""), proxy_enabled).await;
|
get_provider_info(&ctx, email.split('@').last().unwrap_or(""), socks5_enabled).await;
|
||||||
Ok(ProviderInfo::from_dc_type(provider_info))
|
Ok(ProviderInfo::from_dc_type(provider_info))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,11 +325,6 @@ impl CommandApi {
|
|||||||
ctx.get_info().await
|
ctx.get_info().await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_blob_dir(&self, account_id: u32) -> Result<Option<String>> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
Ok(ctx.get_blobdir().to_str().map(|s| s.to_owned()))
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn draft_self_report(&self, account_id: u32) -> Result<u32> {
|
async fn draft_self_report(&self, account_id: u32) -> Result<u32> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
Ok(ctx.draft_self_report().await?.to_u32())
|
Ok(ctx.draft_self_report().await?.to_u32())
|
||||||
@@ -707,22 +685,7 @@ impl CommandApi {
|
|||||||
ChatId::new(chat_id).get_encryption_info(&ctx).await
|
ChatId::new(chat_id).get_encryption_info(&ctx).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get QR code text that will offer a [SecureJoin](https://securejoin.delta.chat/) invitation.
|
/// Get QR code (text and SVG) that will offer an Setup-Contact or Verified-Group invitation.
|
||||||
///
|
|
||||||
/// If `chat_id` is a group chat ID, SecureJoin QR code for the group is returned.
|
|
||||||
/// If `chat_id` is unset, setup contact QR code is returned.
|
|
||||||
async fn get_chat_securejoin_qr_code(
|
|
||||||
&self,
|
|
||||||
account_id: u32,
|
|
||||||
chat_id: Option<u32>,
|
|
||||||
) -> Result<String> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
let chat = chat_id.map(ChatId::new);
|
|
||||||
let qr = securejoin::get_securejoin_qr(&ctx, chat).await?;
|
|
||||||
Ok(qr)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get QR code (text and SVG) that will offer a Setup-Contact or Verified-Group invitation.
|
|
||||||
/// The QR code is compatible to the OPENPGP4FPR format
|
/// The QR code is compatible to the OPENPGP4FPR format
|
||||||
/// so that a basic fingerprint comparison also works e.g. with OpenKeychain.
|
/// so that a basic fingerprint comparison also works e.g. with OpenKeychain.
|
||||||
///
|
///
|
||||||
@@ -734,7 +697,8 @@ impl CommandApi {
|
|||||||
/// the Verified-Group-Invite protocol is offered in the QR code;
|
/// the Verified-Group-Invite protocol is offered in the QR code;
|
||||||
/// works for protected groups as well as for normal groups.
|
/// works for protected groups as well as for normal groups.
|
||||||
/// If not set, the Setup-Contact protocol is offered in the QR code.
|
/// If not set, the Setup-Contact protocol is offered in the QR code.
|
||||||
/// See https://securejoin.delta.chat/ for details about both protocols.
|
/// See https://securejoin.readthedocs.io/en/latest/new.html
|
||||||
|
/// for details about both protocols.
|
||||||
///
|
///
|
||||||
/// return format: `[code, svg]`
|
/// return format: `[code, svg]`
|
||||||
async fn get_chat_securejoin_qr_code_svg(
|
async fn get_chat_securejoin_qr_code_svg(
|
||||||
@@ -744,9 +708,10 @@ impl CommandApi {
|
|||||||
) -> Result<(String, String)> {
|
) -> Result<(String, String)> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
let chat = chat_id.map(ChatId::new);
|
let chat = chat_id.map(ChatId::new);
|
||||||
let qr = securejoin::get_securejoin_qr(&ctx, chat).await?;
|
Ok((
|
||||||
let svg = get_securejoin_qr_svg(&ctx, chat).await?;
|
securejoin::get_securejoin_qr(&ctx, chat).await?,
|
||||||
Ok((qr, svg))
|
get_securejoin_qr_svg(&ctx, chat).await?,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Continue a Setup-Contact or Verified-Group-Invite protocol
|
/// Continue a Setup-Contact or Verified-Group-Invite protocol
|
||||||
@@ -761,7 +726,8 @@ impl CommandApi {
|
|||||||
///
|
///
|
||||||
/// Subsequent calls of `secure_join()` will abort previous, unfinished handshakes.
|
/// Subsequent calls of `secure_join()` will abort previous, unfinished handshakes.
|
||||||
///
|
///
|
||||||
/// See https://securejoin.delta.chat/ for details about both protocols.
|
/// See https://securejoin.readthedocs.io/en/latest/new.html
|
||||||
|
/// for details about both protocols.
|
||||||
///
|
///
|
||||||
/// **qr**: The text of the scanned QR code. Typically, the same string as given
|
/// **qr**: The text of the scanned QR code. Typically, the same string as given
|
||||||
/// to `check_qr()`.
|
/// to `check_qr()`.
|
||||||
@@ -1459,51 +1425,6 @@ impl CommandApi {
|
|||||||
Ok(contact_id.map(|id| id.to_u32()))
|
Ok(contact_id.map(|id| id.to_u32()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses a vCard file located at the given path. Returns contacts in their original order.
|
|
||||||
async fn parse_vcard(&self, path: String) -> Result<Vec<VcardContact>> {
|
|
||||||
let vcard = fs::read(Path::new(&path)).await?;
|
|
||||||
let vcard = str::from_utf8(&vcard)?;
|
|
||||||
Ok(deltachat_contact_tools::parse_vcard(vcard)
|
|
||||||
.into_iter()
|
|
||||||
.map(|c| c.into())
|
|
||||||
.collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Imports contacts from a vCard file located at the given path.
|
|
||||||
///
|
|
||||||
/// Returns the ids of created/modified contacts in the order they appear in the vCard.
|
|
||||||
async fn import_vcard(&self, account_id: u32, path: String) -> Result<Vec<u32>> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
let vcard = tokio::fs::read(Path::new(&path)).await?;
|
|
||||||
let vcard = str::from_utf8(&vcard)?;
|
|
||||||
Ok(deltachat::contact::import_vcard(&ctx, vcard)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(|c| c.to_u32())
|
|
||||||
.collect())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns a vCard containing contacts with the given ids.
|
|
||||||
async fn make_vcard(&self, account_id: u32, contacts: Vec<u32>) -> Result<String> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
let contacts: Vec<_> = contacts.iter().map(|&c| ContactId::new(c)).collect();
|
|
||||||
deltachat::contact::make_vcard(&ctx, &contacts).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets vCard containing the given contacts to the message draft.
|
|
||||||
async fn set_draft_vcard(
|
|
||||||
&self,
|
|
||||||
account_id: u32,
|
|
||||||
msg_id: u32,
|
|
||||||
contacts: Vec<u32>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
let contacts: Vec<_> = contacts.iter().map(|&c| ContactId::new(c)).collect();
|
|
||||||
let mut msg = Message::load_from_db(&ctx, MsgId::new(msg_id)).await?;
|
|
||||||
msg.make_vcard(&ctx, &contacts).await?;
|
|
||||||
msg.get_chat_id().set_draft(&ctx, Some(&mut msg)).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
// chat
|
// chat
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
@@ -1552,6 +1473,55 @@ impl CommandApi {
|
|||||||
Ok(media.iter().map(|msg_id| msg_id.to_u32()).collect())
|
Ok(media.iter().map(|msg_id| msg_id.to_u32()).collect())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Search next/previous message based on a given message and a list of types.
|
||||||
|
/// Typically used to implement the "next" and "previous" buttons
|
||||||
|
/// in a gallery or in a media player.
|
||||||
|
///
|
||||||
|
/// one combined call for getting chat::get_next_media for both directions
|
||||||
|
/// the manual chat::get_next_media in only one direction is not exposed by the jsonrpc yet
|
||||||
|
///
|
||||||
|
/// Deprecated 2023-10-03, use `get_chat_media` method
|
||||||
|
/// and navigate the returned array instead.
|
||||||
|
#[allow(deprecated)]
|
||||||
|
async fn get_neighboring_chat_media(
|
||||||
|
&self,
|
||||||
|
account_id: u32,
|
||||||
|
msg_id: u32,
|
||||||
|
message_type: MessageViewtype,
|
||||||
|
or_message_type2: Option<MessageViewtype>,
|
||||||
|
or_message_type3: Option<MessageViewtype>,
|
||||||
|
) -> Result<(Option<u32>, Option<u32>)> {
|
||||||
|
let ctx = self.get_context(account_id).await?;
|
||||||
|
|
||||||
|
let msg_type: Viewtype = message_type.into();
|
||||||
|
let msg_type2: Viewtype = or_message_type2.map(|v| v.into()).unwrap_or_default();
|
||||||
|
let msg_type3: Viewtype = or_message_type3.map(|v| v.into()).unwrap_or_default();
|
||||||
|
|
||||||
|
let prev = chat::get_next_media(
|
||||||
|
&ctx,
|
||||||
|
MsgId::new(msg_id),
|
||||||
|
chat::Direction::Backward,
|
||||||
|
msg_type,
|
||||||
|
msg_type2,
|
||||||
|
msg_type3,
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
.map(|id| id.to_u32());
|
||||||
|
|
||||||
|
let next = chat::get_next_media(
|
||||||
|
&ctx,
|
||||||
|
MsgId::new(msg_id),
|
||||||
|
chat::Direction::Forward,
|
||||||
|
msg_type,
|
||||||
|
msg_type2,
|
||||||
|
msg_type3,
|
||||||
|
)
|
||||||
|
.await?
|
||||||
|
.map(|id| id.to_u32());
|
||||||
|
|
||||||
|
Ok((prev, next))
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
// backup
|
// backup
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
@@ -1599,21 +1569,20 @@ impl CommandApi {
|
|||||||
/// Returns once a remote device has retrieved the backup, or is cancelled.
|
/// Returns once a remote device has retrieved the backup, or is cancelled.
|
||||||
async fn provide_backup(&self, account_id: u32) -> Result<()> {
|
async fn provide_backup(&self, account_id: u32) -> Result<()> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
|
self.with_state(account_id, |state| {
|
||||||
|
state.backup_provider_qr.send_replace(ProviderQr::Pending);
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
|
||||||
let provider = imex::BackupProvider::prepare(&ctx).await?;
|
let provider = imex::BackupProvider::prepare(&ctx).await?;
|
||||||
self.with_state(account_id, |state| {
|
self.with_state(account_id, |state| {
|
||||||
state.backup_provider_qr.send_replace(Some(provider.qr()));
|
state
|
||||||
|
.backup_provider_qr
|
||||||
|
.send_replace(ProviderQr::Ready(provider.qr()));
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let res = provider.await;
|
provider.await
|
||||||
|
|
||||||
self.with_state(account_id, |state| {
|
|
||||||
state.backup_provider_qr.send_replace(None);
|
|
||||||
})
|
|
||||||
.await;
|
|
||||||
|
|
||||||
res
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the text of the QR code for the running [`CommandApi::provide_backup`].
|
/// Returns the text of the QR code for the running [`CommandApi::provide_backup`].
|
||||||
@@ -1621,17 +1590,11 @@ impl CommandApi {
|
|||||||
/// This QR code text can be used in [`CommandApi::get_backup`] on a second device to
|
/// This QR code text can be used in [`CommandApi::get_backup`] on a second device to
|
||||||
/// retrieve the backup and setup this second device.
|
/// retrieve the backup and setup this second device.
|
||||||
///
|
///
|
||||||
/// This call will block until the QR code is ready,
|
/// This call will fail if there is currently no concurrent call to
|
||||||
/// even if there is no concurrent call to [`CommandApi::provide_backup`],
|
/// [`CommandApi::provide_backup`]. This call may block if the QR code is not yet
|
||||||
/// but will fail after 60 seconds to avoid deadlocks.
|
/// ready.
|
||||||
async fn get_backup_qr(&self, account_id: u32) -> Result<String> {
|
async fn get_backup_qr(&self, account_id: u32) -> Result<String> {
|
||||||
let qr = tokio::time::timeout(
|
let qr = self.inner_get_backup_qr(account_id).await?;
|
||||||
Duration::from_secs(60),
|
|
||||||
self.inner_get_backup_qr(account_id),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.context("Backup provider did not start in time")?
|
|
||||||
.context("Failed to get backup QR code")?;
|
|
||||||
qr::format_backup(&qr)
|
qr::format_backup(&qr)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1640,20 +1603,14 @@ impl CommandApi {
|
|||||||
/// This QR code can be used in [`CommandApi::get_backup`] on a second device to
|
/// This QR code can be used in [`CommandApi::get_backup`] on a second device to
|
||||||
/// retrieve the backup and setup this second device.
|
/// retrieve the backup and setup this second device.
|
||||||
///
|
///
|
||||||
/// This call will block until the QR code is ready,
|
/// This call will fail if there is currently no concurrent call to
|
||||||
/// even if there is no concurrent call to [`CommandApi::provide_backup`],
|
/// [`CommandApi::provide_backup`]. This call may block if the QR code is not yet
|
||||||
/// but will fail after 60 seconds to avoid deadlocks.
|
/// ready.
|
||||||
///
|
///
|
||||||
/// Returns the QR code rendered as an SVG image.
|
/// Returns the QR code rendered as an SVG image.
|
||||||
async fn get_backup_qr_svg(&self, account_id: u32) -> Result<String> {
|
async fn get_backup_qr_svg(&self, account_id: u32) -> Result<String> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
let qr = tokio::time::timeout(
|
let qr = self.inner_get_backup_qr(account_id).await?;
|
||||||
Duration::from_secs(60),
|
|
||||||
self.inner_get_backup_qr(account_id),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.context("Backup provider did not start in time")?
|
|
||||||
.context("Failed to get backup QR code")?;
|
|
||||||
generate_backup_qr(&ctx, &qr).await
|
generate_backup_qr(&ctx, &qr).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1663,9 +1620,6 @@ impl CommandApi {
|
|||||||
/// the current device.
|
/// the current device.
|
||||||
///
|
///
|
||||||
/// Can be cancelled by stopping the ongoing process.
|
/// Can be cancelled by stopping the ongoing process.
|
||||||
///
|
|
||||||
/// Do not forget to call start_io on the account after a successful import,
|
|
||||||
/// otherwise it will not connect to the email server.
|
|
||||||
async fn get_backup(&self, account_id: u32, qr_text: String) -> Result<()> {
|
async fn get_backup(&self, account_id: u32, qr_text: String) -> Result<()> {
|
||||||
let ctx = self.get_context(account_id).await?;
|
let ctx = self.get_context(account_id).await?;
|
||||||
let qr = qr::check_qr(&ctx, &qr_text).await?;
|
let qr = qr::check_qr(&ctx, &qr_text).await?;
|
||||||
@@ -1759,37 +1713,6 @@ impl CommandApi {
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn send_webxdc_realtime_data(
|
|
||||||
&self,
|
|
||||||
account_id: u32,
|
|
||||||
instance_msg_id: u32,
|
|
||||||
data: Vec<u8>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
send_webxdc_realtime_data(&ctx, MsgId::new(instance_msg_id), data).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn send_webxdc_realtime_advertisement(
|
|
||||||
&self,
|
|
||||||
account_id: u32,
|
|
||||||
instance_msg_id: u32,
|
|
||||||
) -> Result<()> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
let fut = send_webxdc_realtime_advertisement(&ctx, MsgId::new(instance_msg_id)).await?;
|
|
||||||
if let Some(fut) = fut {
|
|
||||||
tokio::spawn(async move {
|
|
||||||
fut.await.ok();
|
|
||||||
info!(ctx, "send_webxdc_realtime_advertisement done")
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn leave_webxdc_realtime(&self, account_id: u32, instance_message_id: u32) -> Result<()> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
leave_webxdc_realtime(&ctx, MsgId::new(instance_message_id)).await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_webxdc_status_updates(
|
async fn get_webxdc_status_updates(
|
||||||
&self,
|
&self,
|
||||||
account_id: u32,
|
account_id: u32,
|
||||||
@@ -1831,29 +1754,6 @@ impl CommandApi {
|
|||||||
Ok(general_purpose::STANDARD_NO_PAD.encode(blob))
|
Ok(general_purpose::STANDARD_NO_PAD.encode(blob))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sets Webxdc file as integration.
|
|
||||||
/// `file` is the .xdc to use as Webxdc integration.
|
|
||||||
async fn set_webxdc_integration(&self, account_id: u32, file_path: String) -> Result<()> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
ctx.set_webxdc_integration(&file_path).await
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns Webxdc instance used for optional integrations.
|
|
||||||
/// UI can open the Webxdc as usual.
|
|
||||||
/// Returns `None` if there is no integration; the caller can add one using `set_webxdc_integration` then.
|
|
||||||
/// `integrate_for` is the chat to get the integration for.
|
|
||||||
async fn init_webxdc_integration(
|
|
||||||
&self,
|
|
||||||
account_id: u32,
|
|
||||||
chat_id: Option<u32>,
|
|
||||||
) -> Result<Option<u32>> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
Ok(ctx
|
|
||||||
.init_webxdc_integration(chat_id.map(ChatId::new))
|
|
||||||
.await?
|
|
||||||
.map(|msg_id| msg_id.to_u32()))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Makes an HTTP GET request and returns a response.
|
/// Makes an HTTP GET request and returns a response.
|
||||||
///
|
///
|
||||||
/// `url` is the HTTP or HTTPS URL.
|
/// `url` is the HTTP or HTTPS URL.
|
||||||
@@ -1962,15 +1862,6 @@ impl CommandApi {
|
|||||||
Ok(can_send)
|
Ok(can_send)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Saves a file copy at the user-provided path.
|
|
||||||
///
|
|
||||||
/// Fails if file already exists at the provided path.
|
|
||||||
async fn save_msg_file(&self, account_id: u32, msg_id: u32, path: String) -> Result<()> {
|
|
||||||
let ctx = self.get_context(account_id).await?;
|
|
||||||
let message = Message::load_from_db(&ctx, MsgId::new(msg_id)).await?;
|
|
||||||
message.save_file(&ctx, Path::new(&path)).await
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
// functions for the composer
|
// functions for the composer
|
||||||
// the composer is the message input field
|
// the composer is the message input field
|
||||||
@@ -2043,21 +1934,19 @@ impl CommandApi {
|
|||||||
);
|
);
|
||||||
let destination_path = account_folder.join("stickers").join(collection);
|
let destination_path = account_folder.join("stickers").join(collection);
|
||||||
fs::create_dir_all(&destination_path).await?;
|
fs::create_dir_all(&destination_path).await?;
|
||||||
let file = message.get_filename().context("no file?")?;
|
let file = message.get_file(&ctx).context("no file")?;
|
||||||
message
|
fs::copy(
|
||||||
.save_file(
|
&file,
|
||||||
&ctx,
|
destination_path.join(format!(
|
||||||
&destination_path.join(format!(
|
"{}.{}",
|
||||||
"{}.{}",
|
msg_id,
|
||||||
msg_id,
|
file.extension()
|
||||||
Path::new(&file)
|
.unwrap_or_default()
|
||||||
.extension()
|
.to_str()
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_str()
|
)),
|
||||||
.unwrap_or_default()
|
)
|
||||||
)),
|
.await?;
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2252,3 +2141,15 @@ async fn get_config(
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether a QR code for a BackupProvider is currently available.
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
enum ProviderQr {
|
||||||
|
/// There is no provider, asking for a QR is an error.
|
||||||
|
NoProvider,
|
||||||
|
/// There is a provider, the QR code is pending.
|
||||||
|
Pending,
|
||||||
|
/// There is a provider and QR code.
|
||||||
|
Ready(Qr),
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ pub struct FullChat {
|
|||||||
is_protected: bool,
|
is_protected: bool,
|
||||||
profile_image: Option<String>, //BLOBS ?
|
profile_image: Option<String>, //BLOBS ?
|
||||||
archived: bool,
|
archived: bool,
|
||||||
pinned: bool,
|
|
||||||
// subtitle - will be moved to frontend because it uses translation functions
|
// subtitle - will be moved to frontend because it uses translation functions
|
||||||
chat_type: u32,
|
chat_type: u32,
|
||||||
is_unpromoted: bool,
|
is_unpromoted: bool,
|
||||||
@@ -105,7 +104,6 @@ impl FullChat {
|
|||||||
is_protected: chat.is_protected(),
|
is_protected: chat.is_protected(),
|
||||||
profile_image, //BLOBS ?
|
profile_image, //BLOBS ?
|
||||||
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
||||||
pinned: chat.get_visibility() == chat::ChatVisibility::Pinned,
|
|
||||||
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
|
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
|
||||||
is_unpromoted: chat.is_unpromoted(),
|
is_unpromoted: chat.is_unpromoted(),
|
||||||
is_self_talk: chat.is_self_talk(),
|
is_self_talk: chat.is_self_talk(),
|
||||||
@@ -155,7 +153,6 @@ pub struct BasicChat {
|
|||||||
is_protected: bool,
|
is_protected: bool,
|
||||||
profile_image: Option<String>, //BLOBS ?
|
profile_image: Option<String>, //BLOBS ?
|
||||||
archived: bool,
|
archived: bool,
|
||||||
pinned: bool,
|
|
||||||
chat_type: u32,
|
chat_type: u32,
|
||||||
is_unpromoted: bool,
|
is_unpromoted: bool,
|
||||||
is_self_talk: bool,
|
is_self_talk: bool,
|
||||||
@@ -183,7 +180,6 @@ impl BasicChat {
|
|||||||
is_protected: chat.is_protected(),
|
is_protected: chat.is_protected(),
|
||||||
profile_image, //BLOBS ?
|
profile_image, //BLOBS ?
|
||||||
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
archived: chat.get_visibility() == chat::ChatVisibility::Archived,
|
||||||
pinned: chat.get_visibility() == chat::ChatVisibility::Pinned,
|
|
||||||
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
|
chat_type: chat.get_type().to_u32().context("unknown chat type id")?,
|
||||||
is_unpromoted: chat.is_unpromoted(),
|
is_unpromoted: chat.is_unpromoted(),
|
||||||
is_self_talk: chat.is_self_talk(),
|
is_self_talk: chat.is_self_talk(),
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use deltachat::color;
|
|
||||||
use deltachat::context::Context;
|
use deltachat::context::Context;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use typescript_type_def::TypeDef;
|
use typescript_type_def::TypeDef;
|
||||||
@@ -19,7 +18,6 @@ pub struct ContactObject {
|
|||||||
profile_image: Option<String>, // BLOBS
|
profile_image: Option<String>, // BLOBS
|
||||||
name_and_addr: String,
|
name_and_addr: String,
|
||||||
is_blocked: bool,
|
is_blocked: bool,
|
||||||
e2ee_avail: bool,
|
|
||||||
|
|
||||||
/// True if the contact can be added to verified groups.
|
/// True if the contact can be added to verified groups.
|
||||||
///
|
///
|
||||||
@@ -80,7 +78,6 @@ impl ContactObject {
|
|||||||
profile_image, //BLOBS
|
profile_image, //BLOBS
|
||||||
name_and_addr: contact.get_name_n_addr(),
|
name_and_addr: contact.get_name_n_addr(),
|
||||||
is_blocked: contact.is_blocked(),
|
is_blocked: contact.is_blocked(),
|
||||||
e2ee_avail: contact.e2ee_avail(context).await?,
|
|
||||||
is_verified,
|
is_verified,
|
||||||
is_profile_verified,
|
is_profile_verified,
|
||||||
verifier_id,
|
verifier_id,
|
||||||
@@ -90,35 +87,3 @@ impl ContactObject {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize, TypeDef, schemars::JsonSchema)]
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
pub struct VcardContact {
|
|
||||||
/// Email address.
|
|
||||||
addr: String,
|
|
||||||
/// The contact's name, or the email address if no name was given.
|
|
||||||
display_name: String,
|
|
||||||
/// Public PGP key in Base64.
|
|
||||||
key: Option<String>,
|
|
||||||
/// Profile image in Base64.
|
|
||||||
profile_image: Option<String>,
|
|
||||||
/// Contact color as hex string.
|
|
||||||
color: String,
|
|
||||||
/// Last update timestamp.
|
|
||||||
timestamp: Option<i64>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<deltachat_contact_tools::VcardContact> for VcardContact {
|
|
||||||
fn from(vc: deltachat_contact_tools::VcardContact) -> Self {
|
|
||||||
let display_name = vc.display_name().to_string();
|
|
||||||
let color = color::str_to_color(&vc.addr.to_lowercase());
|
|
||||||
Self {
|
|
||||||
addr: vc.addr,
|
|
||||||
display_name,
|
|
||||||
key: vc.key,
|
|
||||||
profile_image: vc.profile_image,
|
|
||||||
color: color_int_to_hex_string(color),
|
|
||||||
timestamp: vc.timestamp.ok(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -240,10 +240,6 @@ pub enum EventType {
|
|||||||
status_update_serial: u32,
|
status_update_serial: u32,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Data received over an ephemeral peer channel.
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
WebxdcRealtimeData { msg_id: u32, data: Vec<u8> },
|
|
||||||
|
|
||||||
/// Inform that a message containing a webxdc instance has been deleted
|
/// Inform that a message containing a webxdc instance has been deleted
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
WebxdcInstanceDeleted { msg_id: u32 },
|
WebxdcInstanceDeleted { msg_id: u32 },
|
||||||
@@ -254,18 +250,6 @@ pub enum EventType {
|
|||||||
///
|
///
|
||||||
/// This event is only emitted by the account manager
|
/// This event is only emitted by the account manager
|
||||||
AccountsBackgroundFetchDone,
|
AccountsBackgroundFetchDone,
|
||||||
/// Inform that set of chats or the order of the chats in the chatlist has changed.
|
|
||||||
///
|
|
||||||
/// Sometimes this is emitted together with `UIChatlistItemChanged`.
|
|
||||||
ChatlistChanged,
|
|
||||||
|
|
||||||
/// Inform that a single chat list item changed and needs to be rerendered.
|
|
||||||
/// If `chat_id` is set to None, then all currently visible chats need to be rerendered, and all not-visible items need to be cleared from cache if the UI has a cache.
|
|
||||||
#[serde(rename_all = "camelCase")]
|
|
||||||
ChatlistItemChanged { chat_id: Option<u32> },
|
|
||||||
|
|
||||||
/// Inform than some events have been skipped due to event channel overflow.
|
|
||||||
EventChannelOverflow { n: u64 },
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<CoreEventType> for EventType {
|
impl From<CoreEventType> for EventType {
|
||||||
@@ -369,19 +353,10 @@ impl From<CoreEventType> for EventType {
|
|||||||
msg_id: msg_id.to_u32(),
|
msg_id: msg_id.to_u32(),
|
||||||
status_update_serial: status_update_serial.to_u32(),
|
status_update_serial: status_update_serial.to_u32(),
|
||||||
},
|
},
|
||||||
CoreEventType::WebxdcRealtimeData { msg_id, data } => WebxdcRealtimeData {
|
|
||||||
msg_id: msg_id.to_u32(),
|
|
||||||
data,
|
|
||||||
},
|
|
||||||
CoreEventType::WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
|
CoreEventType::WebxdcInstanceDeleted { msg_id } => WebxdcInstanceDeleted {
|
||||||
msg_id: msg_id.to_u32(),
|
msg_id: msg_id.to_u32(),
|
||||||
},
|
},
|
||||||
CoreEventType::AccountsBackgroundFetchDone => AccountsBackgroundFetchDone,
|
CoreEventType::AccountsBackgroundFetchDone => AccountsBackgroundFetchDone,
|
||||||
CoreEventType::ChatlistItemChanged { chat_id } => ChatlistItemChanged {
|
|
||||||
chat_id: chat_id.map(|id| id.to_u32()),
|
|
||||||
},
|
|
||||||
CoreEventType::ChatlistChanged => ChatlistChanged,
|
|
||||||
CoreEventType::EventChannelOverflow { n } => EventChannelOverflow { n },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
use crate::api::VcardContact;
|
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use deltachat::chat::Chat;
|
use deltachat::chat::Chat;
|
||||||
use deltachat::chat::ChatItem;
|
use deltachat::chat::ChatItem;
|
||||||
@@ -36,10 +35,6 @@ pub struct MessageObject {
|
|||||||
parent_id: Option<u32>,
|
parent_id: Option<u32>,
|
||||||
|
|
||||||
text: String,
|
text: String,
|
||||||
|
|
||||||
/// Check if a message has a POI location bound to it.
|
|
||||||
/// These locations are also returned by `get_locations` method.
|
|
||||||
/// The UI may decide to display a special icon beside such messages.
|
|
||||||
has_location: bool,
|
has_location: bool,
|
||||||
has_html: bool,
|
has_html: bool,
|
||||||
view_type: MessageViewtype,
|
view_type: MessageViewtype,
|
||||||
@@ -88,8 +83,6 @@ pub struct MessageObject {
|
|||||||
download_state: DownloadState,
|
download_state: DownloadState,
|
||||||
|
|
||||||
reactions: Option<JSONRPCReactions>,
|
reactions: Option<JSONRPCReactions>,
|
||||||
|
|
||||||
vcard_contact: Option<VcardContact>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
|
#[derive(Serialize, TypeDef, schemars::JsonSchema)]
|
||||||
@@ -176,13 +169,6 @@ impl MessageObject {
|
|||||||
Some(reactions.into())
|
Some(reactions.into())
|
||||||
};
|
};
|
||||||
|
|
||||||
let vcard_contacts: Vec<VcardContact> = message
|
|
||||||
.vcard_contacts(context)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.map(Into::into)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(MessageObject {
|
Ok(MessageObject {
|
||||||
id: msg_id.to_u32(),
|
id: msg_id.to_u32(),
|
||||||
chat_id: message.get_chat_id().to_u32(),
|
chat_id: message.get_chat_id().to_u32(),
|
||||||
@@ -242,8 +228,6 @@ impl MessageObject {
|
|||||||
download_state,
|
download_state,
|
||||||
|
|
||||||
reactions,
|
reactions,
|
||||||
|
|
||||||
vcard_contact: vcard_contacts.first().cloned(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -286,11 +270,6 @@ pub enum MessageViewtype {
|
|||||||
|
|
||||||
/// Message is an webxdc instance.
|
/// Message is an webxdc instance.
|
||||||
Webxdc,
|
Webxdc,
|
||||||
|
|
||||||
/// Message containing shared contacts represented as a vCard (virtual contact file)
|
|
||||||
/// with email addresses and possibly other fields.
|
|
||||||
/// Use `parse_vcard()` to retrieve them.
|
|
||||||
Vcard,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Viewtype> for MessageViewtype {
|
impl From<Viewtype> for MessageViewtype {
|
||||||
@@ -307,7 +286,6 @@ impl From<Viewtype> for MessageViewtype {
|
|||||||
Viewtype::File => MessageViewtype::File,
|
Viewtype::File => MessageViewtype::File,
|
||||||
Viewtype::VideochatInvitation => MessageViewtype::VideochatInvitation,
|
Viewtype::VideochatInvitation => MessageViewtype::VideochatInvitation,
|
||||||
Viewtype::Webxdc => MessageViewtype::Webxdc,
|
Viewtype::Webxdc => MessageViewtype::Webxdc,
|
||||||
Viewtype::Vcard => MessageViewtype::Vcard,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,7 +304,6 @@ impl From<MessageViewtype> for Viewtype {
|
|||||||
MessageViewtype::File => Viewtype::File,
|
MessageViewtype::File => Viewtype::File,
|
||||||
MessageViewtype::VideochatInvitation => Viewtype::VideochatInvitation,
|
MessageViewtype::VideochatInvitation => Viewtype::VideochatInvitation,
|
||||||
MessageViewtype::Webxdc => Viewtype::Webxdc,
|
MessageViewtype::Webxdc => Viewtype::Webxdc,
|
||||||
MessageViewtype::Vcard => Viewtype::Vcard,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -365,14 +342,6 @@ pub enum SystemMessageType {
|
|||||||
LocationOnly,
|
LocationOnly,
|
||||||
InvalidUnencryptedMail,
|
InvalidUnencryptedMail,
|
||||||
|
|
||||||
/// 1:1 chats info message telling that SecureJoin has started and the user should wait for it
|
|
||||||
/// to complete.
|
|
||||||
SecurejoinWait,
|
|
||||||
|
|
||||||
/// 1:1 chats info message telling that SecureJoin is still running, but the user may already
|
|
||||||
/// send messages.
|
|
||||||
SecurejoinWaitTimeout,
|
|
||||||
|
|
||||||
/// Chat ephemeral message timer is changed.
|
/// Chat ephemeral message timer is changed.
|
||||||
EphemeralTimerChanged,
|
EphemeralTimerChanged,
|
||||||
|
|
||||||
@@ -391,9 +360,6 @@ pub enum SystemMessageType {
|
|||||||
|
|
||||||
/// Webxdc info added with `info` set in `send_webxdc_status_update()`.
|
/// Webxdc info added with `info` set in `send_webxdc_status_update()`.
|
||||||
WebxdcInfoMessage,
|
WebxdcInfoMessage,
|
||||||
|
|
||||||
/// This message contains a users iroh node address.
|
|
||||||
IrohNodeAddr,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<deltachat::mimeparser::SystemMessage> for SystemMessageType {
|
impl From<deltachat::mimeparser::SystemMessage> for SystemMessageType {
|
||||||
@@ -416,9 +382,6 @@ impl From<deltachat::mimeparser::SystemMessage> for SystemMessageType {
|
|||||||
SystemMessage::WebxdcStatusUpdate => SystemMessageType::WebxdcStatusUpdate,
|
SystemMessage::WebxdcStatusUpdate => SystemMessageType::WebxdcStatusUpdate,
|
||||||
SystemMessage::WebxdcInfoMessage => SystemMessageType::WebxdcInfoMessage,
|
SystemMessage::WebxdcInfoMessage => SystemMessageType::WebxdcInfoMessage,
|
||||||
SystemMessage::InvalidUnencryptedMail => SystemMessageType::InvalidUnencryptedMail,
|
SystemMessage::InvalidUnencryptedMail => SystemMessageType::InvalidUnencryptedMail,
|
||||||
SystemMessage::IrohNodeAddr => SystemMessageType::IrohNodeAddr,
|
|
||||||
SystemMessage::SecurejoinWait => SystemMessageType::SecurejoinWait,
|
|
||||||
SystemMessage::SecurejoinWaitTimeout => SystemMessageType::SecurejoinWaitTimeout,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -577,9 +540,7 @@ pub struct MessageData {
|
|||||||
pub file: Option<String>,
|
pub file: Option<String>,
|
||||||
pub location: Option<(f64, f64)>,
|
pub location: Option<(f64, f64)>,
|
||||||
pub override_sender_name: Option<String>,
|
pub override_sender_name: Option<String>,
|
||||||
/// Quoted message id. Takes preference over `quoted_text` (see below).
|
|
||||||
pub quoted_message_id: Option<u32>,
|
pub quoted_message_id: Option<u32>,
|
||||||
pub quoted_text: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageData {
|
impl MessageData {
|
||||||
@@ -615,9 +576,6 @@ impl MessageData {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
} else if let Some(text) = self.quoted_text {
|
|
||||||
let protect = false;
|
|
||||||
message.set_quote_text(Some((text, protect)));
|
|
||||||
}
|
}
|
||||||
Ok(message)
|
Ok(message)
|
||||||
}
|
}
|
||||||
@@ -640,7 +598,7 @@ pub struct MessageInfo {
|
|||||||
error: Option<String>,
|
error: Option<String>,
|
||||||
rfc724_mid: String,
|
rfc724_mid: String,
|
||||||
server_urls: Vec<String>,
|
server_urls: Vec<String>,
|
||||||
hop_info: String,
|
hop_info: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MessageInfo {
|
impl MessageInfo {
|
||||||
@@ -673,7 +631,7 @@ impl MessageInfo {
|
|||||||
#[derive(
|
#[derive(
|
||||||
Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize, TypeDef, schemars::JsonSchema,
|
Debug, PartialEq, Eq, Copy, Clone, Serialize, Deserialize, TypeDef, schemars::JsonSchema,
|
||||||
)]
|
)]
|
||||||
#[serde(rename_all = "camelCase", tag = "kind")]
|
#[serde(rename_all = "camelCase", tag = "variant")]
|
||||||
pub enum EphemeralTimer {
|
pub enum EphemeralTimer {
|
||||||
/// Timer is disabled.
|
/// Timer is disabled.
|
||||||
Disabled,
|
Disabled,
|
||||||
|
|||||||
@@ -32,20 +32,13 @@ pub enum QrObject {
|
|||||||
Account {
|
Account {
|
||||||
domain: String,
|
domain: String,
|
||||||
},
|
},
|
||||||
Backup2 {
|
Backup {
|
||||||
auth_token: String,
|
ticket: String,
|
||||||
|
|
||||||
node_addr: String,
|
|
||||||
},
|
},
|
||||||
WebrtcInstance {
|
WebrtcInstance {
|
||||||
domain: String,
|
domain: String,
|
||||||
instance_pattern: String,
|
instance_pattern: String,
|
||||||
},
|
},
|
||||||
Proxy {
|
|
||||||
url: String,
|
|
||||||
host: String,
|
|
||||||
port: u16,
|
|
||||||
},
|
|
||||||
Addr {
|
Addr {
|
||||||
contact_id: u32,
|
contact_id: u32,
|
||||||
draft: Option<String>,
|
draft: Option<String>,
|
||||||
@@ -136,13 +129,8 @@ impl From<Qr> for QrObject {
|
|||||||
}
|
}
|
||||||
Qr::FprWithoutAddr { fingerprint } => QrObject::FprWithoutAddr { fingerprint },
|
Qr::FprWithoutAddr { fingerprint } => QrObject::FprWithoutAddr { fingerprint },
|
||||||
Qr::Account { domain } => QrObject::Account { domain },
|
Qr::Account { domain } => QrObject::Account { domain },
|
||||||
Qr::Backup2 {
|
Qr::Backup { ticket } => QrObject::Backup {
|
||||||
ref node_addr,
|
ticket: ticket.to_string(),
|
||||||
auth_token,
|
|
||||||
} => QrObject::Backup2 {
|
|
||||||
node_addr: serde_json::to_string(node_addr).unwrap_or_default(),
|
|
||||||
|
|
||||||
auth_token,
|
|
||||||
},
|
},
|
||||||
Qr::WebrtcInstance {
|
Qr::WebrtcInstance {
|
||||||
domain,
|
domain,
|
||||||
@@ -151,7 +139,6 @@ impl From<Qr> for QrObject {
|
|||||||
domain,
|
domain,
|
||||||
instance_pattern,
|
instance_pattern,
|
||||||
},
|
},
|
||||||
Qr::Proxy { url, host, port } => QrObject::Proxy { url, host, port },
|
|
||||||
Qr::Addr { contact_id, draft } => {
|
Qr::Addr { contact_id, draft } => {
|
||||||
let contact_id = contact_id.to_u32();
|
let contact_id = contact_id.to_u32();
|
||||||
QrObject::Addr { contact_id, draft }
|
QrObject::Addr { contact_id, draft }
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub use yerpc;
|
pub use yerpc;
|
||||||
|
|
||||||
@@ -83,7 +82,7 @@ mod tests {
|
|||||||
assert_eq!(result, response.to_owned());
|
assert_eq!(result, response.to_owned());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let request = r#"{"jsonrpc":"2.0","method":"batch_set_config","id":2,"params":[1,{"addr":"","mail_user":"","mail_pw":"","mail_server":"","mail_port":"","mail_security":"","imap_certificate_checks":"","send_user":"","send_pw":"","send_server":"","send_port":"","send_security":"","smtp_certificate_checks":""}]}"#;
|
let request = r#"{"jsonrpc":"2.0","method":"batch_set_config","id":2,"params":[1,{"addr":"","mail_user":"","mail_pw":"","mail_server":"","mail_port":"","mail_security":"","imap_certificate_checks":"","send_user":"","send_pw":"","send_server":"","send_port":"","send_security":"","smtp_certificate_checks":"","socks5_enabled":"0","socks5_host":"","socks5_port":"","socks5_user":"","socks5_password":""}]}"#;
|
||||||
let response = r#"{"jsonrpc":"2.0","id":2,"result":null}"#;
|
let response = r#"{"jsonrpc":"2.0","id":2,"result":null}"#;
|
||||||
session.handle_incoming(request).await;
|
session.handle_incoming(request).await;
|
||||||
let result = receiver.recv().await?;
|
let result = receiver.recv().await?;
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@deltachat/tiny-emitter": "3.0.0",
|
"@deltachat/tiny-emitter": "3.0.0",
|
||||||
"isomorphic-ws": "^4.0.1",
|
"isomorphic-ws": "^4.0.1",
|
||||||
"yerpc": "^0.6.2"
|
"yerpc": "^0.4.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^4.2.21",
|
"@types/chai": "^4.2.21",
|
||||||
@@ -25,17 +25,12 @@
|
|||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"import": "./dist/deltachat.js",
|
"import": "./dist/deltachat.js",
|
||||||
"require": "./dist/deltachat.cjs",
|
"require": "./dist/deltachat.cjs"
|
||||||
"types": "./dist/deltachat.d.ts"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"license": "MPL-2.0",
|
"license": "MPL-2.0",
|
||||||
"main": "dist/deltachat.js",
|
"main": "dist/deltachat.js",
|
||||||
"name": "@deltachat/jsonrpc-client",
|
"name": "@deltachat/jsonrpc-client",
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/deltachat/deltachat-core-rust.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "run-s generate-bindings extract-constants build:tsc build:bundle build:cjs",
|
"build": "run-s generate-bindings extract-constants build:tsc build:bundle build:cjs",
|
||||||
"build:bundle": "esbuild --format=esm --bundle dist/deltachat.js --outfile=dist/deltachat.bundle.js",
|
"build:bundle": "esbuild --format=esm --bundle dist/deltachat.js --outfile=dist/deltachat.bundle.js",
|
||||||
@@ -58,5 +53,5 @@
|
|||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"types": "dist/deltachat.d.ts",
|
"types": "dist/deltachat.d.ts",
|
||||||
"version": "1.147.0"
|
"version": "1.137.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,10 @@ describe("online tests", function () {
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
const chatId = await dc.rpc.createChatByContactId(accountId1, contactId);
|
const chatId = await dc.rpc.createChatByContactId(accountId1, contactId);
|
||||||
const eventPromise = waitForEvent(dc, "IncomingMsg", accountId2);
|
const eventPromise = Promise.race([
|
||||||
|
waitForEvent(dc, "MsgsChanged", accountId2),
|
||||||
|
waitForEvent(dc, "IncomingMsg", accountId2),
|
||||||
|
]);
|
||||||
|
|
||||||
await dc.rpc.miscSendTextMessage(accountId1, chatId, "Hello");
|
await dc.rpc.miscSendTextMessage(accountId1, chatId, "Hello");
|
||||||
const { chatId: chatIdOnAccountB } = await eventPromise;
|
const { chatId: chatIdOnAccountB } = await eventPromise;
|
||||||
@@ -116,7 +119,10 @@ describe("online tests", function () {
|
|||||||
null
|
null
|
||||||
);
|
);
|
||||||
const chatId = await dc.rpc.createChatByContactId(accountId1, contactId);
|
const chatId = await dc.rpc.createChatByContactId(accountId1, contactId);
|
||||||
const eventPromise = waitForEvent(dc, "IncomingMsg", accountId2);
|
const eventPromise = Promise.race([
|
||||||
|
waitForEvent(dc, "MsgsChanged", accountId2),
|
||||||
|
waitForEvent(dc, "IncomingMsg", accountId2),
|
||||||
|
]);
|
||||||
dc.rpc.miscSendTextMessage(accountId1, chatId, "Hello2");
|
dc.rpc.miscSendTextMessage(accountId1, chatId, "Hello2");
|
||||||
// wait for message from A
|
// wait for message from A
|
||||||
console.log("wait for message from A");
|
console.log("wait for message from A");
|
||||||
@@ -137,7 +143,10 @@ describe("online tests", function () {
|
|||||||
);
|
);
|
||||||
expect(message.text).equal("Hello2");
|
expect(message.text).equal("Hello2");
|
||||||
// Send message back from B to A
|
// Send message back from B to A
|
||||||
const eventPromise2 = waitForEvent(dc, "IncomingMsg", accountId1);
|
const eventPromise2 = Promise.race([
|
||||||
|
waitForEvent(dc, "MsgsChanged", accountId1),
|
||||||
|
waitForEvent(dc, "IncomingMsg", accountId1),
|
||||||
|
]);
|
||||||
dc.rpc.miscSendTextMessage(accountId2, chatId, "super secret message");
|
dc.rpc.miscSendTextMessage(accountId2, chatId, "super secret message");
|
||||||
// Check if answer arrives at A and if it is encrypted
|
// Check if answer arrives at A and if it is encrypted
|
||||||
await eventPromise2;
|
await eventPromise2;
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "deltachat-repl"
|
name = "deltachat-repl"
|
||||||
version = "1.147.0"
|
version = "1.137.2"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
repository = "https://github.com/deltachat/deltachat-core-rust"
|
repository = "https://github.com/deltachat/deltachat-core-rust"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
ansi_term = "0.12.1"
|
||||||
deltachat = { workspace = true, features = ["internals"]}
|
anyhow = "1"
|
||||||
|
deltachat = { path = "..", features = ["internals"]}
|
||||||
dirs = "5"
|
dirs = "5"
|
||||||
log = { workspace = true }
|
log = "0.4.21"
|
||||||
nu-ansi-term = { workspace = true }
|
pretty_env_logger = "0.5"
|
||||||
rusqlite = { workspace = true }
|
rusqlite = "0.31"
|
||||||
rustyline = "14"
|
rustyline = "14"
|
||||||
tokio = { workspace = true, features = ["fs", "rt-multi-thread", "macros"] }
|
tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] }
|
||||||
tracing-subscriber = { workspace = true, features = ["env-filter"] }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["vendored"]
|
default = ["vendored"]
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
#![allow(clippy::format_push_string)]
|
#![allow(clippy::format_push_string)]
|
||||||
extern crate dirs;
|
extern crate dirs;
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@@ -21,7 +19,6 @@ use deltachat::location;
|
|||||||
use deltachat::log::LogExt;
|
use deltachat::log::LogExt;
|
||||||
use deltachat::message::{self, Message, MessageState, MsgId, Viewtype};
|
use deltachat::message::{self, Message, MessageState, MsgId, Viewtype};
|
||||||
use deltachat::mimeparser::SystemMessage;
|
use deltachat::mimeparser::SystemMessage;
|
||||||
use deltachat::peer_channels::{send_webxdc_realtime_advertisement, send_webxdc_realtime_data};
|
|
||||||
use deltachat::peerstate::*;
|
use deltachat::peerstate::*;
|
||||||
use deltachat::qr::*;
|
use deltachat::qr::*;
|
||||||
use deltachat::reaction::send_reaction;
|
use deltachat::reaction::send_reaction;
|
||||||
@@ -341,6 +338,9 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
receive-backup <qr>\n\
|
receive-backup <qr>\n\
|
||||||
export-keys\n\
|
export-keys\n\
|
||||||
import-keys\n\
|
import-keys\n\
|
||||||
|
export-setup\n\
|
||||||
|
dump <filename>\n\n
|
||||||
|
read <filename>\n\n
|
||||||
poke [<eml-file>|<folder>|<addr> <key-file>]\n\
|
poke [<eml-file>|<folder>|<addr> <key-file>]\n\
|
||||||
reset <flags>\n\
|
reset <flags>\n\
|
||||||
stop\n\
|
stop\n\
|
||||||
@@ -357,7 +357,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
configure\n\
|
configure\n\
|
||||||
connect\n\
|
connect\n\
|
||||||
disconnect\n\
|
disconnect\n\
|
||||||
fetch\n\
|
|
||||||
connectivity\n\
|
connectivity\n\
|
||||||
maybenetwork\n\
|
maybenetwork\n\
|
||||||
housekeeping\n\
|
housekeeping\n\
|
||||||
@@ -489,14 +488,8 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
}
|
}
|
||||||
"send-backup" => {
|
"send-backup" => {
|
||||||
let provider = BackupProvider::prepare(&context).await?;
|
let provider = BackupProvider::prepare(&context).await?;
|
||||||
let qr = format_backup(&provider.qr())?;
|
let qr = provider.qr();
|
||||||
println!("QR code: {}", qr);
|
println!("QR code: {}", format_backup(&qr)?);
|
||||||
let output = Command::new("qrencode")
|
|
||||||
.args(["-t", "ansiutf8", qr.as_str(), "-o", "-"])
|
|
||||||
.output()
|
|
||||||
.expect("failed to execute process");
|
|
||||||
std::io::stdout().write_all(&output.stdout).unwrap();
|
|
||||||
std::io::stderr().write_all(&output.stderr).unwrap();
|
|
||||||
provider.await?;
|
provider.await?;
|
||||||
}
|
}
|
||||||
"receive-backup" => {
|
"receive-backup" => {
|
||||||
@@ -512,6 +505,25 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
"import-keys" => {
|
"import-keys" => {
|
||||||
imex(&context, ImexMode::ImportSelfKeys, arg1.as_ref(), None).await?;
|
imex(&context, ImexMode::ImportSelfKeys, arg1.as_ref(), None).await?;
|
||||||
}
|
}
|
||||||
|
"export-setup" => {
|
||||||
|
let setup_code = create_setup_code(&context);
|
||||||
|
let file_name = blobdir.join("autocrypt-setup-message.html");
|
||||||
|
let file_content = render_setup_file(&context, &setup_code).await?;
|
||||||
|
fs::write(&file_name, file_content).await?;
|
||||||
|
println!(
|
||||||
|
"Setup message written to: {}\nSetup code: {}",
|
||||||
|
file_name.display(),
|
||||||
|
&setup_code,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
"dump" => {
|
||||||
|
ensure!(!arg1.is_empty(), "Argument <filename> missing.");
|
||||||
|
serialize_database(&context, arg1).await?;
|
||||||
|
}
|
||||||
|
"read" => {
|
||||||
|
ensure!(!arg1.is_empty(), "Argument <filename> missing.");
|
||||||
|
deserialize_database(&context, arg1).await?;
|
||||||
|
}
|
||||||
"poke" => {
|
"poke" => {
|
||||||
ensure!(poke_spec(&context, Some(arg1)).await, "Poke failed");
|
ensure!(poke_spec(&context, Some(arg1)).await, "Poke failed");
|
||||||
}
|
}
|
||||||
@@ -640,30 +652,6 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
println!("{cnt} chats");
|
println!("{cnt} chats");
|
||||||
println!("{time_needed:?} to create this list");
|
println!("{time_needed:?} to create this list");
|
||||||
}
|
}
|
||||||
"start-realtime" => {
|
|
||||||
if arg1.is_empty() {
|
|
||||||
bail!("missing msgid");
|
|
||||||
}
|
|
||||||
let msg_id = MsgId::new(arg1.parse()?);
|
|
||||||
let res = send_webxdc_realtime_advertisement(&context, msg_id).await?;
|
|
||||||
|
|
||||||
if let Some(res) = res {
|
|
||||||
println!("waiting for peer channel join");
|
|
||||||
res.await?;
|
|
||||||
}
|
|
||||||
println!("joined peer channel");
|
|
||||||
}
|
|
||||||
"send-realtime" => {
|
|
||||||
if arg1.is_empty() {
|
|
||||||
bail!("missing msgid");
|
|
||||||
}
|
|
||||||
if arg2.is_empty() {
|
|
||||||
bail!("no message");
|
|
||||||
}
|
|
||||||
let msg_id = MsgId::new(arg1.parse()?);
|
|
||||||
send_webxdc_realtime_data(&context, msg_id, arg2.as_bytes().to_vec()).await?;
|
|
||||||
println!("sent realtime message");
|
|
||||||
}
|
|
||||||
"chat" => {
|
"chat" => {
|
||||||
if sel_chat.is_none() && arg1.is_empty() {
|
if sel_chat.is_none() && arg1.is_empty() {
|
||||||
bail!("Argument [chat-id] is missing.");
|
bail!("Argument [chat-id] is missing.");
|
||||||
@@ -1258,10 +1246,10 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
|
|||||||
}
|
}
|
||||||
"providerinfo" => {
|
"providerinfo" => {
|
||||||
ensure!(!arg1.is_empty(), "Argument <addr> missing.");
|
ensure!(!arg1.is_empty(), "Argument <addr> missing.");
|
||||||
let proxy_enabled = context
|
let socks5_enabled = context
|
||||||
.get_config_bool(config::Config::ProxyEnabled)
|
.get_config_bool(config::Config::Socks5Enabled)
|
||||||
.await?;
|
.await?;
|
||||||
match provider::get_provider_info(&context, arg1, proxy_enabled).await {
|
match provider::get_provider_info(&context, arg1, socks5_enabled).await {
|
||||||
Some(info) => {
|
Some(info) => {
|
||||||
println!("Information for provider belonging to {arg1}:");
|
println!("Information for provider belonging to {arg1}:");
|
||||||
println!("status: {}", info.status as u32);
|
println!("status: {}", info.status as u32);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
//! This is a CLI program and a little testing frame. This file must not be
|
//! This is a CLI program and a little testing frame. This file must not be
|
||||||
//! included when using Delta Chat Core as a library.
|
//! included when using Delta Chat Core as a library.
|
||||||
//!
|
//!
|
||||||
@@ -12,6 +11,7 @@ use std::borrow::Cow::{self, Borrowed, Owned};
|
|||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
use ansi_term::Color;
|
||||||
use anyhow::{bail, Error};
|
use anyhow::{bail, Error};
|
||||||
use deltachat::chat::ChatId;
|
use deltachat::chat::ChatId;
|
||||||
use deltachat::config;
|
use deltachat::config;
|
||||||
@@ -21,7 +21,6 @@ use deltachat::qr_code_generator::get_securejoin_qr_svg;
|
|||||||
use deltachat::securejoin::*;
|
use deltachat::securejoin::*;
|
||||||
use deltachat::EventType;
|
use deltachat::EventType;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use nu_ansi_term::Color;
|
|
||||||
use rustyline::completion::{Completer, FilenameCompleter, Pair};
|
use rustyline::completion::{Completer, FilenameCompleter, Pair};
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
use rustyline::highlight::{Highlighter, MatchingBracketHighlighter};
|
use rustyline::highlight::{Highlighter, MatchingBracketHighlighter};
|
||||||
@@ -32,7 +31,6 @@ use rustyline::{
|
|||||||
};
|
};
|
||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::runtime::Handle;
|
use tokio::runtime::Handle;
|
||||||
use tracing_subscriber::EnvFilter;
|
|
||||||
|
|
||||||
mod cmdline;
|
mod cmdline;
|
||||||
use self::cmdline::*;
|
use self::cmdline::*;
|
||||||
@@ -152,7 +150,7 @@ impl Completer for DcHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const IMEX_COMMANDS: [&str; 13] = [
|
const IMEX_COMMANDS: [&str; 14] = [
|
||||||
"initiate-key-transfer",
|
"initiate-key-transfer",
|
||||||
"get-setupcodebegin",
|
"get-setupcodebegin",
|
||||||
"continue-key-transfer",
|
"continue-key-transfer",
|
||||||
@@ -163,12 +161,13 @@ const IMEX_COMMANDS: [&str; 13] = [
|
|||||||
"receive-backup",
|
"receive-backup",
|
||||||
"export-keys",
|
"export-keys",
|
||||||
"import-keys",
|
"import-keys",
|
||||||
|
"export-setup",
|
||||||
"poke",
|
"poke",
|
||||||
"reset",
|
"reset",
|
||||||
"stop",
|
"stop",
|
||||||
];
|
];
|
||||||
|
|
||||||
const DB_COMMANDS: [&str; 11] = [
|
const DB_COMMANDS: [&str; 10] = [
|
||||||
"info",
|
"info",
|
||||||
"set",
|
"set",
|
||||||
"get",
|
"get",
|
||||||
@@ -176,7 +175,6 @@ const DB_COMMANDS: [&str; 11] = [
|
|||||||
"configure",
|
"configure",
|
||||||
"connect",
|
"connect",
|
||||||
"disconnect",
|
"disconnect",
|
||||||
"fetch",
|
|
||||||
"connectivity",
|
"connectivity",
|
||||||
"maybenetwork",
|
"maybenetwork",
|
||||||
"housekeeping",
|
"housekeeping",
|
||||||
@@ -418,9 +416,6 @@ async fn handle_cmd(
|
|||||||
"disconnect" => {
|
"disconnect" => {
|
||||||
ctx.stop_io().await;
|
ctx.stop_io().await;
|
||||||
}
|
}
|
||||||
"fetch" => {
|
|
||||||
ctx.background_fetch().await?;
|
|
||||||
}
|
|
||||||
"configure" => {
|
"configure" => {
|
||||||
ctx.configure().await?;
|
ctx.configure().await?;
|
||||||
}
|
}
|
||||||
@@ -487,10 +482,9 @@ async fn handle_cmd(
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Error> {
|
async fn main() -> Result<(), Error> {
|
||||||
tracing_subscriber::fmt()
|
pretty_env_logger::formatted_timed_builder()
|
||||||
.with_env_filter(
|
.parse_default_env()
|
||||||
EnvFilter::from_default_env().add_directive("deltachat_repl=info".parse()?),
|
.filter_module("deltachat_repl", log::LevelFilter::Info)
|
||||||
)
|
|
||||||
.init();
|
.init();
|
||||||
|
|
||||||
let args = std::env::args().collect();
|
let args = std::env::args().collect();
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
it will echo back any text send to it, it also will print to console all Delta Chat core events.
|
it will echo back any text send to it, it also will print to console all Delta Chat core events.
|
||||||
Pass --help to the CLI to see available options.
|
Pass --help to the CLI to see available options.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from deltachat_rpc_client import events, run_bot_cli
|
from deltachat_rpc_client import events, run_bot_cli
|
||||||
|
|
||||||
hooks = events.HookCollection()
|
hooks = events.HookCollection()
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
it will echo back any message that has non-empty text and also supports the /help command.
|
it will echo back any message that has non-empty text and also supports the /help command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
"""
|
"""
|
||||||
Example echo bot without using hooks
|
Example echo bot without using hooks
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "deltachat-rpc-client"
|
name = "deltachat-rpc-client"
|
||||||
version = "1.147.0"
|
version = "1.137.2"
|
||||||
description = "Python client for Delta Chat core JSON-RPC interface"
|
description = "Python client for Delta Chat core JSON-RPC interface"
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 5 - Production/Stable",
|
"Development Status :: 5 - Production/Stable",
|
||||||
@@ -21,9 +21,6 @@ classifiers = [
|
|||||||
"Topic :: Communications :: Email"
|
"Topic :: Communications :: Email"
|
||||||
]
|
]
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
dependencies = [
|
|
||||||
"imap-tools",
|
|
||||||
]
|
|
||||||
|
|
||||||
[tool.setuptools.package-data]
|
[tool.setuptools.package-data]
|
||||||
deltachat_rpc_client = [
|
deltachat_rpc_client = [
|
||||||
@@ -37,7 +34,7 @@ deltachat_rpc_client = [
|
|||||||
line-length = 120
|
line-length = 120
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
lint.select = [
|
select = [
|
||||||
"E", "W", # pycodestyle
|
"E", "W", # pycodestyle
|
||||||
"F", # Pyflakes
|
"F", # Pyflakes
|
||||||
"N", # pep8-naming
|
"N", # pep8-naming
|
||||||
|
|||||||
@@ -104,11 +104,7 @@ def _run_cli(
|
|||||||
if not client.is_configured():
|
if not client.is_configured():
|
||||||
assert args.email, "Account is not configured and email must be provided"
|
assert args.email, "Account is not configured and email must be provided"
|
||||||
assert args.password, "Account is not configured and password must be provided"
|
assert args.password, "Account is not configured and password must be provided"
|
||||||
configure_thread = Thread(
|
configure_thread = Thread(run=client.configure, kwargs={"email": args.email, "password": args.password})
|
||||||
target=client.configure,
|
|
||||||
daemon=True,
|
|
||||||
kwargs={"email": args.email, "password": args.password},
|
|
||||||
)
|
|
||||||
configure_thread.start()
|
configure_thread.start()
|
||||||
client.run_forever()
|
client.run_forever()
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Optional, Union
|
from typing import TYPE_CHECKING, List, Optional, Tuple, Union
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
|
|
||||||
from ._utils import AttrDict, futuremethod
|
from ._utils import AttrDict, futuremethod
|
||||||
@@ -30,10 +28,6 @@ class Account:
|
|||||||
"""Wait until the next event and return it."""
|
"""Wait until the next event and return it."""
|
||||||
return AttrDict(self._rpc.wait_for_event(self.id))
|
return AttrDict(self._rpc.wait_for_event(self.id))
|
||||||
|
|
||||||
def clear_all_events(self):
|
|
||||||
"""Removes all queued-up events for a given account. Useful for tests."""
|
|
||||||
self._rpc.clear_all_events(self.id)
|
|
||||||
|
|
||||||
def remove(self) -> None:
|
def remove(self) -> None:
|
||||||
"""Remove the account."""
|
"""Remove the account."""
|
||||||
self._rpc.remove_account(self.id)
|
self._rpc.remove_account(self.id)
|
||||||
@@ -93,14 +87,6 @@ class Account:
|
|||||||
"""Configure an account."""
|
"""Configure an account."""
|
||||||
yield self._rpc.configure.future(self.id)
|
yield self._rpc.configure.future(self.id)
|
||||||
|
|
||||||
def bring_online(self):
|
|
||||||
"""Start I/O and wait until IMAP becomes IDLE."""
|
|
||||||
self.start_io()
|
|
||||||
while True:
|
|
||||||
event = self.wait_for_event()
|
|
||||||
if event.kind == EventType.IMAP_INBOX_IDLE:
|
|
||||||
break
|
|
||||||
|
|
||||||
def create_contact(self, obj: Union[int, str, Contact], name: Optional[str] = None) -> Contact:
|
def create_contact(self, obj: Union[int, str, Contact], name: Optional[str] = None) -> Contact:
|
||||||
"""Create a new Contact or return an existing one.
|
"""Create a new Contact or return an existing one.
|
||||||
|
|
||||||
@@ -118,11 +104,6 @@ class Account:
|
|||||||
obj = obj.get_snapshot().address
|
obj = obj.get_snapshot().address
|
||||||
return Contact(self, self._rpc.create_contact(self.id, obj, name))
|
return Contact(self, self._rpc.create_contact(self.id, obj, name))
|
||||||
|
|
||||||
def create_chat(self, account: "Account") -> Chat:
|
|
||||||
addr = account.get_config("addr")
|
|
||||||
contact = self.create_contact(addr)
|
|
||||||
return contact.create_chat()
|
|
||||||
|
|
||||||
def get_contact_by_id(self, contact_id: int) -> Contact:
|
def get_contact_by_id(self, contact_id: int) -> Contact:
|
||||||
"""Return Contact instance for the given contact ID."""
|
"""Return Contact instance for the given contact ID."""
|
||||||
return Contact(self, contact_id)
|
return Contact(self, contact_id)
|
||||||
@@ -132,7 +113,7 @@ class Account:
|
|||||||
contact_id = self._rpc.lookup_contact_id_by_addr(self.id, address)
|
contact_id = self._rpc.lookup_contact_id_by_addr(self.id, address)
|
||||||
return contact_id and Contact(self, contact_id)
|
return contact_id and Contact(self, contact_id)
|
||||||
|
|
||||||
def get_blocked_contacts(self) -> list[AttrDict]:
|
def get_blocked_contacts(self) -> List[AttrDict]:
|
||||||
"""Return a list with snapshots of all blocked contacts."""
|
"""Return a list with snapshots of all blocked contacts."""
|
||||||
contacts = self._rpc.get_blocked_contacts(self.id)
|
contacts = 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]
|
||||||
@@ -157,7 +138,7 @@ class Account:
|
|||||||
with_self: bool = False,
|
with_self: bool = False,
|
||||||
verified_only: bool = False,
|
verified_only: bool = False,
|
||||||
snapshot: bool = False,
|
snapshot: bool = False,
|
||||||
) -> Union[list[Contact], list[AttrDict]]:
|
) -> Union[List[Contact], List[AttrDict]]:
|
||||||
"""Get a filtered list of contacts.
|
"""Get a filtered list of contacts.
|
||||||
|
|
||||||
:param query: if a string is specified, only return contacts
|
:param query: if a string is specified, only return contacts
|
||||||
@@ -192,7 +173,7 @@ class Account:
|
|||||||
no_specials: bool = False,
|
no_specials: bool = False,
|
||||||
alldone_hint: bool = False,
|
alldone_hint: bool = False,
|
||||||
snapshot: bool = False,
|
snapshot: bool = False,
|
||||||
) -> Union[list[Chat], list[AttrDict]]:
|
) -> Union[List[Chat], List[AttrDict]]:
|
||||||
"""Return list of chats.
|
"""Return list of chats.
|
||||||
|
|
||||||
:param query: if a string is specified only chats matching this query are returned.
|
:param query: if a string is specified only chats matching this query are returned.
|
||||||
@@ -244,37 +225,33 @@ class Account:
|
|||||||
The function returns immediately and the handshake runs in background, sending
|
The function returns immediately and the handshake runs in background, sending
|
||||||
and receiving several messages.
|
and receiving several messages.
|
||||||
Subsequent calls of `secure_join()` will abort previous, unfinished handshakes.
|
Subsequent calls of `secure_join()` will abort previous, unfinished handshakes.
|
||||||
See https://securejoin.delta.chat/ for protocol details.
|
See https://securejoin.readthedocs.io/en/latest/new.html for protocol details.
|
||||||
|
|
||||||
:param qrdata: The text of the scanned QR code.
|
:param qrdata: The text of the scanned QR code.
|
||||||
"""
|
"""
|
||||||
return Chat(self, self._rpc.secure_join(self.id, qrdata))
|
return Chat(self, self._rpc.secure_join(self.id, qrdata))
|
||||||
|
|
||||||
def get_qr_code(self) -> str:
|
def get_qr_code(self) -> Tuple[str, str]:
|
||||||
"""Get Setup-Contact QR Code text.
|
"""Get Setup-Contact QR Code text and SVG data.
|
||||||
|
|
||||||
This data needs to be transferred to another Delta Chat account
|
this data needs to be transferred to another Delta Chat account
|
||||||
in a second channel, typically used by mobiles with QRcode-show + scan UX.
|
in a second channel, typically used by mobiles with QRcode-show + scan UX.
|
||||||
"""
|
"""
|
||||||
return self._rpc.get_chat_securejoin_qr_code(self.id, None)
|
|
||||||
|
|
||||||
def get_qr_code_svg(self) -> tuple[str, str]:
|
|
||||||
"""Get Setup-Contact QR code text and SVG."""
|
|
||||||
return self._rpc.get_chat_securejoin_qr_code_svg(self.id, None)
|
return self._rpc.get_chat_securejoin_qr_code_svg(self.id, None)
|
||||||
|
|
||||||
def get_message_by_id(self, msg_id: int) -> Message:
|
def get_message_by_id(self, msg_id: int) -> Message:
|
||||||
"""Return the Message instance with the given ID."""
|
"""Return the Message instance with the given ID."""
|
||||||
return Message(self, msg_id)
|
return Message(self, msg_id)
|
||||||
|
|
||||||
def mark_seen_messages(self, messages: list[Message]) -> None:
|
def mark_seen_messages(self, messages: List[Message]) -> None:
|
||||||
"""Mark the given set of messages as seen."""
|
"""Mark the given set of messages as seen."""
|
||||||
self._rpc.markseen_msgs(self.id, [msg.id for msg in messages])
|
self._rpc.markseen_msgs(self.id, [msg.id for msg in messages])
|
||||||
|
|
||||||
def delete_messages(self, messages: list[Message]) -> None:
|
def delete_messages(self, messages: List[Message]) -> None:
|
||||||
"""Delete messages (local and remote)."""
|
"""Delete messages (local and remote)."""
|
||||||
self._rpc.delete_messages(self.id, [msg.id for msg in messages])
|
self._rpc.delete_messages(self.id, [msg.id for msg in messages])
|
||||||
|
|
||||||
def get_fresh_messages(self) -> list[Message]:
|
def get_fresh_messages(self) -> List[Message]:
|
||||||
"""Return the list of fresh messages, newest messages first.
|
"""Return the list of fresh messages, newest messages first.
|
||||||
|
|
||||||
This call is intended for displaying notifications.
|
This call is intended for displaying notifications.
|
||||||
@@ -284,12 +261,12 @@ class Account:
|
|||||||
fresh_msg_ids = self._rpc.get_fresh_msgs(self.id)
|
fresh_msg_ids = self._rpc.get_fresh_msgs(self.id)
|
||||||
return [Message(self, msg_id) for msg_id in fresh_msg_ids]
|
return [Message(self, msg_id) for msg_id in fresh_msg_ids]
|
||||||
|
|
||||||
def get_next_messages(self) -> list[Message]:
|
def get_next_messages(self) -> List[Message]:
|
||||||
"""Return a list of next messages."""
|
"""Return a list of next messages."""
|
||||||
next_msg_ids = self._rpc.get_next_msgs(self.id)
|
next_msg_ids = self._rpc.get_next_msgs(self.id)
|
||||||
return [Message(self, msg_id) for msg_id in next_msg_ids]
|
return [Message(self, msg_id) for msg_id in next_msg_ids]
|
||||||
|
|
||||||
def wait_next_messages(self) -> list[Message]:
|
def wait_next_messages(self) -> List[Message]:
|
||||||
"""Wait for new messages and return a list of them."""
|
"""Wait for new messages and return a list of them."""
|
||||||
next_msg_ids = self._rpc.wait_next_msgs(self.id)
|
next_msg_ids = self._rpc.wait_next_msgs(self.id)
|
||||||
return [Message(self, msg_id) for msg_id in next_msg_ids]
|
return [Message(self, msg_id) for msg_id in next_msg_ids]
|
||||||
@@ -301,12 +278,6 @@ class Account:
|
|||||||
if event.kind == EventType.INCOMING_MSG:
|
if event.kind == EventType.INCOMING_MSG:
|
||||||
return event
|
return event
|
||||||
|
|
||||||
def wait_for_incoming_msg(self):
|
|
||||||
"""Wait for incoming message and return it.
|
|
||||||
|
|
||||||
Consumes all events before the next incoming message event."""
|
|
||||||
return self.get_message_by_id(self.wait_for_incoming_msg_event().msg_id)
|
|
||||||
|
|
||||||
def wait_for_securejoin_inviter_success(self):
|
def wait_for_securejoin_inviter_success(self):
|
||||||
while True:
|
while True:
|
||||||
event = self.wait_for_event()
|
event = self.wait_for_event()
|
||||||
@@ -319,13 +290,7 @@ class Account:
|
|||||||
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
|
if event["kind"] == "SecurejoinJoinerProgress" and event["progress"] == 1000:
|
||||||
break
|
break
|
||||||
|
|
||||||
def wait_for_reactions_changed(self):
|
def get_fresh_messages_in_arrival_order(self) -> List[Message]:
|
||||||
while True:
|
|
||||||
event = self.wait_for_event()
|
|
||||||
if event.kind == EventType.REACTIONS_CHANGED:
|
|
||||||
return event
|
|
||||||
|
|
||||||
def get_fresh_messages_in_arrival_order(self) -> list[Message]:
|
|
||||||
"""Return fresh messages list sorted in the order of their arrival, with ascending IDs."""
|
"""Return fresh messages list sorted in the order of their arrival, with ascending IDs."""
|
||||||
warn(
|
warn(
|
||||||
"get_fresh_messages_in_arrival_order is deprecated, use get_next_messages instead.",
|
"get_fresh_messages_in_arrival_order is deprecated, use get_next_messages instead.",
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import calendar
|
import calendar
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from tempfile import NamedTemporaryFile
|
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union
|
||||||
from typing import TYPE_CHECKING, Optional, Union
|
|
||||||
|
|
||||||
from ._utils import AttrDict
|
from ._utils import AttrDict
|
||||||
from .const import ChatVisibility, ViewType
|
from .const import ChatVisibility, ViewType
|
||||||
@@ -96,11 +93,7 @@ class Chat:
|
|||||||
"""Return encryption info for this chat."""
|
"""Return encryption info for this chat."""
|
||||||
return self._rpc.get_chat_encryption_info(self.account.id, self.id)
|
return self._rpc.get_chat_encryption_info(self.account.id, self.id)
|
||||||
|
|
||||||
def get_qr_code(self) -> str:
|
def get_qr_code(self) -> Tuple[str, str]:
|
||||||
"""Get Join-Group QR code text."""
|
|
||||||
return self._rpc.get_chat_securejoin_qr_code(self.account.id, self.id)
|
|
||||||
|
|
||||||
def get_qr_code_svg(self) -> tuple[str, str]:
|
|
||||||
"""Get Join-Group QR code text and SVG data."""
|
"""Get Join-Group QR code text and SVG data."""
|
||||||
return self._rpc.get_chat_securejoin_qr_code_svg(self.account.id, self.id)
|
return self._rpc.get_chat_securejoin_qr_code_svg(self.account.id, self.id)
|
||||||
|
|
||||||
@@ -124,7 +117,7 @@ class Chat:
|
|||||||
html: Optional[str] = None,
|
html: Optional[str] = None,
|
||||||
viewtype: Optional[ViewType] = None,
|
viewtype: Optional[ViewType] = None,
|
||||||
file: Optional[str] = None,
|
file: Optional[str] = None,
|
||||||
location: Optional[tuple[float, float]] = None,
|
location: Optional[Tuple[float, float]] = None,
|
||||||
override_sender_name: Optional[str] = None,
|
override_sender_name: Optional[str] = None,
|
||||||
quoted_msg: Optional[Union[int, Message]] = None,
|
quoted_msg: Optional[Union[int, Message]] = None,
|
||||||
) -> Message:
|
) -> Message:
|
||||||
@@ -149,10 +142,6 @@ class Chat:
|
|||||||
msg_id = self._rpc.misc_send_text_message(self.account.id, self.id, text)
|
msg_id = self._rpc.misc_send_text_message(self.account.id, self.id, text)
|
||||||
return Message(self.account, msg_id)
|
return Message(self.account, msg_id)
|
||||||
|
|
||||||
def send_file(self, path):
|
|
||||||
"""Send a file and return the resulting Message instance."""
|
|
||||||
return self.send_message(file=path)
|
|
||||||
|
|
||||||
def send_videochat_invitation(self) -> Message:
|
def send_videochat_invitation(self) -> Message:
|
||||||
"""Send a videochat invitation and return the resulting Message instance."""
|
"""Send a videochat invitation and return the resulting Message instance."""
|
||||||
msg_id = self._rpc.send_videochat_invitation(self.account.id, self.id)
|
msg_id = self._rpc.send_videochat_invitation(self.account.id, self.id)
|
||||||
@@ -163,7 +152,7 @@ class Chat:
|
|||||||
msg_id = self._rpc.send_sticker(self.account.id, self.id, path)
|
msg_id = self._rpc.send_sticker(self.account.id, self.id, path)
|
||||||
return Message(self.account, msg_id)
|
return Message(self.account, msg_id)
|
||||||
|
|
||||||
def forward_messages(self, messages: list[Message]) -> None:
|
def forward_messages(self, messages: List[Message]) -> None:
|
||||||
"""Forward a list of messages to this chat."""
|
"""Forward a list of messages to this chat."""
|
||||||
msg_ids = [msg.id for msg in messages]
|
msg_ids = [msg.id for msg in messages]
|
||||||
self._rpc.forward_messages(self.account.id, msg_ids, self.id)
|
self._rpc.forward_messages(self.account.id, msg_ids, self.id)
|
||||||
@@ -195,7 +184,7 @@ class Chat:
|
|||||||
snapshot["message"] = Message(self.account, snapshot.id)
|
snapshot["message"] = Message(self.account, snapshot.id)
|
||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
def get_messages(self, info_only: bool = False, add_daymarker: bool = False) -> list[Message]:
|
def get_messages(self, info_only: bool = False, add_daymarker: bool = False) -> List[Message]:
|
||||||
"""get the list of messages in this chat."""
|
"""get the list of messages in this chat."""
|
||||||
msgs = self._rpc.get_message_ids(self.account.id, self.id, info_only, add_daymarker)
|
msgs = self._rpc.get_message_ids(self.account.id, self.id, info_only, add_daymarker)
|
||||||
return [Message(self.account, msg_id) for msg_id in msgs]
|
return [Message(self.account, msg_id) for msg_id in msgs]
|
||||||
@@ -230,7 +219,7 @@ class Chat:
|
|||||||
contact_id = cnt
|
contact_id = cnt
|
||||||
self._rpc.remove_contact_from_chat(self.account.id, self.id, contact_id)
|
self._rpc.remove_contact_from_chat(self.account.id, self.id, contact_id)
|
||||||
|
|
||||||
def get_contacts(self) -> list[Contact]:
|
def get_contacts(self) -> List[Contact]:
|
||||||
"""Get the contacts belonging to this chat.
|
"""Get the contacts belonging to this chat.
|
||||||
|
|
||||||
For single/direct chats self-address is not included.
|
For single/direct chats self-address is not included.
|
||||||
@@ -254,7 +243,7 @@ class Chat:
|
|||||||
contact: Optional[Contact] = None,
|
contact: Optional[Contact] = None,
|
||||||
timestamp_from: Optional["datetime"] = None,
|
timestamp_from: Optional["datetime"] = None,
|
||||||
timestamp_to: Optional["datetime"] = None,
|
timestamp_to: Optional["datetime"] = None,
|
||||||
) -> list[AttrDict]:
|
) -> List[AttrDict]:
|
||||||
"""Get list of location snapshots for the given contact in the given timespan."""
|
"""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
|
time_to = calendar.timegm(timestamp_to.utctimetuple()) if timestamp_to else 0
|
||||||
@@ -262,7 +251,7 @@ class Chat:
|
|||||||
|
|
||||||
result = self._rpc.get_locations(self.account.id, self.id, contact_id, time_from, time_to)
|
result = self._rpc.get_locations(self.account.id, self.id, contact_id, time_from, time_to)
|
||||||
locations = []
|
locations = []
|
||||||
contacts: dict[int, Contact] = {}
|
contacts: Dict[int, Contact] = {}
|
||||||
for loc in result:
|
for loc in result:
|
||||||
location = AttrDict(loc)
|
location = AttrDict(loc)
|
||||||
location["chat"] = self
|
location["chat"] = self
|
||||||
@@ -270,11 +259,3 @@ class Chat:
|
|||||||
location["message"] = Message(self.account, location.msg_id)
|
location["message"] = Message(self.account, location.msg_id)
|
||||||
locations.append(location)
|
locations.append(location)
|
||||||
return locations
|
return locations
|
||||||
|
|
||||||
def send_contact(self, contact: Contact):
|
|
||||||
"""Send contact to the chat."""
|
|
||||||
vcard = contact.make_vcard()
|
|
||||||
with NamedTemporaryFile(suffix=".vcard") as f:
|
|
||||||
f.write(vcard.encode())
|
|
||||||
f.flush()
|
|
||||||
self._rpc.send_msg(self.account.id, self.id, {"viewtype": ViewType.VCARD, "file": f.name})
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
"""Event loop implementations offering high level event handling/hooking."""
|
"""Event loop implementations offering high level event handling/hooking."""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Callable,
|
Callable,
|
||||||
|
Dict,
|
||||||
Iterable,
|
Iterable,
|
||||||
Optional,
|
Optional,
|
||||||
|
Set,
|
||||||
|
Tuple,
|
||||||
Type,
|
Type,
|
||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
@@ -38,16 +39,16 @@ class Client:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
account: "Account",
|
account: "Account",
|
||||||
hooks: Optional[Iterable[tuple[Callable, Union[type, EventFilter]]]] = None,
|
hooks: Optional[Iterable[Tuple[Callable, Union[type, EventFilter]]]] = None,
|
||||||
logger: Optional[logging.Logger] = None,
|
logger: Optional[logging.Logger] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.account = account
|
self.account = account
|
||||||
self.logger = logger or logging
|
self.logger = logger or logging
|
||||||
self._hooks: dict[type, set[tuple]] = {}
|
self._hooks: Dict[type, Set[tuple]] = {}
|
||||||
self._should_process_messages = 0
|
self._should_process_messages = 0
|
||||||
self.add_hooks(hooks or [])
|
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:
|
for hook, event in hooks:
|
||||||
self.add_hook(hook, event)
|
self.add_hook(hook, event)
|
||||||
|
|
||||||
|
|||||||
@@ -59,10 +59,6 @@ class EventType(str, Enum):
|
|||||||
SELFAVATAR_CHANGED = "SelfavatarChanged"
|
SELFAVATAR_CHANGED = "SelfavatarChanged"
|
||||||
WEBXDC_STATUS_UPDATE = "WebxdcStatusUpdate"
|
WEBXDC_STATUS_UPDATE = "WebxdcStatusUpdate"
|
||||||
WEBXDC_INSTANCE_DELETED = "WebxdcInstanceDeleted"
|
WEBXDC_INSTANCE_DELETED = "WebxdcInstanceDeleted"
|
||||||
CHATLIST_CHANGED = "ChatlistChanged"
|
|
||||||
CHATLIST_ITEM_CHANGED = "ChatlistItemChanged"
|
|
||||||
CONFIG_SYNCED = "ConfigSynced"
|
|
||||||
WEBXDC_REALTIME_DATA = "WebxdcRealtimeData"
|
|
||||||
|
|
||||||
|
|
||||||
class ChatId(IntEnum):
|
class ChatId(IntEnum):
|
||||||
@@ -115,7 +111,6 @@ class ViewType(str, Enum):
|
|||||||
FILE = "File"
|
FILE = "File"
|
||||||
VIDEOCHAT_INVITATION = "VideochatInvitation"
|
VIDEOCHAT_INVITATION = "VideochatInvitation"
|
||||||
WEBXDC = "Webxdc"
|
WEBXDC = "Webxdc"
|
||||||
VCARD = "Vcard"
|
|
||||||
|
|
||||||
|
|
||||||
class SystemMessageType(str, Enum):
|
class SystemMessageType(str, Enum):
|
||||||
|
|||||||
@@ -60,6 +60,3 @@ class Contact:
|
|||||||
self.account,
|
self.account,
|
||||||
self._rpc.create_chat_by_contact_id(self.account.id, self.id),
|
self._rpc.create_chat_by_contact_id(self.account.id, self.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
def make_vcard(self) -> str:
|
|
||||||
return self._rpc.make_vcard(self.account.id, [self.id])
|
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
from __future__ import annotations
|
from typing import TYPE_CHECKING, Dict, List
|
||||||
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from ._utils import AttrDict
|
from ._utils import AttrDict
|
||||||
from .account import Account
|
from .account import Account
|
||||||
@@ -23,7 +21,7 @@ class DeltaChat:
|
|||||||
account_id = self.rpc.add_account()
|
account_id = self.rpc.add_account()
|
||||||
return Account(self, account_id)
|
return Account(self, account_id)
|
||||||
|
|
||||||
def get_all_accounts(self) -> list[Account]:
|
def get_all_accounts(self) -> List[Account]:
|
||||||
"""Return a list of all available accounts."""
|
"""Return a list of all available accounts."""
|
||||||
account_ids = self.rpc.get_all_account_ids()
|
account_ids = self.rpc.get_all_account_ids()
|
||||||
return [Account(self, account_id) for account_id in account_ids]
|
return [Account(self, account_id) for account_id in account_ids]
|
||||||
@@ -46,6 +44,6 @@ class DeltaChat:
|
|||||||
"""Get information about the Delta Chat core in this system."""
|
"""Get information about the Delta Chat core in this system."""
|
||||||
return AttrDict(self.rpc.get_system_info())
|
return AttrDict(self.rpc.get_system_info())
|
||||||
|
|
||||||
def set_translations(self, translations: dict[str, str]) -> None:
|
def set_translations(self, translations: Dict[str, str]) -> None:
|
||||||
"""Set stock translation strings."""
|
"""Set stock translation strings."""
|
||||||
self.rpc.set_stock_strings(translations)
|
self.rpc.set_stock_strings(translations)
|
||||||
|
|||||||
@@ -1,214 +0,0 @@
|
|||||||
"""
|
|
||||||
Internal Python-level IMAP handling used by the tests.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import imaplib
|
|
||||||
import io
|
|
||||||
import pathlib
|
|
||||||
import ssl
|
|
||||||
from contextlib import contextmanager
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from imap_tools import (
|
|
||||||
AND,
|
|
||||||
Header,
|
|
||||||
MailBox,
|
|
||||||
MailMessage,
|
|
||||||
MailMessageFlags,
|
|
||||||
errors,
|
|
||||||
)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from . import Account
|
|
||||||
|
|
||||||
FLAGS = b"FLAGS"
|
|
||||||
FETCH = b"FETCH"
|
|
||||||
ALL = "1:*"
|
|
||||||
|
|
||||||
|
|
||||||
class DirectImap:
|
|
||||||
def __init__(self, account: Account) -> None:
|
|
||||||
self.account = account
|
|
||||||
self.logid = account.get_config("displayname") or id(account)
|
|
||||||
self._idling = False
|
|
||||||
self.connect()
|
|
||||||
|
|
||||||
def connect(self):
|
|
||||||
# Assume the testing server supports TLS on port 993.
|
|
||||||
host = self.account.get_config("configured_mail_server")
|
|
||||||
port = 993
|
|
||||||
|
|
||||||
user = self.account.get_config("addr")
|
|
||||||
host = user.rsplit("@")[-1]
|
|
||||||
pw = self.account.get_config("mail_pw")
|
|
||||||
|
|
||||||
self.conn = MailBox(host, port, ssl_context=ssl.create_default_context())
|
|
||||||
self.conn.login(user, pw)
|
|
||||||
|
|
||||||
self.select_folder("INBOX")
|
|
||||||
|
|
||||||
def shutdown(self):
|
|
||||||
try:
|
|
||||||
self.conn.logout()
|
|
||||||
except (OSError, imaplib.IMAP4.abort):
|
|
||||||
print("Could not logout direct_imap conn")
|
|
||||||
|
|
||||||
def create_folder(self, foldername):
|
|
||||||
try:
|
|
||||||
self.conn.folder.create(foldername)
|
|
||||||
except errors.MailboxFolderCreateError as e:
|
|
||||||
print("Can't create", foldername, "probably it already exists:", str(e))
|
|
||||||
|
|
||||||
def select_folder(self, foldername: str) -> tuple:
|
|
||||||
assert not self._idling
|
|
||||||
return self.conn.folder.set(foldername)
|
|
||||||
|
|
||||||
def select_config_folder(self, config_name: str):
|
|
||||||
"""Return info about selected folder if it is
|
|
||||||
configured, otherwise None.
|
|
||||||
"""
|
|
||||||
if "_" not in config_name:
|
|
||||||
config_name = f"configured_{config_name}_folder"
|
|
||||||
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."""
|
|
||||||
assert not self._idling
|
|
||||||
return [folder.name for folder in self.conn.folder.list()]
|
|
||||||
|
|
||||||
def delete(self, uid_list: str, expunge=True):
|
|
||||||
"""delete a range of messages (imap-syntax).
|
|
||||||
If expunge is true, perform the expunge-operation
|
|
||||||
to make sure the messages are really gone and not
|
|
||||||
just flagged as deleted.
|
|
||||||
"""
|
|
||||||
self.conn.client.uid("STORE", uid_list, "+FLAGS", r"(\Deleted)")
|
|
||||||
if expunge:
|
|
||||||
self.conn.expunge()
|
|
||||||
|
|
||||||
def get_all_messages(self) -> list[MailMessage]:
|
|
||||||
assert not self._idling
|
|
||||||
return list(self.conn.fetch())
|
|
||||||
|
|
||||||
def get_unread_messages(self) -> list[str]:
|
|
||||||
assert not self._idling
|
|
||||||
return [msg.uid for msg in self.conn.fetch(AND(seen=False))]
|
|
||||||
|
|
||||||
def mark_all_read(self):
|
|
||||||
messages = self.get_unread_messages()
|
|
||||||
if messages:
|
|
||||||
res = self.conn.flag(messages, MailMessageFlags.SEEN, True)
|
|
||||||
print("marked seen:", messages, res)
|
|
||||||
|
|
||||||
def get_unread_cnt(self) -> int:
|
|
||||||
return len(self.get_unread_messages())
|
|
||||||
|
|
||||||
def dump_imap_structures(self, dir, logfile):
|
|
||||||
assert not self._idling
|
|
||||||
stream = io.StringIO()
|
|
||||||
|
|
||||||
def log(*args, **kwargs):
|
|
||||||
kwargs["file"] = stream
|
|
||||||
print(*args, **kwargs)
|
|
||||||
|
|
||||||
empty_folders = []
|
|
||||||
for imapfolder in self.list_folders():
|
|
||||||
self.select_folder(imapfolder)
|
|
||||||
messages = list(self.get_all_messages())
|
|
||||||
if not messages:
|
|
||||||
empty_folders.append(imapfolder)
|
|
||||||
continue
|
|
||||||
|
|
||||||
log("---------", imapfolder, len(messages), "messages ---------")
|
|
||||||
# get message content without auto-marking it as seen
|
|
||||||
# fetching 'RFC822' would mark it as seen.
|
|
||||||
for msg in self.conn.fetch(mark_seen=False):
|
|
||||||
body = getattr(msg.obj, "text", None)
|
|
||||||
if not body:
|
|
||||||
body = getattr(msg.obj, "html", None)
|
|
||||||
if not body:
|
|
||||||
log("Message", msg.uid, "has empty body")
|
|
||||||
continue
|
|
||||||
|
|
||||||
path = pathlib.Path(str(dir)).joinpath("IMAP", self.logid, imapfolder)
|
|
||||||
path.mkdir(parents=True, exist_ok=True)
|
|
||||||
fn = path.joinpath(str(msg.uid))
|
|
||||||
fn.write_bytes(body)
|
|
||||||
log("Message", msg.uid, fn)
|
|
||||||
log(
|
|
||||||
"Message",
|
|
||||||
msg.uid,
|
|
||||||
msg.flags,
|
|
||||||
"Message-Id:",
|
|
||||||
msg.obj.get("Message-Id"),
|
|
||||||
)
|
|
||||||
|
|
||||||
if empty_folders:
|
|
||||||
log("--------- EMPTY FOLDERS:", empty_folders)
|
|
||||||
|
|
||||||
print(stream.getvalue(), file=logfile)
|
|
||||||
|
|
||||||
@contextmanager
|
|
||||||
def idle(self):
|
|
||||||
"""return Idle ContextManager."""
|
|
||||||
idle_manager = IdleManager(self)
|
|
||||||
try:
|
|
||||||
yield idle_manager
|
|
||||||
finally:
|
|
||||||
idle_manager.done()
|
|
||||||
|
|
||||||
def append(self, folder: str, msg: str):
|
|
||||||
"""Upload a message to *folder*.
|
|
||||||
Trailing whitespace or a linebreak at the beginning will be removed automatically.
|
|
||||||
"""
|
|
||||||
if msg.startswith("\n"):
|
|
||||||
msg = msg[1:]
|
|
||||||
msg = "\n".join([s.lstrip() for s in msg.splitlines()])
|
|
||||||
self.conn.append(bytes(msg, encoding="ascii"), folder)
|
|
||||||
|
|
||||||
def get_uid_by_message_id(self, message_id) -> str:
|
|
||||||
msgs = [msg.uid for msg in self.conn.fetch(AND(header=Header("MESSAGE-ID", message_id)))]
|
|
||||||
if len(msgs) == 0:
|
|
||||||
raise Exception("Did not find message " + message_id + ", maybe you forgot to select the correct folder?")
|
|
||||||
return msgs[0]
|
|
||||||
|
|
||||||
|
|
||||||
class IdleManager:
|
|
||||||
def __init__(self, direct_imap) -> None:
|
|
||||||
self.direct_imap = direct_imap
|
|
||||||
self.log = direct_imap.account.log
|
|
||||||
# fetch latest messages before starting idle so that it only
|
|
||||||
# returns messages that arrive anew
|
|
||||||
self.direct_imap.conn.fetch("1:*")
|
|
||||||
self.direct_imap.conn.idle.start()
|
|
||||||
|
|
||||||
def check(self, timeout=None) -> list[bytes]:
|
|
||||||
"""(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}")
|
|
||||||
return res
|
|
||||||
|
|
||||||
def wait_for_new_message(self, timeout=None) -> bytes:
|
|
||||||
while True:
|
|
||||||
for item in self.check(timeout=timeout):
|
|
||||||
if b"EXISTS" in item or b"RECENT" in item:
|
|
||||||
return item
|
|
||||||
|
|
||||||
def wait_for_seen(self, timeout=None) -> int:
|
|
||||||
"""Return first message with SEEN flag from a running idle-stream."""
|
|
||||||
while True:
|
|
||||||
for item in self.check(timeout=timeout):
|
|
||||||
if FETCH in item:
|
|
||||||
self.log(str(item))
|
|
||||||
if FLAGS in item and rb"\Seen" in item:
|
|
||||||
return int(item.split(b" ")[1])
|
|
||||||
|
|
||||||
def done(self):
|
|
||||||
"""send idle-done to server if we are currently in idle mode."""
|
|
||||||
return self.direct_imap.conn.idle.stop()
|
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
"""High-level classes for event processing and filtering."""
|
"""High-level classes for event processing and filtering."""
|
||||||
|
|
||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
from typing import TYPE_CHECKING, Callable, Iterable, Iterator, Optional, Union
|
from typing import TYPE_CHECKING, Callable, Iterable, Iterator, Optional, Set, Tuple, Union
|
||||||
|
|
||||||
from .const import EventType
|
from .const import EventType
|
||||||
|
|
||||||
@@ -265,9 +263,9 @@ class HookCollection:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self._hooks: set[tuple[Callable, Union[type, EventFilter]]] = set()
|
self._hooks: Set[Tuple[Callable, Union[type, EventFilter]]] = set()
|
||||||
|
|
||||||
def __iter__(self) -> Iterator[tuple[Callable, Union[type, EventFilter]]]:
|
def __iter__(self) -> Iterator[Tuple[Callable, Union[type, EventFilter]]]:
|
||||||
return iter(self._hooks)
|
return iter(self._hooks)
|
||||||
|
|
||||||
def on(self, event: Union[type, EventFilter]) -> Callable: # noqa
|
def on(self, event: Union[type, EventFilter]) -> Callable: # noqa
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import json
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import TYPE_CHECKING, Optional, Union
|
from typing import TYPE_CHECKING, Optional, Union
|
||||||
|
|
||||||
from ._utils import AttrDict, futuremethod
|
from ._utils import AttrDict
|
||||||
from .const import EventType
|
|
||||||
from .contact import Contact
|
from .contact import Contact
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -22,10 +21,9 @@ class Message:
|
|||||||
def _rpc(self) -> "Rpc":
|
def _rpc(self) -> "Rpc":
|
||||||
return self.account._rpc
|
return self.account._rpc
|
||||||
|
|
||||||
def send_reaction(self, *reaction: str) -> "Message":
|
def send_reaction(self, *reaction: str):
|
||||||
"""Send a reaction to this message."""
|
"""Send a reaction to this message."""
|
||||||
msg_id = self._rpc.send_reaction(self.account.id, self.id, reaction)
|
self._rpc.send_reaction(self.account.id, self.id, reaction)
|
||||||
return Message(self.account, msg_id)
|
|
||||||
|
|
||||||
def get_snapshot(self) -> AttrDict:
|
def get_snapshot(self) -> AttrDict:
|
||||||
"""Get a snapshot with the properties of this message."""
|
"""Get a snapshot with the properties of this message."""
|
||||||
@@ -63,18 +61,3 @@ class Message:
|
|||||||
|
|
||||||
def get_webxdc_info(self) -> dict:
|
def get_webxdc_info(self) -> dict:
|
||||||
return self._rpc.get_webxdc_info(self.account.id, self.id)
|
return self._rpc.get_webxdc_info(self.account.id, self.id)
|
||||||
|
|
||||||
def wait_until_delivered(self) -> None:
|
|
||||||
"""Consume events until the message is delivered."""
|
|
||||||
while True:
|
|
||||||
event = self.account.wait_for_event()
|
|
||||||
if event.kind == EventType.MSG_DELIVERED and event.msg_id == self.id:
|
|
||||||
break
|
|
||||||
|
|
||||||
@futuremethod
|
|
||||||
def send_webxdc_realtime_advertisement(self):
|
|
||||||
yield self._rpc.send_webxdc_realtime_advertisement.future(self.account.id, self.id)
|
|
||||||
|
|
||||||
@futuremethod
|
|
||||||
def send_webxdc_realtime_data(self, data) -> None:
|
|
||||||
yield self._rpc.send_webxdc_realtime_data.future(self.account.id, self.id, list(data))
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
from typing import AsyncGenerator, Optional
|
from typing import AsyncGenerator, List, Optional
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from . import Account, AttrDict, Bot, Chat, Client, DeltaChat, EventType, Message
|
from . import Account, AttrDict, Bot, Client, DeltaChat, EventType, Message
|
||||||
from ._utils import futuremethod
|
from ._utils import futuremethod
|
||||||
from .rpc import Rpc
|
from .rpc import Rpc
|
||||||
|
|
||||||
@@ -56,10 +54,14 @@ class ACFactory:
|
|||||||
@futuremethod
|
@futuremethod
|
||||||
def get_online_account(self):
|
def get_online_account(self):
|
||||||
account = yield self.new_configured_account.future()
|
account = yield self.new_configured_account.future()
|
||||||
account.bring_online()
|
account.start_io()
|
||||||
|
while True:
|
||||||
|
event = account.wait_for_event()
|
||||||
|
if event.kind == EventType.IMAP_INBOX_IDLE:
|
||||||
|
break
|
||||||
return account
|
return account
|
||||||
|
|
||||||
def get_online_accounts(self, num: int) -> list[Account]:
|
def get_online_accounts(self, num: int) -> List[Account]:
|
||||||
futures = [self.get_online_account.future() for _ in range(num)]
|
futures = [self.get_online_account.future() for _ in range(num)]
|
||||||
return [f() for f in futures]
|
return [f() for f in futures]
|
||||||
|
|
||||||
@@ -73,10 +75,6 @@ class ACFactory:
|
|||||||
ac_clone.configure()
|
ac_clone.configure()
|
||||||
return ac_clone
|
return ac_clone
|
||||||
|
|
||||||
def get_accepted_chat(self, ac1: Account, ac2: Account) -> Chat:
|
|
||||||
ac2.create_chat(ac1)
|
|
||||||
return ac1.create_chat(ac2)
|
|
||||||
|
|
||||||
def send_message(
|
def send_message(
|
||||||
self,
|
self,
|
||||||
to_account: Account,
|
to_account: Account,
|
||||||
@@ -114,13 +112,13 @@ class ACFactory:
|
|||||||
return to_client.run_until(lambda e: e.kind == EventType.INCOMING_MSG)
|
return to_client.run_until(lambda e: e.kind == EventType.INCOMING_MSG)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture()
|
||||||
def rpc(tmp_path) -> AsyncGenerator:
|
def rpc(tmp_path) -> AsyncGenerator:
|
||||||
rpc_server = Rpc(accounts_dir=str(tmp_path / "accounts"))
|
rpc_server = Rpc(accounts_dir=str(tmp_path / "accounts"))
|
||||||
with rpc_server:
|
with rpc_server:
|
||||||
yield rpc_server
|
yield rpc_server
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture()
|
||||||
def acfactory(rpc) -> AsyncGenerator:
|
def acfactory(rpc) -> AsyncGenerator:
|
||||||
return ACFactory(DeltaChat(rpc))
|
return ACFactory(DeltaChat(rpc))
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
from queue import Empty, Queue
|
from queue import Queue
|
||||||
from threading import Event, Thread
|
from threading import Event, Thread
|
||||||
from typing import Any, Iterator, Optional
|
from typing import Any, Dict, Iterator, Optional
|
||||||
|
|
||||||
|
|
||||||
class JsonRpcError(Exception):
|
class JsonRpcError(Exception):
|
||||||
@@ -69,11 +67,11 @@ class Rpc:
|
|||||||
self._kwargs = kwargs
|
self._kwargs = kwargs
|
||||||
self.process: subprocess.Popen
|
self.process: subprocess.Popen
|
||||||
self.id_iterator: Iterator[int]
|
self.id_iterator: Iterator[int]
|
||||||
self.event_queues: dict[int, Queue]
|
self.event_queues: Dict[int, Queue]
|
||||||
# Map from request ID to `threading.Event`.
|
# Map from request ID to `threading.Event`.
|
||||||
self.request_events: dict[int, Event]
|
self.request_events: Dict[int, Event]
|
||||||
# Map from request ID to the result.
|
# Map from request ID to the result.
|
||||||
self.request_results: dict[int, Any]
|
self.request_results: Dict[int, Any]
|
||||||
self.request_queue: Queue[Any]
|
self.request_queue: Queue[Any]
|
||||||
self.closing: bool
|
self.closing: bool
|
||||||
self.reader_thread: Thread
|
self.reader_thread: Thread
|
||||||
@@ -188,14 +186,5 @@ class Rpc:
|
|||||||
queue = self.get_queue(account_id)
|
queue = self.get_queue(account_id)
|
||||||
return queue.get()
|
return queue.get()
|
||||||
|
|
||||||
def clear_all_events(self, account_id: int):
|
|
||||||
"""Removes all queued-up events for a given account. Useful for tests."""
|
|
||||||
queue = self.get_queue(account_id)
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
queue.get_nowait()
|
|
||||||
except Empty:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def __getattr__(self, attr: str):
|
def __getattr__(self, attr: str):
|
||||||
return RpcMethod(self, attr)
|
return RpcMethod(self, attr)
|
||||||
|
|||||||
@@ -1,218 +0,0 @@
|
|||||||
from __future__ import annotations
|
|
||||||
|
|
||||||
import base64
|
|
||||||
import os
|
|
||||||
from typing import TYPE_CHECKING
|
|
||||||
|
|
||||||
from deltachat_rpc_client import Account, EventType, const
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from deltachat_rpc_client.pytestplugin import ACFactory
|
|
||||||
|
|
||||||
|
|
||||||
def wait_for_chatlist_and_specific_item(account, chat_id):
|
|
||||||
first_event = ""
|
|
||||||
while True:
|
|
||||||
event = account.wait_for_event()
|
|
||||||
if event.kind == EventType.CHATLIST_CHANGED:
|
|
||||||
first_event = "change"
|
|
||||||
break
|
|
||||||
if event.kind == EventType.CHATLIST_ITEM_CHANGED and event.chat_id == chat_id:
|
|
||||||
first_event = "item_change"
|
|
||||||
break
|
|
||||||
while True:
|
|
||||||
event = account.wait_for_event()
|
|
||||||
if event.kind == EventType.CHATLIST_CHANGED and first_event == "item_change":
|
|
||||||
break
|
|
||||||
if event.kind == EventType.CHATLIST_ITEM_CHANGED and event.chat_id == chat_id and first_event == "change":
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def wait_for_chatlist_specific_item(account, chat_id):
|
|
||||||
while True:
|
|
||||||
event = account.wait_for_event()
|
|
||||||
if event.kind == EventType.CHATLIST_ITEM_CHANGED and event.chat_id == chat_id:
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def wait_for_chatlist(account):
|
|
||||||
while True:
|
|
||||||
event = account.wait_for_event()
|
|
||||||
if event.kind == EventType.CHATLIST_CHANGED:
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def test_delivery_status(acfactory: ACFactory) -> None:
|
|
||||||
"""
|
|
||||||
Test change status on chatlistitem when status changes (delivered, read)
|
|
||||||
"""
|
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
|
||||||
|
|
||||||
bob_addr = bob.get_config("addr")
|
|
||||||
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
|
|
||||||
alice_chat_bob = alice_contact_bob.create_chat()
|
|
||||||
|
|
||||||
alice.clear_all_events()
|
|
||||||
bob.stop_io()
|
|
||||||
alice.stop_io()
|
|
||||||
alice_chat_bob.send_text("hi")
|
|
||||||
wait_for_chatlist_and_specific_item(alice, chat_id=alice_chat_bob.id)
|
|
||||||
|
|
||||||
alice.clear_all_events()
|
|
||||||
alice.start_io()
|
|
||||||
wait_for_chatlist_specific_item(alice, chat_id=alice_chat_bob.id)
|
|
||||||
|
|
||||||
bob.clear_all_events()
|
|
||||||
bob.start_io()
|
|
||||||
|
|
||||||
event = bob.wait_for_incoming_msg_event()
|
|
||||||
msg = bob.get_message_by_id(event.msg_id)
|
|
||||||
msg.get_snapshot().chat.accept()
|
|
||||||
msg.mark_seen()
|
|
||||||
|
|
||||||
chat_item = alice._rpc.get_chatlist_items_by_entries(alice.id, [alice_chat_bob.id])[str(alice_chat_bob.id)]
|
|
||||||
assert chat_item["summaryStatus"] == const.MessageState.OUT_DELIVERED
|
|
||||||
|
|
||||||
alice.clear_all_events()
|
|
||||||
|
|
||||||
while True:
|
|
||||||
event = alice.wait_for_event()
|
|
||||||
if event.kind == EventType.MSG_READ:
|
|
||||||
break
|
|
||||||
|
|
||||||
wait_for_chatlist_specific_item(alice, chat_id=alice_chat_bob.id)
|
|
||||||
chat_item = alice._rpc.get_chatlist_items_by_entries(alice.id, [alice_chat_bob.id])[str(alice_chat_bob.id)]
|
|
||||||
assert chat_item["summaryStatus"] == const.MessageState.OUT_MDN_RCVD
|
|
||||||
|
|
||||||
|
|
||||||
def test_delivery_status_failed(acfactory: ACFactory) -> None:
|
|
||||||
"""
|
|
||||||
Test change status on chatlistitem when status changes failed
|
|
||||||
"""
|
|
||||||
(alice,) = acfactory.get_online_accounts(1)
|
|
||||||
|
|
||||||
invalid_contact = alice.create_contact("example@example.com", "invalid address")
|
|
||||||
invalid_chat = alice.get_chat_by_id(alice._rpc.create_chat_by_contact_id(alice.id, invalid_contact.id))
|
|
||||||
|
|
||||||
alice.clear_all_events()
|
|
||||||
|
|
||||||
failing_message = invalid_chat.send_text("test")
|
|
||||||
|
|
||||||
wait_for_chatlist_and_specific_item(alice, invalid_chat.id)
|
|
||||||
|
|
||||||
assert failing_message.get_snapshot().state == const.MessageState.OUT_PENDING
|
|
||||||
|
|
||||||
while True:
|
|
||||||
event = alice.wait_for_event()
|
|
||||||
if event.kind == EventType.MSG_FAILED:
|
|
||||||
break
|
|
||||||
|
|
||||||
wait_for_chatlist_specific_item(alice, invalid_chat.id)
|
|
||||||
|
|
||||||
assert failing_message.get_snapshot().state == const.MessageState.OUT_FAILED
|
|
||||||
|
|
||||||
|
|
||||||
def test_download_on_demand(acfactory: ACFactory) -> None:
|
|
||||||
"""
|
|
||||||
Test if download on demand emits chatlist update events.
|
|
||||||
This is only needed for last message in chat, but finding that out is too expensive, so it's always emitted
|
|
||||||
"""
|
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
|
||||||
|
|
||||||
bob_addr = bob.get_config("addr")
|
|
||||||
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
|
|
||||||
alice_chat_bob = alice_contact_bob.create_chat()
|
|
||||||
alice_chat_bob.send_text("hi")
|
|
||||||
|
|
||||||
alice.set_config("download_limit", "1")
|
|
||||||
|
|
||||||
msg = bob.wait_for_incoming_msg()
|
|
||||||
chat_id = msg.get_snapshot().chat_id
|
|
||||||
msg.get_snapshot().chat.accept()
|
|
||||||
bob.get_chat_by_id(chat_id).send_message(
|
|
||||||
"Hello World, this message is bigger than 5 bytes",
|
|
||||||
html=base64.b64encode(os.urandom(300000)).decode("utf-8"),
|
|
||||||
)
|
|
||||||
|
|
||||||
message = alice.wait_for_incoming_msg()
|
|
||||||
snapshot = message.get_snapshot()
|
|
||||||
assert snapshot.download_state == const.DownloadState.AVAILABLE
|
|
||||||
|
|
||||||
alice.clear_all_events()
|
|
||||||
|
|
||||||
snapshot = message.get_snapshot()
|
|
||||||
chat_id = snapshot.chat_id
|
|
||||||
alice._rpc.download_full_message(alice.id, message.id)
|
|
||||||
|
|
||||||
wait_for_chatlist_specific_item(alice, chat_id)
|
|
||||||
|
|
||||||
|
|
||||||
def get_multi_account_test_setup(acfactory: ACFactory) -> [Account, Account, Account]:
|
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
|
||||||
|
|
||||||
bob_addr = bob.get_config("addr")
|
|
||||||
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
|
|
||||||
alice_chat_bob = alice_contact_bob.create_chat()
|
|
||||||
alice_chat_bob.send_text("hi")
|
|
||||||
|
|
||||||
bob.wait_for_incoming_msg_event()
|
|
||||||
|
|
||||||
alice_second_device: Account = acfactory.get_unconfigured_account()
|
|
||||||
|
|
||||||
alice._rpc.provide_backup.future(alice.id)
|
|
||||||
backup_code = alice._rpc.get_backup_qr(alice.id)
|
|
||||||
alice_second_device._rpc.get_backup(alice_second_device.id, backup_code)
|
|
||||||
alice_second_device.start_io()
|
|
||||||
alice.clear_all_events()
|
|
||||||
alice_second_device.clear_all_events()
|
|
||||||
bob.clear_all_events()
|
|
||||||
return [alice, alice_second_device, bob, alice_chat_bob]
|
|
||||||
|
|
||||||
|
|
||||||
def test_imap_sync_seen_msgs(acfactory: ACFactory) -> None:
|
|
||||||
"""
|
|
||||||
Test that chatlist changed events are emitted for the second device
|
|
||||||
when the message is marked as read on the first device
|
|
||||||
"""
|
|
||||||
alice, alice_second_device, bob, alice_chat_bob = get_multi_account_test_setup(acfactory)
|
|
||||||
|
|
||||||
alice_chat_bob.send_text("hello")
|
|
||||||
|
|
||||||
msg = bob.wait_for_incoming_msg()
|
|
||||||
bob_chat_id = msg.get_snapshot().chat_id
|
|
||||||
msg.get_snapshot().chat.accept()
|
|
||||||
|
|
||||||
alice.clear_all_events()
|
|
||||||
alice_second_device.clear_all_events()
|
|
||||||
bob.get_chat_by_id(bob_chat_id).send_text("hello")
|
|
||||||
|
|
||||||
# make sure alice_second_device already received the message
|
|
||||||
alice_second_device.wait_for_incoming_msg_event()
|
|
||||||
|
|
||||||
msg = alice.wait_for_incoming_msg()
|
|
||||||
alice_second_device.clear_all_events()
|
|
||||||
msg.mark_seen()
|
|
||||||
|
|
||||||
wait_for_chatlist_specific_item(bob, bob_chat_id)
|
|
||||||
wait_for_chatlist_specific_item(alice, alice_chat_bob.id)
|
|
||||||
|
|
||||||
|
|
||||||
def test_multidevice_sync_chat(acfactory: ACFactory) -> None:
|
|
||||||
"""
|
|
||||||
Test multidevice sync: syncing chat visibility and muting across multiple devices
|
|
||||||
"""
|
|
||||||
alice, alice_second_device, bob, alice_chat_bob = get_multi_account_test_setup(acfactory)
|
|
||||||
|
|
||||||
alice_chat_bob.archive()
|
|
||||||
wait_for_chatlist_specific_item(alice_second_device, alice_chat_bob.id)
|
|
||||||
assert alice_second_device.get_chat_by_id(alice_chat_bob.id).get_basic_snapshot().archived
|
|
||||||
|
|
||||||
alice_second_device.clear_all_events()
|
|
||||||
alice_chat_bob.pin()
|
|
||||||
wait_for_chatlist_specific_item(alice_second_device, alice_chat_bob.id)
|
|
||||||
assert alice_second_device.get_chat_by_id(alice_chat_bob.id).get_basic_snapshot().pinned
|
|
||||||
|
|
||||||
alice_second_device.clear_all_events()
|
|
||||||
alice_chat_bob.mute()
|
|
||||||
wait_for_chatlist_specific_item(alice_second_device, alice_chat_bob.id)
|
|
||||||
assert alice_second_device.get_chat_by_id(alice_chat_bob.id).get_basic_snapshot().is_muted
|
|
||||||
@@ -1,210 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Testing webxdc iroh connectivity
|
|
||||||
|
|
||||||
If you want to debug iroh at rust-trace/log level set
|
|
||||||
|
|
||||||
RUST_LOG=iroh_net=trace,iroh_gossip=trace
|
|
||||||
"""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
|
|
||||||
import pytest
|
|
||||||
|
|
||||||
from deltachat_rpc_client import EventType
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def path_to_webxdc(request):
|
|
||||||
p = request.path.parent.parent.parent.joinpath("test-data/webxdc/chess.xdc")
|
|
||||||
assert p.exists()
|
|
||||||
return str(p)
|
|
||||||
|
|
||||||
|
|
||||||
def log(msg):
|
|
||||||
print()
|
|
||||||
print("*" * 80 + "\n" + msg + "\n", file=sys.stderr)
|
|
||||||
print()
|
|
||||||
|
|
||||||
|
|
||||||
def setup_realtime_webxdc(ac1, ac2, path_to_webxdc):
|
|
||||||
assert ac1.get_config("webxdc_realtime_enabled") == "1"
|
|
||||||
assert ac2.get_config("webxdc_realtime_enabled") == "1"
|
|
||||||
ac1_ac2_chat = ac1.create_chat(ac2)
|
|
||||||
ac2.create_chat(ac1)
|
|
||||||
|
|
||||||
# share a webxdc app between ac1 and ac2
|
|
||||||
ac1_webxdc_msg = ac1_ac2_chat.send_message(text="play", file=path_to_webxdc)
|
|
||||||
ac2_webxdc_msg = ac2.wait_for_incoming_msg()
|
|
||||||
assert ac2_webxdc_msg.get_snapshot().text == "play"
|
|
||||||
|
|
||||||
# send iroh announcements simultaneously
|
|
||||||
log("sending ac1 -> ac2 realtime advertisement and additional message")
|
|
||||||
ac1_webxdc_msg.send_webxdc_realtime_advertisement()
|
|
||||||
|
|
||||||
log("sending ac2 -> ac1 realtime advertisement and additional message")
|
|
||||||
ac2_webxdc_msg.send_webxdc_realtime_advertisement()
|
|
||||||
|
|
||||||
return ac1_webxdc_msg, ac2_webxdc_msg
|
|
||||||
|
|
||||||
|
|
||||||
def setup_thread_send_realtime_data(msg, data):
|
|
||||||
def thread_run():
|
|
||||||
for _i in range(10):
|
|
||||||
msg.send_webxdc_realtime_data(data)
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
threading.Thread(target=thread_run, daemon=True).start()
|
|
||||||
|
|
||||||
|
|
||||||
def wait_receive_realtime_data(msg_data_list):
|
|
||||||
account = msg_data_list[0][0].account
|
|
||||||
msg_data_list = msg_data_list[:]
|
|
||||||
|
|
||||||
log(f"account {account.id}: waiting for realtime data {msg_data_list}")
|
|
||||||
while msg_data_list:
|
|
||||||
event = account.wait_for_event()
|
|
||||||
if event.kind == EventType.WEBXDC_REALTIME_DATA:
|
|
||||||
for i, (msg, data) in enumerate(msg_data_list):
|
|
||||||
if msg.id == event.msg_id:
|
|
||||||
assert list(data) == event.data
|
|
||||||
log(f"msg {msg.id}: got correct realtime data {data}")
|
|
||||||
del msg_data_list[i]
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def test_realtime_sequentially(acfactory, path_to_webxdc):
|
|
||||||
"""Test two peers trying to establish connection sequentially."""
|
|
||||||
ac1, ac2 = acfactory.get_online_accounts(2)
|
|
||||||
ac1.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
ac2.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
ac1.create_chat(ac2)
|
|
||||||
ac2.create_chat(ac1)
|
|
||||||
|
|
||||||
# share a webxdc app between ac1 and ac2
|
|
||||||
ac1_webxdc_msg = acfactory.send_message(from_account=ac1, to_account=ac2, text="play", file=path_to_webxdc)
|
|
||||||
ac2_webxdc_msg = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id)
|
|
||||||
snapshot = ac2_webxdc_msg.get_snapshot()
|
|
||||||
assert snapshot.text == "play"
|
|
||||||
|
|
||||||
# send iroh announcements sequentially
|
|
||||||
log("sending ac1 -> ac2 realtime advertisement and additional message")
|
|
||||||
ac1_webxdc_msg.send_webxdc_realtime_advertisement()
|
|
||||||
acfactory.send_message(from_account=ac1, to_account=ac2, text="ping1")
|
|
||||||
|
|
||||||
log("waiting for incoming message on ac2")
|
|
||||||
snapshot = ac2.get_message_by_id(ac2.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
|
||||||
assert snapshot.text == "ping1"
|
|
||||||
|
|
||||||
log("sending ac2 -> ac1 realtime advertisement and additional message")
|
|
||||||
ac2_webxdc_msg.send_webxdc_realtime_advertisement()
|
|
||||||
acfactory.send_message(from_account=ac2, to_account=ac1, text="ping2")
|
|
||||||
|
|
||||||
log("waiting for incoming message on ac1")
|
|
||||||
snapshot = ac1.get_message_by_id(ac1.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
|
||||||
assert snapshot.text == "ping2"
|
|
||||||
|
|
||||||
log("sending realtime data ac1 -> ac2")
|
|
||||||
ac1_webxdc_msg.send_webxdc_realtime_data(b"foo")
|
|
||||||
|
|
||||||
log("ac2: waiting for realtime data")
|
|
||||||
while 1:
|
|
||||||
event = ac2.wait_for_event()
|
|
||||||
if event.kind == EventType.WEBXDC_REALTIME_DATA:
|
|
||||||
assert event.data == list(b"foo")
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def test_realtime_simultaneously(acfactory, path_to_webxdc):
|
|
||||||
"""Test two peers trying to establish connection simultaneously."""
|
|
||||||
ac1, ac2 = acfactory.get_online_accounts(2)
|
|
||||||
ac1.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
ac2.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
|
|
||||||
ac1_webxdc_msg, ac2_webxdc_msg = setup_realtime_webxdc(ac1, ac2, path_to_webxdc)
|
|
||||||
|
|
||||||
setup_thread_send_realtime_data(ac1_webxdc_msg, [10])
|
|
||||||
wait_receive_realtime_data([(ac2_webxdc_msg, [10])])
|
|
||||||
|
|
||||||
|
|
||||||
def test_two_parallel_realtime_simultaneously(acfactory, path_to_webxdc):
|
|
||||||
"""Test two peers trying to establish connection simultaneously."""
|
|
||||||
ac1, ac2 = acfactory.get_online_accounts(2)
|
|
||||||
ac1.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
ac2.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
|
|
||||||
ac1_webxdc_msg, ac2_webxdc_msg = setup_realtime_webxdc(ac1, ac2, path_to_webxdc)
|
|
||||||
ac1_webxdc_msg2, ac2_webxdc_msg2 = setup_realtime_webxdc(ac1, ac2, path_to_webxdc)
|
|
||||||
|
|
||||||
setup_thread_send_realtime_data(ac1_webxdc_msg, [10])
|
|
||||||
setup_thread_send_realtime_data(ac1_webxdc_msg2, [20])
|
|
||||||
setup_thread_send_realtime_data(ac2_webxdc_msg, [30])
|
|
||||||
setup_thread_send_realtime_data(ac2_webxdc_msg2, [40])
|
|
||||||
|
|
||||||
wait_receive_realtime_data([(ac1_webxdc_msg, [30]), (ac1_webxdc_msg2, [40])])
|
|
||||||
wait_receive_realtime_data([(ac2_webxdc_msg, [10]), (ac2_webxdc_msg2, [20])])
|
|
||||||
|
|
||||||
|
|
||||||
def test_no_duplicate_messages(acfactory, path_to_webxdc):
|
|
||||||
"""Test that messages are received only once."""
|
|
||||||
ac1, ac2 = acfactory.get_online_accounts(2)
|
|
||||||
ac1.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
ac2.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
|
|
||||||
ac1_ac2_chat = ac1.create_chat(ac2)
|
|
||||||
|
|
||||||
ac1_webxdc_msg = ac1_ac2_chat.send_message(text="webxdc", file=path_to_webxdc)
|
|
||||||
|
|
||||||
ac2_webxdc_msg = ac2.wait_for_incoming_msg()
|
|
||||||
ac2_webxdc_msg.get_snapshot().chat.accept()
|
|
||||||
assert ac2_webxdc_msg.get_snapshot().text == "webxdc"
|
|
||||||
|
|
||||||
# Issue a "send" call in parallel with sending advertisement.
|
|
||||||
# Previously due to a bug this caused subscribing to the channel twice.
|
|
||||||
ac2_webxdc_msg.send_webxdc_realtime_data.future(b"foobar")
|
|
||||||
ac2_webxdc_msg.send_webxdc_realtime_advertisement()
|
|
||||||
|
|
||||||
def thread_run():
|
|
||||||
for i in range(10):
|
|
||||||
data = str(i).encode()
|
|
||||||
ac1_webxdc_msg.send_webxdc_realtime_data(data)
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
threading.Thread(target=thread_run, daemon=True).start()
|
|
||||||
|
|
||||||
while 1:
|
|
||||||
event = ac2.wait_for_event()
|
|
||||||
if event.kind == EventType.WEBXDC_REALTIME_DATA:
|
|
||||||
n = int(bytes(event.data).decode())
|
|
||||||
break
|
|
||||||
|
|
||||||
while 1:
|
|
||||||
event = ac2.wait_for_event()
|
|
||||||
if event.kind == EventType.WEBXDC_REALTIME_DATA:
|
|
||||||
assert int(bytes(event.data).decode()) > n
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def test_no_reordering(acfactory, path_to_webxdc):
|
|
||||||
"""Test that sending a lot of realtime messages does not result in reordering."""
|
|
||||||
ac1, ac2 = acfactory.get_online_accounts(2)
|
|
||||||
ac1.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
ac2.set_config("webxdc_realtime_enabled", "1")
|
|
||||||
|
|
||||||
ac1_webxdc_msg, ac2_webxdc_msg = setup_realtime_webxdc(ac1, ac2, path_to_webxdc)
|
|
||||||
|
|
||||||
setup_thread_send_realtime_data(ac1_webxdc_msg, b"hello")
|
|
||||||
wait_receive_realtime_data([(ac2_webxdc_msg, b"hello")])
|
|
||||||
|
|
||||||
for i in range(200):
|
|
||||||
ac1_webxdc_msg.send_webxdc_realtime_data([i])
|
|
||||||
|
|
||||||
for i in range(200):
|
|
||||||
while 1:
|
|
||||||
event = ac2.wait_for_event()
|
|
||||||
if event.kind == EventType.WEBXDC_REALTIME_DATA and bytes(event.data) != b"hello":
|
|
||||||
if event.data[0] == i:
|
|
||||||
break
|
|
||||||
pytest.fail("Reordering detected")
|
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from deltachat_rpc_client import Chat, EventType, SpecialContactId
|
from deltachat_rpc_client import Chat, EventType, SpecialContactId
|
||||||
|
|
||||||
|
|
||||||
def test_qr_setup_contact(acfactory, tmp_path) -> None:
|
def test_qr_setup_contact(acfactory, tmp_path) -> None:
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
alice, bob = acfactory.get_online_accounts(2)
|
||||||
|
|
||||||
qr_code = alice.get_qr_code()
|
qr_code, _svg = alice.get_qr_code()
|
||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
|
|
||||||
alice.wait_for_securejoin_inviter_success()
|
alice.wait_for_securejoin_inviter_success()
|
||||||
@@ -31,52 +30,23 @@ def test_qr_setup_contact(acfactory, tmp_path) -> None:
|
|||||||
bob2.export_self_keys(tmp_path)
|
bob2.export_self_keys(tmp_path)
|
||||||
|
|
||||||
logging.info("Bob imports a key")
|
logging.info("Bob imports a key")
|
||||||
bob.import_self_keys(tmp_path)
|
bob.import_self_keys(tmp_path / "private-key-default.asc")
|
||||||
|
|
||||||
assert bob.get_config("key_id") == "2"
|
assert bob.get_config("key_id") == "2"
|
||||||
bob_contact_alice_snapshot = bob_contact_alice.get_snapshot()
|
bob_contact_alice_snapshot = bob_contact_alice.get_snapshot()
|
||||||
assert not bob_contact_alice_snapshot.is_verified
|
assert not bob_contact_alice_snapshot.is_verified
|
||||||
|
|
||||||
|
|
||||||
def test_qr_setup_contact_svg(acfactory) -> None:
|
|
||||||
alice = acfactory.new_configured_account()
|
|
||||||
_, _, domain = alice.get_config("addr").rpartition("@")
|
|
||||||
|
|
||||||
_qr_code, svg = alice.get_qr_code_svg()
|
|
||||||
|
|
||||||
# Test that email address is in SVG
|
|
||||||
# when we have no display name.
|
|
||||||
# Check only the domain name, because
|
|
||||||
# long address may be split over multiple lines
|
|
||||||
# and not matched.
|
|
||||||
assert domain in svg
|
|
||||||
|
|
||||||
alice.set_config("displayname", "Alice")
|
|
||||||
|
|
||||||
# Test that display name is used
|
|
||||||
# in SVG and no address is visible.
|
|
||||||
_qr_code, svg = alice.get_qr_code_svg()
|
|
||||||
assert domain not in svg
|
|
||||||
assert "Alice" in svg
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("protect", [True, False])
|
@pytest.mark.parametrize("protect", [True, False])
|
||||||
def test_qr_securejoin(acfactory, protect, tmp_path):
|
def test_qr_securejoin(acfactory, protect):
|
||||||
alice, bob, fiona = acfactory.get_online_accounts(3)
|
alice, bob = acfactory.get_online_accounts(2)
|
||||||
|
|
||||||
# Setup second device for Alice
|
logging.info("Alice creates a verified group")
|
||||||
# to test observing securejoin protocol.
|
alice_chat = alice.create_group("Verified group", protect=protect)
|
||||||
alice.export_backup(tmp_path)
|
|
||||||
files = list(tmp_path.glob("*.tar"))
|
|
||||||
alice2 = acfactory.get_unconfigured_account()
|
|
||||||
alice2.import_backup(files[0])
|
|
||||||
|
|
||||||
logging.info("Alice creates a group")
|
|
||||||
alice_chat = alice.create_group("Group", protect=protect)
|
|
||||||
assert alice_chat.get_basic_snapshot().is_protected == protect
|
assert alice_chat.get_basic_snapshot().is_protected == protect
|
||||||
|
|
||||||
logging.info("Bob joins the group")
|
logging.info("Bob joins verified group")
|
||||||
qr_code = alice_chat.get_qr_code()
|
qr_code, _svg = alice_chat.get_qr_code()
|
||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
|
|
||||||
# Check that at least some of the handshake messages are deleted.
|
# Check that at least some of the handshake messages are deleted.
|
||||||
@@ -104,21 +74,6 @@ def test_qr_securejoin(acfactory, protect, tmp_path):
|
|||||||
bob_contact_alice_snapshot = bob_contact_alice.get_snapshot()
|
bob_contact_alice_snapshot = bob_contact_alice.get_snapshot()
|
||||||
assert bob_contact_alice_snapshot.is_verified
|
assert bob_contact_alice_snapshot.is_verified
|
||||||
|
|
||||||
# Start second Alice device.
|
|
||||||
# Alice observes securejoin protocol and verifies Bob on second device.
|
|
||||||
alice2.start_io()
|
|
||||||
alice2.wait_for_securejoin_inviter_success()
|
|
||||||
alice2_contact_bob = alice2.get_contact_by_addr(bob.get_config("addr"))
|
|
||||||
alice2_contact_bob_snapshot = alice2_contact_bob.get_snapshot()
|
|
||||||
assert alice2_contact_bob_snapshot.is_verified
|
|
||||||
|
|
||||||
# The QR code token is synced, so alice2 must be able to handle join requests.
|
|
||||||
logging.info("Fiona joins the group via alice2")
|
|
||||||
alice.stop_io()
|
|
||||||
fiona.secure_join(qr_code)
|
|
||||||
alice2.wait_for_securejoin_inviter_success()
|
|
||||||
fiona.wait_for_securejoin_joiner_success()
|
|
||||||
|
|
||||||
|
|
||||||
def test_qr_securejoin_contact_request(acfactory) -> None:
|
def test_qr_securejoin_contact_request(acfactory) -> None:
|
||||||
"""Alice invites Bob to a group when Bob's chat with Alice is in a contact request mode."""
|
"""Alice invites Bob to a group when Bob's chat with Alice is in a contact request mode."""
|
||||||
@@ -136,7 +91,7 @@ def test_qr_securejoin_contact_request(acfactory) -> None:
|
|||||||
|
|
||||||
alice_chat = alice.create_group("Verified group", protect=True)
|
alice_chat = alice.create_group("Verified group", protect=True)
|
||||||
logging.info("Bob joins verified group")
|
logging.info("Bob joins verified group")
|
||||||
qr_code = alice_chat.get_qr_code()
|
qr_code, _svg = alice_chat.get_qr_code()
|
||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
while True:
|
while True:
|
||||||
event = bob.wait_for_event()
|
event = bob.wait_for_event()
|
||||||
@@ -151,7 +106,7 @@ def test_qr_readreceipt(acfactory) -> None:
|
|||||||
alice, bob, charlie = acfactory.get_online_accounts(3)
|
alice, bob, charlie = acfactory.get_online_accounts(3)
|
||||||
|
|
||||||
logging.info("Bob and Charlie setup contact with Alice")
|
logging.info("Bob and Charlie setup contact with Alice")
|
||||||
qr_code = alice.get_qr_code()
|
qr_code, _svg = alice.get_qr_code()
|
||||||
|
|
||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
charlie.secure_join(qr_code)
|
charlie.secure_join(qr_code)
|
||||||
@@ -213,13 +168,13 @@ def test_setup_contact_resetup(acfactory) -> None:
|
|||||||
"""Tests that setup contact works after Alice resets the device and changes the key."""
|
"""Tests that setup contact works after Alice resets the device and changes the key."""
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
alice, bob = acfactory.get_online_accounts(2)
|
||||||
|
|
||||||
qr_code = alice.get_qr_code()
|
qr_code, _svg = alice.get_qr_code()
|
||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
bob.wait_for_securejoin_joiner_success()
|
bob.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
alice = acfactory.resetup_account(alice)
|
alice = acfactory.resetup_account(alice)
|
||||||
|
|
||||||
qr_code = alice.get_qr_code()
|
qr_code, _svg = alice.get_qr_code()
|
||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
bob.wait_for_securejoin_joiner_success()
|
bob.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
@@ -233,7 +188,7 @@ def test_verified_group_recovery(acfactory) -> None:
|
|||||||
assert chat.get_basic_snapshot().is_protected
|
assert chat.get_basic_snapshot().is_protected
|
||||||
|
|
||||||
logging.info("ac2 joins verified group")
|
logging.info("ac2 joins verified group")
|
||||||
qr_code = chat.get_qr_code()
|
qr_code, _svg = chat.get_qr_code()
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
ac2.wait_for_securejoin_joiner_success()
|
ac2.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
@@ -250,7 +205,7 @@ def test_verified_group_recovery(acfactory) -> None:
|
|||||||
ac2 = acfactory.resetup_account(ac2)
|
ac2 = acfactory.resetup_account(ac2)
|
||||||
|
|
||||||
logging.info("ac2 reverifies with ac3")
|
logging.info("ac2 reverifies with ac3")
|
||||||
qr_code = ac3.get_qr_code()
|
qr_code, _svg = ac3.get_qr_code()
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
ac2.wait_for_securejoin_joiner_success()
|
ac2.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
@@ -297,7 +252,7 @@ def test_verified_group_member_added_recovery(acfactory) -> None:
|
|||||||
assert chat.get_basic_snapshot().is_protected
|
assert chat.get_basic_snapshot().is_protected
|
||||||
|
|
||||||
logging.info("ac2 joins verified group")
|
logging.info("ac2 joins verified group")
|
||||||
qr_code = chat.get_qr_code()
|
qr_code, _svg = chat.get_qr_code()
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
ac2.wait_for_securejoin_joiner_success()
|
ac2.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
@@ -314,7 +269,7 @@ def test_verified_group_member_added_recovery(acfactory) -> None:
|
|||||||
ac2 = acfactory.resetup_account(ac2)
|
ac2 = acfactory.resetup_account(ac2)
|
||||||
|
|
||||||
logging.info("ac2 reverifies with ac3")
|
logging.info("ac2 reverifies with ac3")
|
||||||
qr_code = ac3.get_qr_code()
|
qr_code, _svg = ac3.get_qr_code()
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
ac2.wait_for_securejoin_joiner_success()
|
ac2.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
@@ -381,7 +336,7 @@ def test_qr_join_chat_with_pending_bobstate_issue4894(acfactory):
|
|||||||
ac1, ac2, ac3, ac4 = acfactory.get_online_accounts(4)
|
ac1, ac2, ac3, ac4 = acfactory.get_online_accounts(4)
|
||||||
|
|
||||||
logging.info("ac3: verify with ac2")
|
logging.info("ac3: verify with ac2")
|
||||||
qr_code = ac2.get_qr_code()
|
qr_code, _svg = ac2.get_qr_code()
|
||||||
ac3.secure_join(qr_code)
|
ac3.secure_join(qr_code)
|
||||||
ac2.wait_for_securejoin_inviter_success()
|
ac2.wait_for_securejoin_inviter_success()
|
||||||
|
|
||||||
@@ -391,7 +346,7 @@ def test_qr_join_chat_with_pending_bobstate_issue4894(acfactory):
|
|||||||
|
|
||||||
logging.info("ac1: create verified group that ac2 fully joins")
|
logging.info("ac1: create verified group that ac2 fully joins")
|
||||||
ch1 = ac1.create_group("Group", protect=True)
|
ch1 = ac1.create_group("Group", protect=True)
|
||||||
qr_code = ch1.get_qr_code()
|
qr_code, _svg = ch1.get_qr_code()
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
ac1.wait_for_securejoin_inviter_success()
|
ac1.wait_for_securejoin_inviter_success()
|
||||||
|
|
||||||
@@ -404,7 +359,7 @@ def test_qr_join_chat_with_pending_bobstate_issue4894(acfactory):
|
|||||||
break
|
break
|
||||||
|
|
||||||
logging.info("ac1: let ac2 join again but shutoff ac1 in the middle of securejoin")
|
logging.info("ac1: let ac2 join again but shutoff ac1 in the middle of securejoin")
|
||||||
qr_code = ch1.get_qr_code()
|
qr_code, _svg = ch1.get_qr_code()
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
ac1.remove()
|
ac1.remove()
|
||||||
logging.info("ac2 now has pending bobstate but ac1 is shutoff")
|
logging.info("ac2 now has pending bobstate but ac1 is shutoff")
|
||||||
@@ -426,7 +381,7 @@ def test_qr_join_chat_with_pending_bobstate_issue4894(acfactory):
|
|||||||
break
|
break
|
||||||
|
|
||||||
logging.info("ac3: create a join-code for group VG and let ac4 join, check that ac2 got it")
|
logging.info("ac3: create a join-code for group VG and let ac4 join, check that ac2 got it")
|
||||||
qr_code = vg.get_qr_code()
|
qr_code, _svg = vg.get_qr_code()
|
||||||
ac4.secure_join(qr_code)
|
ac4.secure_join(qr_code)
|
||||||
ac3.wait_for_securejoin_inviter_success()
|
ac3.wait_for_securejoin_inviter_success()
|
||||||
while 1:
|
while 1:
|
||||||
@@ -447,7 +402,7 @@ def test_qr_new_group_unblocked(acfactory):
|
|||||||
|
|
||||||
ac1, ac2 = acfactory.get_online_accounts(2)
|
ac1, ac2 = acfactory.get_online_accounts(2)
|
||||||
ac1_chat = ac1.create_group("Group for joining", protect=True)
|
ac1_chat = ac1.create_group("Group for joining", protect=True)
|
||||||
qr_code = ac1_chat.get_qr_code()
|
qr_code, _svg = ac1_chat.get_qr_code()
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
|
|
||||||
ac1.wait_for_securejoin_inviter_success()
|
ac1.wait_for_securejoin_inviter_success()
|
||||||
@@ -470,7 +425,7 @@ def test_aeap_flow_verified(acfactory):
|
|||||||
logging.info("ac1: create verified-group QR, ac2 scans and joins")
|
logging.info("ac1: create verified-group QR, ac2 scans and joins")
|
||||||
chat = ac1.create_group("hello", protect=True)
|
chat = ac1.create_group("hello", protect=True)
|
||||||
assert chat.get_basic_snapshot().is_protected
|
assert chat.get_basic_snapshot().is_protected
|
||||||
qr_code = chat.get_qr_code()
|
qr_code, _svg = chat.get_qr_code()
|
||||||
logging.info("ac2: start QR-code based join-group protocol")
|
logging.info("ac2: start QR-code based join-group protocol")
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
ac1.wait_for_securejoin_inviter_success()
|
ac1.wait_for_securejoin_inviter_success()
|
||||||
@@ -509,12 +464,12 @@ def test_gossip_verification(acfactory) -> None:
|
|||||||
alice, bob, carol = acfactory.get_online_accounts(3)
|
alice, bob, carol = acfactory.get_online_accounts(3)
|
||||||
|
|
||||||
# Bob verifies Alice.
|
# Bob verifies Alice.
|
||||||
qr_code = alice.get_qr_code()
|
qr_code, _svg = alice.get_qr_code()
|
||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
bob.wait_for_securejoin_joiner_success()
|
bob.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
# Bob verifies Carol.
|
# Bob verifies Carol.
|
||||||
qr_code = carol.get_qr_code()
|
qr_code, _svg = carol.get_qr_code()
|
||||||
bob.secure_join(qr_code)
|
bob.secure_join(qr_code)
|
||||||
bob.wait_for_securejoin_joiner_success()
|
bob.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
@@ -565,16 +520,16 @@ def test_securejoin_after_contact_resetup(acfactory) -> None:
|
|||||||
ac3_chat = ac3.create_group("Verified group", protect=True)
|
ac3_chat = ac3.create_group("Verified group", protect=True)
|
||||||
|
|
||||||
# ac1 joins ac3 group.
|
# ac1 joins ac3 group.
|
||||||
ac3_qr_code = ac3_chat.get_qr_code()
|
ac3_qr_code, _svg = ac3_chat.get_qr_code()
|
||||||
ac1.secure_join(ac3_qr_code)
|
ac1.secure_join(ac3_qr_code)
|
||||||
ac1.wait_for_securejoin_joiner_success()
|
ac1.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
# ac1 waits for member added message and creates a QR code.
|
# ac1 waits for member added message and creates a QR code.
|
||||||
snapshot = ac1.get_message_by_id(ac1.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
snapshot = ac1.get_message_by_id(ac1.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
||||||
ac1_qr_code = snapshot.chat.get_qr_code()
|
ac1_qr_code, _svg = snapshot.chat.get_qr_code()
|
||||||
|
|
||||||
# ac2 verifies ac1
|
# ac2 verifies ac1
|
||||||
qr_code = ac1.get_qr_code()
|
qr_code, _svg = ac1.get_qr_code()
|
||||||
ac2.secure_join(qr_code)
|
ac2.secure_join(qr_code)
|
||||||
ac2.wait_for_securejoin_joiner_success()
|
ac2.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
@@ -634,7 +589,7 @@ def test_withdraw_securejoin_qr(acfactory):
|
|||||||
assert alice_chat.get_basic_snapshot().is_protected
|
assert alice_chat.get_basic_snapshot().is_protected
|
||||||
logging.info("Bob joins verified group")
|
logging.info("Bob joins verified group")
|
||||||
|
|
||||||
qr_code = alice_chat.get_qr_code()
|
qr_code, _svg = alice_chat.get_qr_code()
|
||||||
bob_chat = bob.secure_join(qr_code)
|
bob_chat = bob.secure_join(qr_code)
|
||||||
bob.wait_for_securejoin_joiner_success()
|
bob.wait_for_securejoin_joiner_success()
|
||||||
|
|
||||||
@@ -657,8 +612,7 @@ def test_withdraw_securejoin_qr(acfactory):
|
|||||||
logging.info("Bob scanned withdrawn QR code")
|
logging.info("Bob scanned withdrawn QR code")
|
||||||
while True:
|
while True:
|
||||||
event = alice.wait_for_event()
|
event = alice.wait_for_event()
|
||||||
if (
|
if event.kind == EventType.MSGS_CHANGED and event.chat_id != 0:
|
||||||
event.kind == EventType.WARNING
|
|
||||||
and "Ignoring vg-request-with-auth message because of invalid auth code." in event.msg
|
|
||||||
):
|
|
||||||
break
|
break
|
||||||
|
snapshot = alice.get_message_by_id(event.msg_id).get_snapshot()
|
||||||
|
assert snapshot.text == "Cannot establish guaranteed end-to-end encryption with {}".format(bob.get_config("addr"))
|
||||||
|
|||||||
@@ -1,18 +1,10 @@
|
|||||||
import base64
|
|
||||||
import concurrent.futures
|
import concurrent.futures
|
||||||
import json
|
import json
|
||||||
import logging
|
|
||||||
import os
|
|
||||||
import socket
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from deltachat_rpc_client import EventType, events
|
||||||
from deltachat_rpc_client import Contact, EventType, Message, events
|
|
||||||
from deltachat_rpc_client.const import DownloadState, MessageState
|
|
||||||
from deltachat_rpc_client.direct_imap import DirectImap
|
|
||||||
from deltachat_rpc_client.rpc import JsonRpcError
|
from deltachat_rpc_client.rpc import JsonRpcError
|
||||||
|
|
||||||
|
|
||||||
@@ -71,38 +63,6 @@ def test_configure_starttls(acfactory) -> None:
|
|||||||
assert account.is_configured()
|
assert account.is_configured()
|
||||||
|
|
||||||
|
|
||||||
def test_configure_ip(acfactory) -> None:
|
|
||||||
account = acfactory.new_preconfigured_account()
|
|
||||||
|
|
||||||
domain = account.get_config("addr").rsplit("@")[-1]
|
|
||||||
ip_address = socket.gethostbyname(domain)
|
|
||||||
|
|
||||||
# This should fail TLS check.
|
|
||||||
account.set_config("mail_server", ip_address)
|
|
||||||
with pytest.raises(JsonRpcError):
|
|
||||||
account.configure()
|
|
||||||
|
|
||||||
|
|
||||||
def test_configure_alternative_port(acfactory) -> None:
|
|
||||||
"""Test that configuration with alternative port 443 works."""
|
|
||||||
account = acfactory.new_preconfigured_account()
|
|
||||||
|
|
||||||
account.set_config("mail_port", "443")
|
|
||||||
account.set_config("send_port", "443")
|
|
||||||
|
|
||||||
account.configure()
|
|
||||||
|
|
||||||
|
|
||||||
def test_configure_username(acfactory) -> None:
|
|
||||||
account = acfactory.new_preconfigured_account()
|
|
||||||
|
|
||||||
addr = account.get_config("addr")
|
|
||||||
account.set_config("mail_user", addr)
|
|
||||||
account.configure()
|
|
||||||
|
|
||||||
assert account.get_config("configured_mail_user") == addr
|
|
||||||
|
|
||||||
|
|
||||||
def test_account(acfactory) -> None:
|
def test_account(acfactory) -> None:
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
alice, bob = acfactory.get_online_accounts(2)
|
||||||
|
|
||||||
@@ -138,12 +98,12 @@ def test_account(acfactory) -> None:
|
|||||||
assert alice.get_chatlist(snapshot=True)
|
assert alice.get_chatlist(snapshot=True)
|
||||||
assert alice.get_qr_code()
|
assert alice.get_qr_code()
|
||||||
assert alice.get_fresh_messages()
|
assert alice.get_fresh_messages()
|
||||||
|
assert alice.get_next_messages()
|
||||||
|
|
||||||
# Test sending empty message.
|
# Test sending empty message.
|
||||||
assert len(bob.wait_next_messages()) == 0
|
assert len(bob.wait_next_messages()) == 0
|
||||||
alice_chat_bob.send_text("")
|
alice_chat_bob.send_text("")
|
||||||
messages = bob.wait_next_messages()
|
messages = bob.wait_next_messages()
|
||||||
assert bob.get_next_messages() == messages
|
|
||||||
assert len(messages) == 1
|
assert len(messages) == 1
|
||||||
message = messages[0]
|
message = messages[0]
|
||||||
snapshot = message.get_snapshot()
|
snapshot = message.get_snapshot()
|
||||||
@@ -433,7 +393,7 @@ def test_provider_info(rpc) -> None:
|
|||||||
assert provider_info["id"] == "gmail"
|
assert provider_info["id"] == "gmail"
|
||||||
|
|
||||||
# Disable MX record resolution.
|
# Disable MX record resolution.
|
||||||
rpc.set_config(account_id, "proxy_enabled", "1")
|
rpc.set_config(account_id, "socks5_enabled", "1")
|
||||||
provider_info = rpc.get_provider_info(account_id, "github.com")
|
provider_info = rpc.get_provider_info(account_id, "github.com")
|
||||||
assert provider_info is None
|
assert provider_info is None
|
||||||
|
|
||||||
@@ -479,200 +439,3 @@ def test_mdn_doesnt_break_autocrypt(acfactory) -> None:
|
|||||||
message = alice.get_message_by_id(msg_id)
|
message = alice.get_message_by_id(msg_id)
|
||||||
snapshot = message.get_snapshot()
|
snapshot = message.get_snapshot()
|
||||||
assert snapshot.show_padlock
|
assert snapshot.show_padlock
|
||||||
|
|
||||||
|
|
||||||
def test_reaction_to_partially_fetched_msg(acfactory, tmp_path):
|
|
||||||
"""See https://github.com/deltachat/deltachat-core-rust/issues/3688 "Partially downloaded
|
|
||||||
messages are received out of order".
|
|
||||||
|
|
||||||
If the Inbox contains X small messages followed by Y large messages followed by Z small
|
|
||||||
messages, Delta Chat first downloaded a batch of X+Z messages, and then a batch of Y messages.
|
|
||||||
|
|
||||||
This bug was discovered by @Simon-Laux while testing reactions PR #3644 and can be reproduced
|
|
||||||
with online test as follows:
|
|
||||||
- Bob enables download limit and goes offline.
|
|
||||||
- Alice sends a large message to Bob and reacts to this message with a thumbs-up.
|
|
||||||
- Bob goes online
|
|
||||||
- Bob first processes a reaction message and throws it away because there is no corresponding
|
|
||||||
message, then processes a partially downloaded message.
|
|
||||||
- As a result, Bob does not see a reaction
|
|
||||||
"""
|
|
||||||
download_limit = 300000
|
|
||||||
ac1, ac2 = acfactory.get_online_accounts(2)
|
|
||||||
ac1_addr = ac1.get_config("addr")
|
|
||||||
chat = ac1.create_chat(ac2)
|
|
||||||
ac2.set_config("download_limit", str(download_limit))
|
|
||||||
ac2.stop_io()
|
|
||||||
|
|
||||||
logging.info("sending small+large messages from ac1 to ac2")
|
|
||||||
msgs = []
|
|
||||||
msgs.append(chat.send_text("hi"))
|
|
||||||
path = tmp_path / "large"
|
|
||||||
path.write_bytes(os.urandom(download_limit + 1))
|
|
||||||
msgs.append(chat.send_file(str(path)))
|
|
||||||
for m in msgs:
|
|
||||||
m.wait_until_delivered()
|
|
||||||
|
|
||||||
logging.info("sending a reaction to the large message from ac1 to ac2")
|
|
||||||
# TODO: Find the reason of an occasional message reordering on the server (so that the reaction
|
|
||||||
# has a lower UID than the previous message). W/a is to sleep for some time to let the reaction
|
|
||||||
# have a later INTERNALDATE.
|
|
||||||
time.sleep(1.1)
|
|
||||||
react_str = "\N{THUMBS UP SIGN}"
|
|
||||||
msgs.append(msgs[-1].send_reaction(react_str))
|
|
||||||
msgs[-1].wait_until_delivered()
|
|
||||||
|
|
||||||
ac2.start_io()
|
|
||||||
|
|
||||||
logging.info("wait for ac2 to receive a reaction")
|
|
||||||
msg2 = Message(ac2, ac2.wait_for_reactions_changed().msg_id)
|
|
||||||
assert msg2.get_sender_contact().get_snapshot().address == ac1_addr
|
|
||||||
assert msg2.get_snapshot().download_state == DownloadState.AVAILABLE
|
|
||||||
reactions = msg2.get_reactions()
|
|
||||||
contacts = [Contact(ac2, int(i)) for i in reactions.reactions_by_contact]
|
|
||||||
assert len(contacts) == 1
|
|
||||||
assert contacts[0].get_snapshot().address == ac1_addr
|
|
||||||
assert list(reactions.reactions_by_contact.values())[0] == [react_str]
|
|
||||||
|
|
||||||
|
|
||||||
def test_reactions_for_a_reordering_move(acfactory):
|
|
||||||
"""When a batch of messages is moved from Inbox to DeltaChat folder with a single MOVE command,
|
|
||||||
their UIDs may be reordered (e.g. Gmail is known for that) which led to that messages were
|
|
||||||
processed by receive_imf in the wrong order, and, particularly, reactions were processed before
|
|
||||||
messages they refer to and thus dropped.
|
|
||||||
"""
|
|
||||||
(ac1,) = acfactory.get_online_accounts(1)
|
|
||||||
ac2 = acfactory.new_preconfigured_account()
|
|
||||||
ac2.configure()
|
|
||||||
ac2.set_config("mvbox_move", "1")
|
|
||||||
ac2.bring_online()
|
|
||||||
chat1 = acfactory.get_accepted_chat(ac1, ac2)
|
|
||||||
ac2.stop_io()
|
|
||||||
|
|
||||||
logging.info("sending message + reaction from ac1 to ac2")
|
|
||||||
msg1 = chat1.send_text("hi")
|
|
||||||
msg1.wait_until_delivered()
|
|
||||||
# It's is sad, but messages must differ in their INTERNALDATEs to be processed in the correct
|
|
||||||
# order by DC, and most (if not all) mail servers provide only seconds precision.
|
|
||||||
time.sleep(1.1)
|
|
||||||
react_str = "\N{THUMBS UP SIGN}"
|
|
||||||
msg1.send_reaction(react_str).wait_until_delivered()
|
|
||||||
|
|
||||||
logging.info("moving messages to ac2's DeltaChat folder in the reverse order")
|
|
||||||
ac2_direct_imap = DirectImap(ac2)
|
|
||||||
ac2_direct_imap.connect()
|
|
||||||
for uid in sorted([m.uid for m in ac2_direct_imap.get_all_messages()], reverse=True):
|
|
||||||
ac2_direct_imap.conn.move(uid, "DeltaChat")
|
|
||||||
|
|
||||||
logging.info("receiving messages by ac2")
|
|
||||||
ac2.start_io()
|
|
||||||
msg2 = Message(ac2, ac2.wait_for_reactions_changed().msg_id)
|
|
||||||
assert msg2.get_snapshot().text == msg1.get_snapshot().text
|
|
||||||
reactions = msg2.get_reactions()
|
|
||||||
contacts = [Contact(ac2, int(i)) for i in reactions.reactions_by_contact]
|
|
||||||
assert len(contacts) == 1
|
|
||||||
assert contacts[0].get_snapshot().address == ac1.get_config("addr")
|
|
||||||
assert list(reactions.reactions_by_contact.values())[0] == [react_str]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("n_accounts", [3, 2])
|
|
||||||
def test_download_limit_chat_assignment(acfactory, tmp_path, n_accounts):
|
|
||||||
download_limit = 300000
|
|
||||||
|
|
||||||
alice, *others = acfactory.get_online_accounts(n_accounts)
|
|
||||||
bob = others[0]
|
|
||||||
|
|
||||||
alice_group = alice.create_group("test group")
|
|
||||||
for account in others:
|
|
||||||
chat = account.create_chat(alice)
|
|
||||||
chat.send_text("Hello Alice!")
|
|
||||||
assert alice.get_message_by_id(alice.wait_for_incoming_msg_event().msg_id).get_snapshot().text == "Hello Alice!"
|
|
||||||
|
|
||||||
contact_addr = account.get_config("addr")
|
|
||||||
contact = alice.create_contact(contact_addr, "")
|
|
||||||
|
|
||||||
alice_group.add_contact(contact)
|
|
||||||
|
|
||||||
if n_accounts == 2:
|
|
||||||
bob_chat_alice = bob.create_chat(alice)
|
|
||||||
bob.set_config("download_limit", str(download_limit))
|
|
||||||
|
|
||||||
alice_group.send_text("hi")
|
|
||||||
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
|
||||||
assert snapshot.text == "hi"
|
|
||||||
bob_group = snapshot.chat
|
|
||||||
|
|
||||||
path = tmp_path / "large"
|
|
||||||
path.write_bytes(os.urandom(download_limit + 1))
|
|
||||||
|
|
||||||
for i in range(10):
|
|
||||||
logging.info("Sending message %s", i)
|
|
||||||
alice_group.send_file(str(path))
|
|
||||||
snapshot = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id).get_snapshot()
|
|
||||||
assert snapshot.download_state == DownloadState.AVAILABLE
|
|
||||||
if n_accounts > 2:
|
|
||||||
assert snapshot.chat == bob_group
|
|
||||||
else:
|
|
||||||
# Group contains only Alice and Bob,
|
|
||||||
# so partially downloaded messages are
|
|
||||||
# hard to distinguish from private replies to group messages.
|
|
||||||
#
|
|
||||||
# Message may be a private reply, so we assign it to 1:1 chat with Alice.
|
|
||||||
assert snapshot.chat == bob_chat_alice
|
|
||||||
|
|
||||||
|
|
||||||
def test_markseen_contact_request(acfactory, tmp_path):
|
|
||||||
"""
|
|
||||||
Test that seen status is synchronized for contact request messages
|
|
||||||
even though read receipt is not sent.
|
|
||||||
"""
|
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
|
||||||
|
|
||||||
# Bob sets up a second device.
|
|
||||||
bob.export_backup(tmp_path)
|
|
||||||
files = list(tmp_path.glob("*.tar"))
|
|
||||||
bob2 = acfactory.get_unconfigured_account()
|
|
||||||
bob2.import_backup(files[0])
|
|
||||||
bob2.start_io()
|
|
||||||
|
|
||||||
alice_chat_bob = alice.create_chat(bob)
|
|
||||||
alice_chat_bob.send_text("Hello Bob!")
|
|
||||||
|
|
||||||
message = bob.get_message_by_id(bob.wait_for_incoming_msg_event().msg_id)
|
|
||||||
message2 = bob2.get_message_by_id(bob2.wait_for_incoming_msg_event().msg_id)
|
|
||||||
assert message2.get_snapshot().state == MessageState.IN_FRESH
|
|
||||||
|
|
||||||
message.mark_seen()
|
|
||||||
while True:
|
|
||||||
event = bob2.wait_for_event()
|
|
||||||
if event.kind == EventType.MSGS_NOTICED:
|
|
||||||
break
|
|
||||||
assert message2.get_snapshot().state == MessageState.IN_SEEN
|
|
||||||
|
|
||||||
|
|
||||||
def test_get_http_response(acfactory):
|
|
||||||
alice = acfactory.new_configured_account()
|
|
||||||
http_response = alice._rpc.get_http_response(alice.id, "https://example.org")
|
|
||||||
assert http_response["mimetype"] == "text/html"
|
|
||||||
assert b"<title>Example Domain</title>" in base64.b64decode((http_response["blob"] + "==").encode())
|
|
||||||
|
|
||||||
|
|
||||||
def test_configured_imap_certificate_checks(acfactory):
|
|
||||||
alice = acfactory.new_configured_account()
|
|
||||||
configured_certificate_checks = alice.get_config("configured_imap_certificate_checks")
|
|
||||||
|
|
||||||
# Certificate checks should be configured (not None)
|
|
||||||
assert configured_certificate_checks
|
|
||||||
|
|
||||||
# 0 is the value old Delta Chat core versions used
|
|
||||||
# to mean user entered "imap_certificate_checks=0" (Automatic)
|
|
||||||
# and configuration failed to use strict TLS checks
|
|
||||||
# so it switched strict TLS checks off.
|
|
||||||
#
|
|
||||||
# New versions of Delta Chat are not disabling TLS checks
|
|
||||||
# unless users explicitly disables them
|
|
||||||
# or provider database says provider has invalid certificates.
|
|
||||||
#
|
|
||||||
# Core 1.142.4, 1.142.5 and 1.142.6 saved this value due to bug.
|
|
||||||
# This test is a regression test to prevent this happening again.
|
|
||||||
assert configured_certificate_checks != "0"
|
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
def test_vcard(acfactory) -> None:
|
|
||||||
alice, bob = acfactory.get_online_accounts(2)
|
|
||||||
|
|
||||||
bob_addr = bob.get_config("addr")
|
|
||||||
alice_contact_bob = alice.create_contact(bob_addr, "Bob")
|
|
||||||
alice_contact_charlie = alice.create_contact("charlie@example.org", "Charlie")
|
|
||||||
|
|
||||||
alice_chat_bob = alice_contact_bob.create_chat()
|
|
||||||
alice_chat_bob.send_contact(alice_contact_charlie)
|
|
||||||
|
|
||||||
event = bob.wait_for_incoming_msg_event()
|
|
||||||
message = bob.get_message_by_id(event.msg_id)
|
|
||||||
snapshot = message.get_snapshot()
|
|
||||||
assert snapshot.vcard_contact
|
|
||||||
assert snapshot.vcard_contact.addr == "charlie@example.org"
|
|
||||||
@@ -22,9 +22,10 @@ skipsdist = True
|
|||||||
skip_install = True
|
skip_install = True
|
||||||
deps =
|
deps =
|
||||||
ruff
|
ruff
|
||||||
|
black
|
||||||
commands =
|
commands =
|
||||||
ruff format --quiet --diff src/ examples/ tests/
|
black --quiet --check --diff src/ examples/ tests/
|
||||||
ruff check src/ examples/ tests/
|
ruff src/ examples/ tests/
|
||||||
|
|
||||||
[pytest]
|
[pytest]
|
||||||
timeout = 300
|
timeout = 300
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "deltachat-rpc-server"
|
name = "deltachat-rpc-server"
|
||||||
version = "1.147.0"
|
version = "1.137.2"
|
||||||
description = "DeltaChat JSON-RPC server"
|
description = "DeltaChat JSON-RPC server"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
@@ -10,18 +10,18 @@ keywords = ["deltachat", "chat", "openpgp", "email", "encryption"]
|
|||||||
categories = ["cryptography", "std", "email"]
|
categories = ["cryptography", "std", "email"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
deltachat-jsonrpc = { workspace = true }
|
deltachat-jsonrpc = { path = "../deltachat-jsonrpc", default-features = false }
|
||||||
deltachat = { workspace = true }
|
deltachat = { path = "..", default-features = false }
|
||||||
|
|
||||||
anyhow = { workspace = true }
|
anyhow = "1"
|
||||||
futures-lite = { workspace = true }
|
env_logger = { version = "0.10.0" }
|
||||||
log = { workspace = true }
|
futures-lite = "2.3.0"
|
||||||
serde_json = { workspace = true }
|
log = "0.4"
|
||||||
serde = { workspace = true, features = ["derive"] }
|
serde_json = "1"
|
||||||
tokio = { workspace = true, features = ["io-std"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
tokio-util = { workspace = true }
|
tokio = { version = "1.37.0", features = ["io-std"] }
|
||||||
tracing-subscriber = { workspace = true, features = ["env-filter"] }
|
tokio-util = "0.7.9"
|
||||||
yerpc = { workspace = true, features = ["anyhow_expose", "openrpc"] }
|
yerpc = { version = "0.5.2", features = ["anyhow_expose", "openrpc"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["vendored"]
|
default = ["vendored"]
|
||||||
|
|||||||
3
deltachat-rpc-server/npm-package/.gitignore
vendored
3
deltachat-rpc-server/npm-package/.gitignore
vendored
@@ -1,3 +0,0 @@
|
|||||||
platform_package
|
|
||||||
*.tgz
|
|
||||||
package-lock.json
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
platform_package/*
|
|
||||||
scripts/
|
|
||||||
*.tgz
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
## npm package for deltachat-rpc-server
|
|
||||||
|
|
||||||
This is the successor of `deltachat-node`,
|
|
||||||
it does not use NAPI bindings but instead uses stdio executables
|
|
||||||
to let you talk to core over jsonrpc over stdio.
|
|
||||||
This simplifies cross-compilation and even reduces binary size (no CFFI layer and no NAPI layer).
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
> The **minimum** nodejs version for this package is `16`
|
|
||||||
|
|
||||||
```
|
|
||||||
npm i @deltachat/stdio-rpc-server @deltachat/jsonrpc-client
|
|
||||||
```
|
|
||||||
|
|
||||||
```js
|
|
||||||
import { startDeltaChat } from "@deltachat/stdio-rpc-server";
|
|
||||||
import { C } from "@deltachat/jsonrpc-client";
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const dc = await startDeltaChat("deltachat-data");
|
|
||||||
console.log(await dc.rpc.getSystemInfo());
|
|
||||||
dc.close()
|
|
||||||
}
|
|
||||||
main()
|
|
||||||
```
|
|
||||||
|
|
||||||
For a more complete example refer to https://github.com/deltachat-bot/echo/pull/69/files (TODO change link when pr is merged).
|
|
||||||
|
|
||||||
## How to use on an unsupported platform
|
|
||||||
|
|
||||||
<!-- todo instructions, will uses an env var for pointing to `deltachat-rpc-server` binary -->
|
|
||||||
|
|
||||||
<!-- todo copy parts from https://github.com/deltachat/deltachat-desktop/blob/7045c6f549e4b9d5caa0709d5bd314bbd9fd53db/docs/UPDATE_CORE.md -->
|
|
||||||
|
|
||||||
## How does it work when you install it
|
|
||||||
|
|
||||||
NPM automatically installs platform dependent optional dependencies when `os` and `cpu` fields are set correctly.
|
|
||||||
|
|
||||||
references:
|
|
||||||
|
|
||||||
- https://napi.rs/docs/deep-dive/release#3-the-native-addon-for-different-platforms-is-distributed-through-different-npm-packages, [webarchive version](https://web.archive.org/web/20240309234250/https://napi.rs/docs/deep-dive/release#3-the-native-addon-for-different-platforms-is-distributed-through-different-npm-packages)
|
|
||||||
- https://docs.npmjs.com/cli/v6/configuring-npm/package-json#cpu
|
|
||||||
- https://docs.npmjs.com/cli/v6/configuring-npm/package-json#os
|
|
||||||
|
|
||||||
When you import this package it searches for the rpc server in the following locations and order:
|
|
||||||
|
|
||||||
1. `DELTA_CHAT_RPC_SERVER` environment variable
|
|
||||||
2. use the PATH when `{takeVersionFromPATH: true}` is supplied in the options.
|
|
||||||
3. prebuilds in npm packages
|
|
||||||
|
|
||||||
so by default it uses the prebuilds.
|
|
||||||
|
|
||||||
## How do you built this package in CI
|
|
||||||
|
|
||||||
- To build platform packages, run the `build_platform_package.py` script:
|
|
||||||
```
|
|
||||||
python3 build_platform_package.py <cargo-target>
|
|
||||||
# example
|
|
||||||
python3 build_platform_package.py x86_64-apple-darwin
|
|
||||||
```
|
|
||||||
- Then pass it as an artifact to the last CI action that publishes the main package.
|
|
||||||
- upload all packages from `deltachat-rpc-server/npm-package/platform_package`.
|
|
||||||
- then publish `deltachat-rpc-server/npm-package`,
|
|
||||||
- this will run `update_optional_dependencies_and_version.js` (in the `prepack` script),
|
|
||||||
which puts all platform packages into `optionalDependencies` and updates the `version` in `package.json`
|
|
||||||
|
|
||||||
## How to build a version you can use localy on your host machine for development
|
|
||||||
|
|
||||||
You can not install the npm packet from the previous section locally, unless you have a local npm registry set up where you upload it too. This is why we have seperate scripts for making it work for local installation.
|
|
||||||
|
|
||||||
- If you just need your host platform run `python scripts/make_local_dev_version.py`
|
|
||||||
- note: this clears the `platform_package` folder
|
|
||||||
- (advanced) If you need more than one platform for local install you can just run `node scripts/update_optional_dependencies_and_version.js` after building multiple plaftorms with `build_platform_package.py`
|
|
||||||
|
|
||||||
## Thanks to nlnet
|
|
||||||
|
|
||||||
The initial work on this package was funded by nlnet as part of the [Delta Tauri](https://nlnet.nl/project/DeltaTauri/) Project.
|
|
||||||
42
deltachat-rpc-server/npm-package/index.d.ts
vendored
42
deltachat-rpc-server/npm-package/index.d.ts
vendored
@@ -1,42 +0,0 @@
|
|||||||
import { StdioDeltaChat } from "@deltachat/jsonrpc-client";
|
|
||||||
|
|
||||||
export interface SearchOptions {
|
|
||||||
/** whether take deltachat-rpc-server inside of $PATH*/
|
|
||||||
takeVersionFromPATH: boolean;
|
|
||||||
|
|
||||||
/** whether to disable the DELTA_CHAT_RPC_SERVER environment variable */
|
|
||||||
disableEnvPath: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @returns absolute path to deltachat-rpc-server binary
|
|
||||||
* @throws when it is not found
|
|
||||||
*/
|
|
||||||
export function getRPCServerPath(
|
|
||||||
options?: Partial<SearchOptions>
|
|
||||||
): Promise<string>;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export type DeltaChatOverJsonRpcServer = StdioDeltaChat & {
|
|
||||||
readonly pathToServerBinary: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface StartOptions {
|
|
||||||
/** whether to disable outputting stderr to the parent process's stderr */
|
|
||||||
muteStdErr: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param directory directory for accounts folder
|
|
||||||
* @param options
|
|
||||||
*/
|
|
||||||
export function startDeltaChat(directory: string, options?: Partial<SearchOptions & StartOptions> ): Promise<DeltaChatOverJsonRpcServer>
|
|
||||||
|
|
||||||
|
|
||||||
export namespace FnTypes {
|
|
||||||
export type getRPCServerPath = typeof getRPCServerPath
|
|
||||||
export type startDeltaChat = typeof startDeltaChat
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
//@ts-check
|
|
||||||
import { spawn } from "node:child_process";
|
|
||||||
import { stat } from "node:fs/promises";
|
|
||||||
import os from "node:os";
|
|
||||||
import process from "node:process";
|
|
||||||
import { ENV_VAR_NAME, PATH_EXECUTABLE_NAME } from "./src/const.js";
|
|
||||||
import {
|
|
||||||
ENV_VAR_LOCATION_NOT_FOUND,
|
|
||||||
FAILED_TO_START_SERVER_EXECUTABLE,
|
|
||||||
NPM_NOT_FOUND_SUPPORTED_PLATFORM_ERROR,
|
|
||||||
NPM_NOT_FOUND_UNSUPPORTED_PLATFORM_ERROR,
|
|
||||||
} from "./src/errors.js";
|
|
||||||
|
|
||||||
import { createRequire } from "node:module";
|
|
||||||
|
|
||||||
function findRPCServerInNodeModules() {
|
|
||||||
const arch = os.arch();
|
|
||||||
const operating_system = process.platform;
|
|
||||||
const package_name = `@deltachat/stdio-rpc-server-${operating_system}-${arch}`;
|
|
||||||
try {
|
|
||||||
const { resolve } = createRequire(import.meta.url);
|
|
||||||
return resolve(package_name);
|
|
||||||
} catch (error) {
|
|
||||||
console.debug("findRpcServerInNodeModules", error);
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
if (
|
|
||||||
Object.keys(require("./package.json").optionalDependencies).includes(
|
|
||||||
package_name
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new Error(NPM_NOT_FOUND_SUPPORTED_PLATFORM_ERROR(package_name));
|
|
||||||
} else {
|
|
||||||
throw new Error(NPM_NOT_FOUND_UNSUPPORTED_PLATFORM_ERROR());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @type {import("./index").FnTypes.getRPCServerPath} */
|
|
||||||
export async function getRPCServerPath(options = {}) {
|
|
||||||
const { takeVersionFromPATH, disableEnvPath } = {
|
|
||||||
takeVersionFromPATH: false,
|
|
||||||
disableEnvPath: false,
|
|
||||||
...options,
|
|
||||||
};
|
|
||||||
// 1. check if it is set as env var
|
|
||||||
if (process.env[ENV_VAR_NAME] && !disableEnvPath) {
|
|
||||||
try {
|
|
||||||
if (!(await stat(process.env[ENV_VAR_NAME])).isFile()) {
|
|
||||||
throw new Error(
|
|
||||||
`expected ${ENV_VAR_NAME} to point to the deltachat-rpc-server executable`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
throw new Error(ENV_VAR_LOCATION_NOT_FOUND());
|
|
||||||
}
|
|
||||||
return process.env[ENV_VAR_NAME];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. check if PATH should be used
|
|
||||||
if (takeVersionFromPATH) {
|
|
||||||
return PATH_EXECUTABLE_NAME;
|
|
||||||
}
|
|
||||||
// 3. check for prebuilds
|
|
||||||
|
|
||||||
return findRPCServerInNodeModules();
|
|
||||||
}
|
|
||||||
|
|
||||||
import { StdioDeltaChat } from "@deltachat/jsonrpc-client";
|
|
||||||
|
|
||||||
/** @type {import("./index").FnTypes.startDeltaChat} */
|
|
||||||
export async function startDeltaChat(directory, options = {}) {
|
|
||||||
const pathToServerBinary = await getRPCServerPath(options);
|
|
||||||
const server = spawn(pathToServerBinary, {
|
|
||||||
env: {
|
|
||||||
RUST_LOG: process.env.RUST_LOG,
|
|
||||||
DC_ACCOUNTS_PATH: directory,
|
|
||||||
},
|
|
||||||
stdio: ["pipe", "pipe", options.muteStdErr ? "ignore" : "inherit"],
|
|
||||||
});
|
|
||||||
|
|
||||||
server.on("error", (err) => {
|
|
||||||
throw new Error(FAILED_TO_START_SERVER_EXECUTABLE(pathToServerBinary, err));
|
|
||||||
});
|
|
||||||
let shouldClose = false;
|
|
||||||
|
|
||||||
server.on("exit", () => {
|
|
||||||
if (shouldClose) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new Error("Server quit");
|
|
||||||
});
|
|
||||||
|
|
||||||
/** @type {import('./index').DeltaChatOverJsonRpcServer} */
|
|
||||||
//@ts-expect-error
|
|
||||||
const dc = new StdioDeltaChat(server.stdin, server.stdout, true);
|
|
||||||
|
|
||||||
dc.close = () => {
|
|
||||||
shouldClose = true;
|
|
||||||
if (!server.kill()) {
|
|
||||||
console.log("server termination failed");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//@ts-expect-error
|
|
||||||
dc.pathToServerBinary = pathToServerBinary;
|
|
||||||
|
|
||||||
return dc;
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"license": "MPL-2.0",
|
|
||||||
"main": "index.js",
|
|
||||||
"name": "@deltachat/stdio-rpc-server",
|
|
||||||
"optionalDependencies": {},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@deltachat/jsonrpc-client": "*"
|
|
||||||
},
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/deltachat/deltachat-core-rust.git"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"prepack": "node scripts/update_optional_dependencies_and_version.js"
|
|
||||||
},
|
|
||||||
"type": "module",
|
|
||||||
"types": "index.d.ts",
|
|
||||||
"version": "1.147.0"
|
|
||||||
}
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
import subprocess
|
|
||||||
from sys import argv
|
|
||||||
from os import path, makedirs, chdir
|
|
||||||
from shutil import copy
|
|
||||||
from src.make_package import write_package_json
|
|
||||||
|
|
||||||
# ensure correct working directory
|
|
||||||
chdir(path.join(path.dirname(path.abspath(__file__)), "../"))
|
|
||||||
|
|
||||||
if len(argv) < 2:
|
|
||||||
print("First argument should be target architecture as required by cargo")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
target = argv[1].strip()
|
|
||||||
|
|
||||||
subprocess.run(
|
|
||||||
["cargo", "build", "--release", "-p", "deltachat-rpc-server", "--target", target],
|
|
||||||
check=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
newpath = "platform_package"
|
|
||||||
if not path.exists(newpath):
|
|
||||||
makedirs(newpath)
|
|
||||||
|
|
||||||
# make new folder
|
|
||||||
|
|
||||||
platform_path = "platform_package/" + target
|
|
||||||
if not path.exists(platform_path):
|
|
||||||
makedirs(platform_path)
|
|
||||||
|
|
||||||
# copy binary it over
|
|
||||||
|
|
||||||
|
|
||||||
def binary_path(binary_name):
|
|
||||||
return "../../target/" + target + "/release/" + binary_name
|
|
||||||
|
|
||||||
|
|
||||||
my_binary_name = "deltachat-rpc-server"
|
|
||||||
|
|
||||||
if not path.isfile(binary_path("deltachat-rpc-server")):
|
|
||||||
my_binary_name = "deltachat-rpc-server.exe"
|
|
||||||
if not path.isfile(binary_path("deltachat-rpc-server.exe")):
|
|
||||||
print("Did not find the build")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
my_binary_path = binary_path(my_binary_name)
|
|
||||||
|
|
||||||
copy(my_binary_path, platform_path + "/" + my_binary_name)
|
|
||||||
|
|
||||||
# make a package.json for it
|
|
||||||
|
|
||||||
write_package_json(platform_path, target, my_binary_name)
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
# This script is for making a version of the npm packet that you can install locally
|
|
||||||
|
|
||||||
import subprocess
|
|
||||||
from sys import argv
|
|
||||||
from os import path, makedirs, chdir
|
|
||||||
import re
|
|
||||||
import json
|
|
||||||
import tomllib
|
|
||||||
from shutil import copy, rmtree
|
|
||||||
|
|
||||||
# ensure correct working directory
|
|
||||||
chdir(path.join(path.dirname(path.abspath(__file__)), "../"))
|
|
||||||
|
|
||||||
# get host target with "rustc -vV"
|
|
||||||
output = subprocess.run(["rustc", "-vV"], capture_output=True)
|
|
||||||
host_target = re.search('host: ([-\\w]*)', output.stdout.decode("utf-8")).group(1)
|
|
||||||
print("host target to build for is:", host_target)
|
|
||||||
|
|
||||||
# clean platform_package folder
|
|
||||||
newpath = r'platform_package'
|
|
||||||
if not path.exists(newpath):
|
|
||||||
makedirs(newpath)
|
|
||||||
else:
|
|
||||||
rmtree(path.join(path.dirname(path.abspath(__file__)), "../platform_package/"))
|
|
||||||
makedirs(newpath)
|
|
||||||
|
|
||||||
# run build_platform_package.py with the host's target to build it
|
|
||||||
subprocess.run(["python", "scripts/build_platform_package.py", host_target], capture_output=False, check=True)
|
|
||||||
|
|
||||||
# run update_optional_dependencies_and_version.js to adjust the package / make it installable locally
|
|
||||||
subprocess.run(["node", "scripts/update_optional_dependencies_and_version.js", "--local"], capture_output=False, check=True)
|
|
||||||
|
|
||||||
# typescript / npm local package installing/linking needs that this package has it's own node_modules folder
|
|
||||||
subprocess.run(["npm", "i"], capture_output=False, check=True)
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
import subprocess
|
|
||||||
from sys import argv
|
|
||||||
from os import path, makedirs, chdir, chmod, stat
|
|
||||||
import json
|
|
||||||
from shutil import copy
|
|
||||||
from src.make_package import write_package_json
|
|
||||||
|
|
||||||
# ensure correct working directory
|
|
||||||
chdir(path.join(path.dirname(path.abspath(__file__)), "../"))
|
|
||||||
|
|
||||||
if len(argv) < 3:
|
|
||||||
print("First argument should be target architecture as required by cargo")
|
|
||||||
print("Second argument should be the location of th built binary (binary_path)")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
target = argv[1].strip()
|
|
||||||
binary_path = argv[2].strip()
|
|
||||||
|
|
||||||
output = subprocess.run(["rustc","--print","target-list"], capture_output=True, check=True)
|
|
||||||
available_targets = output.stdout.decode("utf-8")
|
|
||||||
|
|
||||||
if available_targets.find(target) == -1:
|
|
||||||
print("target", target, "is not known / not valid")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
newpath = r'platform_package'
|
|
||||||
if not path.exists(newpath):
|
|
||||||
makedirs(newpath)
|
|
||||||
|
|
||||||
# make new folder
|
|
||||||
|
|
||||||
platform_path = 'platform_package/' + target
|
|
||||||
if not path.exists(platform_path):
|
|
||||||
makedirs(platform_path)
|
|
||||||
|
|
||||||
# copy binary it over
|
|
||||||
|
|
||||||
my_binary_name = path.basename(binary_path)
|
|
||||||
new_binary_path = platform_path + "/" + my_binary_name
|
|
||||||
copy(binary_path, new_binary_path)
|
|
||||||
chmod(new_binary_path, 0o555) # everyone can read & execute, nobody can write
|
|
||||||
|
|
||||||
# make a package.json for it
|
|
||||||
|
|
||||||
write_package_json(platform_path, target, my_binary_name)
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
def convert_cpu_arch_to_npm_cpu_arch(arch):
|
|
||||||
if arch == "x86_64":
|
|
||||||
return "x64"
|
|
||||||
if arch == "i686":
|
|
||||||
return "ia32"
|
|
||||||
if arch == "aarch64":
|
|
||||||
return "arm64"
|
|
||||||
if arch == "armv7" or arch == "arm":
|
|
||||||
return "arm"
|
|
||||||
print("architecture might not be known by nodejs, please make sure it can be returned by 'process.arch':", arch)
|
|
||||||
return arch
|
|
||||||
|
|
||||||
def convert_os_to_npm_os(os):
|
|
||||||
if os == "windows":
|
|
||||||
return "win32"
|
|
||||||
if os == "darwin" or os == "linux":
|
|
||||||
return os
|
|
||||||
if os.startswith("android"):
|
|
||||||
return "android"
|
|
||||||
print("architecture might not be known by nodejs, please make sure it can be returned by 'process.platform':", os)
|
|
||||||
return os
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import tomllib
|
|
||||||
import json
|
|
||||||
|
|
||||||
from .convert_platform import convert_cpu_arch_to_npm_cpu_arch, convert_os_to_npm_os
|
|
||||||
|
|
||||||
def write_package_json(platform_path, rust_target, my_binary_name):
|
|
||||||
if len(rust_target.split("-")) == 3:
|
|
||||||
[cpu_arch, vendor, os] = rust_target.split("-")
|
|
||||||
else:
|
|
||||||
[cpu_arch, vendor, os, _env] = rust_target.split("-")
|
|
||||||
|
|
||||||
# read version
|
|
||||||
tomlfile = open("../../Cargo.toml", 'rb')
|
|
||||||
version = tomllib.load(tomlfile)['package']['version']
|
|
||||||
|
|
||||||
package_json = {
|
|
||||||
"name": "@deltachat/stdio-rpc-server-"
|
|
||||||
+ convert_os_to_npm_os(os)
|
|
||||||
+ "-"
|
|
||||||
+ convert_cpu_arch_to_npm_cpu_arch(cpu_arch),
|
|
||||||
"version": version,
|
|
||||||
"os": [convert_os_to_npm_os(os)],
|
|
||||||
"cpu": [convert_cpu_arch_to_npm_cpu_arch(cpu_arch)],
|
|
||||||
"main": my_binary_name,
|
|
||||||
"license": "MPL-2.0",
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "https://github.com/deltachat/deltachat-core-rust.git",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
file = open(platform_path + "/package.json", 'w')
|
|
||||||
file.write(json.dumps(package_json, indent=4))
|
|
||||||
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
import fs from "node:fs/promises";
|
|
||||||
import { join, dirname } from "node:path";
|
|
||||||
import { fileURLToPath } from "node:url";
|
|
||||||
|
|
||||||
const expected_cwd = join(dirname(fileURLToPath(import.meta.url)), "..");
|
|
||||||
|
|
||||||
if (process.cwd() !== expected_cwd) {
|
|
||||||
console.error(
|
|
||||||
"CWD missmatch: this script needs to be run from " + expected_cwd,
|
|
||||||
{ actual: process.cwd(), expected: expected_cwd }
|
|
||||||
);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// whether to use local paths instead of npm registry version number for the prebuilds in optionalDependencies
|
|
||||||
// useful for local development
|
|
||||||
const is_local = process.argv.includes("--local");
|
|
||||||
|
|
||||||
const package_json = JSON.parse(await fs.readFile("./package.json", "utf8"));
|
|
||||||
|
|
||||||
const cargo_toml = await fs.readFile("../Cargo.toml", "utf8");
|
|
||||||
const version = cargo_toml
|
|
||||||
.split("\n")
|
|
||||||
.find((line) => line.includes("version"))
|
|
||||||
.split('"')[1];
|
|
||||||
|
|
||||||
const platform_packages_dir = "./platform_package";
|
|
||||||
|
|
||||||
const platform_package_names = await Promise.all(
|
|
||||||
(await fs.readdir(platform_packages_dir)).map(async (name) => {
|
|
||||||
const p = JSON.parse(
|
|
||||||
await fs.readFile(
|
|
||||||
join(platform_packages_dir, name, "package.json"),
|
|
||||||
"utf8"
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (p.version !== version) {
|
|
||||||
console.error(
|
|
||||||
name,
|
|
||||||
"has a different version than the version of the rpc server.",
|
|
||||||
{ rpc_server: version, platform_package: p.version }
|
|
||||||
);
|
|
||||||
throw new Error("version missmatch");
|
|
||||||
}
|
|
||||||
return { folder_name: name, package_name: p.name };
|
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
package_json.version = version;
|
|
||||||
package_json.optionalDependencies = {};
|
|
||||||
for (const { folder_name, package_name } of platform_package_names) {
|
|
||||||
package_json.optionalDependencies[package_name] = is_local
|
|
||||||
? `file:${expected_cwd}/platform_package/${folder_name}` // npm seems to work better with an absolute path here
|
|
||||||
: version;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_local) {
|
|
||||||
package_json.peerDependencies["@deltachat/jsonrpc-client"] =
|
|
||||||
`file:${join(expected_cwd, "/../../deltachat-jsonrpc/typescript")}`;
|
|
||||||
} else {
|
|
||||||
package_json.peerDependencies["@deltachat/jsonrpc-client"] = "*";
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.writeFile("./package.json", JSON.stringify(package_json, null, 4));
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
//@ts-check
|
|
||||||
|
|
||||||
export const PATH_EXECUTABLE_NAME = 'deltachat-rpc-server'
|
|
||||||
|
|
||||||
export const ENV_VAR_NAME = "DELTA_CHAT_RPC_SERVER"
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
//@ts-check
|
|
||||||
import { ENV_VAR_NAME } from "./const.js";
|
|
||||||
|
|
||||||
const cargoInstallCommand =
|
|
||||||
"cargo install --git https://github.com/deltachat/deltachat-core-rust deltachat-rpc-server";
|
|
||||||
|
|
||||||
export function NPM_NOT_FOUND_SUPPORTED_PLATFORM_ERROR(package_name) {
|
|
||||||
return `deltachat-rpc-server not found:
|
|
||||||
|
|
||||||
- Install it with "npm i ${package_name}"
|
|
||||||
- or download/compile deltachat-rpc-server for your platform and
|
|
||||||
- either put it into your PATH (for example with "${cargoInstallCommand}")
|
|
||||||
- or set the "${ENV_VAR_NAME}" env var to the path to deltachat-rpc-server"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function NPM_NOT_FOUND_UNSUPPORTED_PLATFORM_ERROR() {
|
|
||||||
return `deltachat-rpc-server not found:
|
|
||||||
|
|
||||||
Unfortunately no prebuild is available for your system, so you need to provide deltachat-rpc-server yourself.
|
|
||||||
|
|
||||||
- Download or Compile deltachat-rpc-server for your platform and
|
|
||||||
- either put it into your PATH (for example with "${cargoInstallCommand}")
|
|
||||||
- or set the "${ENV_VAR_NAME}" env var to the path to deltachat-rpc-server"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ENV_VAR_LOCATION_NOT_FOUND(error) {
|
|
||||||
return `deltachat-rpc-server not found in ${ENV_VAR_NAME}:
|
|
||||||
|
|
||||||
Error: ${error}
|
|
||||||
|
|
||||||
Content of ${ENV_VAR_NAME}: "${process.env[ENV_VAR_NAME]}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function FAILED_TO_START_SERVER_EXECUTABLE(pathToServerBinary, error) {
|
|
||||||
return `Failed to start server executable at '${pathToServerBinary}',
|
|
||||||
|
|
||||||
Error: ${error}
|
|
||||||
|
|
||||||
Make sure the deltachat-rpc-server binary exists at this location
|
|
||||||
and you can start it with \`${pathToServerBinary} --version\``;
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
#![recursion_limit = "256"]
|
|
||||||
//! Delta Chat core RPC server.
|
//! Delta Chat core RPC server.
|
||||||
//!
|
//!
|
||||||
//! It speaks JSON Lines over stdio.
|
//! It speaks JSON Lines over stdio.
|
||||||
@@ -11,7 +10,6 @@ use deltachat::constants::DC_VERSION_STR;
|
|||||||
use deltachat_jsonrpc::api::{Accounts, CommandApi};
|
use deltachat_jsonrpc::api::{Accounts, CommandApi};
|
||||||
use futures_lite::stream::StreamExt;
|
use futures_lite::stream::StreamExt;
|
||||||
use tokio::io::{self, AsyncBufReadExt, BufReader};
|
use tokio::io::{self, AsyncBufReadExt, BufReader};
|
||||||
use tracing_subscriber::EnvFilter;
|
|
||||||
use yerpc::RpcServer as _;
|
use yerpc::RpcServer as _;
|
||||||
|
|
||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
@@ -29,9 +27,6 @@ async fn main() {
|
|||||||
// "For technical reasons, stdin is implemented by using an ordinary blocking read on a separate
|
// "For technical reasons, stdin is implemented by using an ordinary blocking read on a separate
|
||||||
// thread, and it is impossible to cancel that read. This can make shutdown of the runtime hang
|
// thread, and it is impossible to cancel that read. This can make shutdown of the runtime hang
|
||||||
// until the user presses enter."
|
// until the user presses enter."
|
||||||
if let Err(error) = &r {
|
|
||||||
log::error!("Fatal error: {error:#}.")
|
|
||||||
}
|
|
||||||
std::process::exit(if r.is_ok() { 0 } else { 1 });
|
std::process::exit(if r.is_ok() { 0 } else { 1 });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,13 +59,7 @@ async fn main_impl() -> Result<()> {
|
|||||||
#[cfg(target_family = "unix")]
|
#[cfg(target_family = "unix")]
|
||||||
let mut sigterm = signal_unix::signal(signal_unix::SignalKind::terminate())?;
|
let mut sigterm = signal_unix::signal(signal_unix::SignalKind::terminate())?;
|
||||||
|
|
||||||
// Logs from `log` crate and traces from `tracing` crate
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
|
||||||
// are configurable with `RUST_LOG` environment variable
|
|
||||||
// and go to stderr to avoid interferring with JSON-RPC using stdout.
|
|
||||||
tracing_subscriber::fmt()
|
|
||||||
.with_env_filter(EnvFilter::from_default_env())
|
|
||||||
.with_writer(std::io::stderr)
|
|
||||||
.init();
|
|
||||||
|
|
||||||
let path = std::env::var("DC_ACCOUNTS_PATH").unwrap_or_else(|_| "accounts".to_string());
|
let path = std::env::var("DC_ACCOUNTS_PATH").unwrap_or_else(|_| "accounts".to_string());
|
||||||
log::info!("Starting with accounts directory `{}`.", path);
|
log::info!("Starting with accounts directory `{}`.", path);
|
||||||
@@ -79,7 +68,7 @@ async fn main_impl() -> Result<()> {
|
|||||||
|
|
||||||
log::info!("Creating JSON-RPC API.");
|
log::info!("Creating JSON-RPC API.");
|
||||||
let accounts = Arc::new(RwLock::new(accounts));
|
let accounts = Arc::new(RwLock::new(accounts));
|
||||||
let state = CommandApi::from_arc(accounts.clone()).await;
|
let state = CommandApi::from_arc(accounts.clone());
|
||||||
|
|
||||||
let (client, mut out_receiver) = RpcClient::new();
|
let (client, mut out_receiver) = RpcClient::new();
|
||||||
let session = RpcSession::new(client.clone(), state.clone());
|
let session = RpcSession::new(client.clone(), state.clone());
|
||||||
|
|||||||
42
deny.toml
42
deny.toml
@@ -1,6 +1,7 @@
|
|||||||
[advisories]
|
[advisories]
|
||||||
ignore = [
|
ignore = [
|
||||||
"RUSTSEC-2020-0071",
|
"RUSTSEC-2020-0071",
|
||||||
|
"RUSTSEC-2022-0093",
|
||||||
|
|
||||||
# Timing attack on RSA.
|
# Timing attack on RSA.
|
||||||
# Delta Chat does not use RSA for new keys
|
# Delta Chat does not use RSA for new keys
|
||||||
@@ -9,6 +10,9 @@ ignore = [
|
|||||||
# <https://rustsec.org/advisories/RUSTSEC-2023-0071>
|
# <https://rustsec.org/advisories/RUSTSEC-2023-0071>
|
||||||
"RUSTSEC-2023-0071",
|
"RUSTSEC-2023-0071",
|
||||||
|
|
||||||
|
# Unmaintained ansi_term
|
||||||
|
"RUSTSEC-2021-0139",
|
||||||
|
|
||||||
# Unmaintained encoding
|
# Unmaintained encoding
|
||||||
"RUSTSEC-2021-0153",
|
"RUSTSEC-2021-0153",
|
||||||
]
|
]
|
||||||
@@ -20,19 +24,24 @@ ignore = [
|
|||||||
# Please keep this list alphabetically sorted.
|
# Please keep this list alphabetically sorted.
|
||||||
skip = [
|
skip = [
|
||||||
{ name = "async-channel", version = "1.9.0" },
|
{ name = "async-channel", version = "1.9.0" },
|
||||||
|
{ name = "base16ct", version = "0.1.1" },
|
||||||
{ name = "base64", version = "<0.21" },
|
{ name = "base64", version = "<0.21" },
|
||||||
{ name = "base64", version = "0.21.7" },
|
|
||||||
{ name = "bitflags", version = "1.3.2" },
|
{ name = "bitflags", version = "1.3.2" },
|
||||||
|
{ name = "block-buffer", version = "<0.10" },
|
||||||
|
{ name = "convert_case", version = "0.4.0" },
|
||||||
|
{ name = "curve25519-dalek", version = "3.2.0" },
|
||||||
|
{ name = "darling_core", version = "<0.14" },
|
||||||
|
{ name = "darling_macro", version = "<0.14" },
|
||||||
|
{ name = "darling", version = "<0.14" },
|
||||||
|
{ name = "der", version = "0.6.1" },
|
||||||
|
{ name = "digest", version = "<0.10" },
|
||||||
|
{ name = "ed25519-dalek", version = "1.0.1" },
|
||||||
|
{ name = "ed25519", version = "1.5.3" },
|
||||||
{ name = "event-listener", version = "2.5.3" },
|
{ name = "event-listener", version = "2.5.3" },
|
||||||
{ name = "event-listener", version = "4.0.3" },
|
|
||||||
{ name = "fastrand", version = "1.9.0" },
|
|
||||||
{ name = "futures-lite", version = "1.13.0" },
|
|
||||||
{ name = "getrandom", version = "<0.2" },
|
{ name = "getrandom", version = "<0.2" },
|
||||||
{ name = "h2", version = "0.3.26" },
|
{ name = "idna", version = "0.4.0" },
|
||||||
{ name = "http-body", version = "0.4.6" },
|
{ name = "pem-rfc7468", version = "0.6.0" },
|
||||||
{ name = "http", version = "0.2.12" },
|
{ name = "pkcs8", version = "0.9.0" },
|
||||||
{ name = "hyper", version = "0.14.28" },
|
|
||||||
{ name = "nix", version = "0.26.4" },
|
|
||||||
{ name = "quick-error", version = "<2.0" },
|
{ name = "quick-error", version = "<2.0" },
|
||||||
{ name = "rand_chacha", version = "<0.3" },
|
{ name = "rand_chacha", version = "<0.3" },
|
||||||
{ name = "rand_core", version = "<0.6" },
|
{ name = "rand_core", version = "<0.6" },
|
||||||
@@ -40,22 +49,29 @@ skip = [
|
|||||||
{ name = "redox_syscall", version = "0.3.5" },
|
{ name = "redox_syscall", version = "0.3.5" },
|
||||||
{ name = "regex-automata", version = "0.1.10" },
|
{ name = "regex-automata", version = "0.1.10" },
|
||||||
{ name = "regex-syntax", version = "0.6.29" },
|
{ name = "regex-syntax", version = "0.6.29" },
|
||||||
|
{ name = "ring", version = "0.16.20" },
|
||||||
|
{ name = "sec1", version = "0.3.0" },
|
||||||
|
{ name = "sha2", version = "<0.10" },
|
||||||
|
{ name = "signature", version = "1.6.4" },
|
||||||
|
{ name = "spin", version = "<0.9.6" },
|
||||||
|
{ name = "spki", version = "0.6.0" },
|
||||||
{ name = "sync_wrapper", version = "0.1.2" },
|
{ name = "sync_wrapper", version = "0.1.2" },
|
||||||
{ name = "syn", version = "1.0.109" },
|
{ name = "syn", version = "1.0.109" },
|
||||||
{ name = "time", version = "<0.3" },
|
{ name = "time", version = "<0.3" },
|
||||||
|
{ name = "toml_edit", version = "0.21.1" },
|
||||||
|
{ name = "untrusted", version = "0.7.1" },
|
||||||
{ name = "wasi", version = "<0.11" },
|
{ name = "wasi", version = "<0.11" },
|
||||||
{ name = "windows_aarch64_gnullvm", version = "<0.52" },
|
{ name = "windows_aarch64_gnullvm", version = "<0.52" },
|
||||||
{ name = "windows_aarch64_msvc", version = "<0.52" },
|
{ name = "windows_aarch64_msvc", version = "<0.52" },
|
||||||
{ name = "windows-core", version = "<0.54.0" },
|
|
||||||
{ name = "windows_i686_gnu", version = "<0.52" },
|
{ name = "windows_i686_gnu", version = "<0.52" },
|
||||||
{ name = "windows_i686_msvc", version = "<0.52" },
|
{ name = "windows_i686_msvc", version = "<0.52" },
|
||||||
{ name = "windows-sys", version = "<0.59" },
|
{ name = "windows-sys", version = "<0.52" },
|
||||||
{ name = "windows-targets", version = "<0.52" },
|
{ name = "windows-targets", version = "<0.52" },
|
||||||
{ name = "windows", version = "<0.54.0" },
|
{ name = "windows", version = "0.32.0" },
|
||||||
{ name = "windows_x86_64_gnullvm", version = "<0.52" },
|
{ name = "windows_x86_64_gnullvm", version = "<0.52" },
|
||||||
{ name = "windows_x86_64_gnu", version = "<0.52" },
|
{ name = "windows_x86_64_gnu", version = "<0.52" },
|
||||||
{ name = "windows_x86_64_msvc", version = "<0.52" },
|
{ name = "windows_x86_64_msvc", version = "<0.52" },
|
||||||
{ name = "winreg", version = "0.50.0" },
|
{ name = "winnow", version = "0.5.40" },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
65
flake.lock
generated
65
flake.lock
generated
@@ -7,11 +7,11 @@
|
|||||||
"nixpkgs": "nixpkgs"
|
"nixpkgs": "nixpkgs"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1712088936,
|
"lastModified": 1710633978,
|
||||||
"narHash": "sha256-mVjeSWQiR/t4UZ9fUawY9OEPAhY1R3meYG+0oh8DUBs=",
|
"narHash": "sha256-yemnwSvW7cdWtXGpivFA5jDO35rGPs6fqxlQ4l6ODXs=",
|
||||||
"owner": "tadfisher",
|
"owner": "tadfisher",
|
||||||
"repo": "android-nixpkgs",
|
"repo": "android-nixpkgs",
|
||||||
"rev": "2d8181caef279f19c4a33dc694723f89ffc195d4",
|
"rev": "e91fb3d8517538e5ad9b422c9a4f604b56008a9e",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -29,11 +29,11 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711099426,
|
"lastModified": 1708939976,
|
||||||
"narHash": "sha256-HzpgM/wc3aqpnHJJ2oDqPBkNsqWbW0WfWUO8lKu8nGk=",
|
"narHash": "sha256-O5+nFozxz2Vubpdl1YZtPrilcIXPcRAjqNdNE8oCRoA=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "devshell",
|
"repo": "devshell",
|
||||||
"rev": "2d45b54ca4a183f2fdcf4b19c895b64fbf620ee8",
|
"rev": "5ddecd67edbd568ebe0a55905273e56cc82aabe3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -48,11 +48,11 @@
|
|||||||
"rust-analyzer-src": "rust-analyzer-src"
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1714112748,
|
"lastModified": 1710742993,
|
||||||
"narHash": "sha256-jq6Cpf/pQH85p+uTwPPrGG8Ky/zUOTwMJ7mcqc5M4So=",
|
"narHash": "sha256-W0PQCe0bW3hKF5lHawXrKynBcdSP18Qa4sb8DcUfOqI=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "fenix",
|
"repo": "fenix",
|
||||||
"rev": "3ae4b908a795b6a3824d401a0702e11a7157d7e1",
|
"rev": "6f2fec850f569d61562d3a47dc263f19e9c7d825",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -84,11 +84,11 @@
|
|||||||
"systems": "systems_2"
|
"systems": "systems_2"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1710146030,
|
"lastModified": 1709126324,
|
||||||
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
|
"narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
|
"rev": "d465f4819400de7c8d874d50b982301f28a84605",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -120,11 +120,11 @@
|
|||||||
"nixpkgs": "nixpkgs_3"
|
"nixpkgs": "nixpkgs_3"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1713520724,
|
"lastModified": 1698420672,
|
||||||
"narHash": "sha256-CO8MmVDmqZX2FovL75pu5BvwhW+Vugc7Q6ze7Hj8heI=",
|
"narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "naersk",
|
"repo": "naersk",
|
||||||
"rev": "c5037590290c6c7dae2e42e7da1e247e54ed2d49",
|
"rev": "aeb58d5e8faead8980a807c840232697982d47b9",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -150,11 +150,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711703276,
|
"lastModified": 1709237383,
|
||||||
"narHash": "sha256-iMUFArF0WCatKK6RzfUJknjem0H9m4KgorO/p3Dopkk=",
|
"narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "d8fe5e6c92d0d190646fb9f1056741a229980089",
|
"rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -166,11 +166,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
"nixpkgs_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1713895582,
|
"lastModified": 1710631334,
|
||||||
"narHash": "sha256-cfh1hi+6muQMbi9acOlju3V1gl8BEaZBXBR9jQfQi4U=",
|
"narHash": "sha256-rL5LSYd85kplL5othxK5lmAtjyMOBg390sGBTb3LRMM=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "572af610f6151fd41c212f897c71f7056e3fb518",
|
"rev": "c75037bbf9093a2acb617804ee46320d6d1fea5a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -182,11 +182,12 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs_3": {
|
"nixpkgs_3": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1711668574,
|
"lastModified": 1710765496,
|
||||||
"narHash": "sha256-u1dfs0ASQIEr1icTVrsKwg2xToIpn7ZXxW3RHfHxshg=",
|
"narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=",
|
||||||
"path": "/nix/store/9fpv0kjq9a80isa1wkkvrdqsh9dpcn05-source",
|
"owner": "NixOS",
|
||||||
"rev": "219951b495fc2eac67b1456824cc1ec1fd2ee659",
|
"repo": "nixpkgs",
|
||||||
"type": "path"
|
"rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7",
|
||||||
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"id": "nixpkgs",
|
"id": "nixpkgs",
|
||||||
@@ -195,11 +196,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs_4": {
|
"nixpkgs_4": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1714076141,
|
"lastModified": 1710631334,
|
||||||
"narHash": "sha256-Drmja/f5MRHZCskS6mvzFqxEaZMeciScCTFxWVLqWEY=",
|
"narHash": "sha256-rL5LSYd85kplL5othxK5lmAtjyMOBg390sGBTb3LRMM=",
|
||||||
"owner": "nixos",
|
"owner": "nixos",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856",
|
"rev": "c75037bbf9093a2acb617804ee46320d6d1fea5a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -222,11 +223,11 @@
|
|||||||
"rust-analyzer-src": {
|
"rust-analyzer-src": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1714031783,
|
"lastModified": 1710708100,
|
||||||
"narHash": "sha256-xS/niQsq1CQPOe4M4jvVPO2cnXS/EIeRG5gIopUbk+Q=",
|
"narHash": "sha256-Jd6pmXlwKk5uYcjyO/8BfbUVmx8g31Qfk7auI2IG66A=",
|
||||||
"owner": "rust-lang",
|
"owner": "rust-lang",
|
||||||
"repo": "rust-analyzer",
|
"repo": "rust-analyzer",
|
||||||
"rev": "56bee2ddafa6177b19c631eedc88d43366553223",
|
"rev": "b6d1887bc4f9543b6c6bf098179a62446f34a6c3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
16
flake.nix
16
flake.nix
@@ -35,7 +35,6 @@
|
|||||||
./CMakeLists.txt
|
./CMakeLists.txt
|
||||||
./CONTRIBUTING.md
|
./CONTRIBUTING.md
|
||||||
./deltachat_derive
|
./deltachat_derive
|
||||||
./deltachat-contact-tools
|
|
||||||
./deltachat-ffi
|
./deltachat-ffi
|
||||||
./deltachat-jsonrpc
|
./deltachat-jsonrpc
|
||||||
./deltachat-ratelimit
|
./deltachat-ratelimit
|
||||||
@@ -483,7 +482,6 @@
|
|||||||
format = "pyproject";
|
format = "pyproject";
|
||||||
propagatedBuildInputs = [
|
propagatedBuildInputs = [
|
||||||
pkgs.python3Packages.setuptools
|
pkgs.python3Packages.setuptools
|
||||||
pkgs.python3Packages.imap-tools
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -525,15 +523,9 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
devShells.default = let
|
devShells.default = pkgs.mkShell {
|
||||||
pkgs = import nixpkgs {
|
|
||||||
system = system;
|
|
||||||
overlays = [ fenix.overlays.default ];
|
|
||||||
};
|
|
||||||
in pkgs.mkShell {
|
|
||||||
|
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs; [
|
||||||
(fenix.packages.${system}.complete.withComponents [
|
(fenixPkgs.complete.withComponents [
|
||||||
"cargo"
|
"cargo"
|
||||||
"clippy"
|
"clippy"
|
||||||
"rust-src"
|
"rust-src"
|
||||||
@@ -541,10 +533,8 @@
|
|||||||
"rustfmt"
|
"rustfmt"
|
||||||
])
|
])
|
||||||
cargo-deny
|
cargo-deny
|
||||||
rust-analyzer-nightly
|
fenixPkgs.rust-analyzer
|
||||||
cargo-nextest
|
|
||||||
perl # needed to build vendored OpenSSL
|
perl # needed to build vendored OpenSSL
|
||||||
git-cliff
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
2695
fuzz/Cargo.lock
generated
2695
fuzz/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -30,9 +30,6 @@ module.exports = {
|
|||||||
DC_DOWNLOAD_IN_PROGRESS: 1000,
|
DC_DOWNLOAD_IN_PROGRESS: 1000,
|
||||||
DC_DOWNLOAD_UNDECIPHERABLE: 30,
|
DC_DOWNLOAD_UNDECIPHERABLE: 30,
|
||||||
DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE: 2200,
|
DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE: 2200,
|
||||||
DC_EVENT_CHANNEL_OVERFLOW: 2400,
|
|
||||||
DC_EVENT_CHATLIST_CHANGED: 2300,
|
|
||||||
DC_EVENT_CHATLIST_ITEM_CHANGED: 2301,
|
|
||||||
DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED: 2021,
|
DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED: 2021,
|
||||||
DC_EVENT_CHAT_MODIFIED: 2020,
|
DC_EVENT_CHAT_MODIFIED: 2020,
|
||||||
DC_EVENT_CONFIGURE_PROGRESS: 2041,
|
DC_EVENT_CONFIGURE_PROGRESS: 2041,
|
||||||
@@ -67,7 +64,6 @@ module.exports = {
|
|||||||
DC_EVENT_SMTP_MESSAGE_SENT: 103,
|
DC_EVENT_SMTP_MESSAGE_SENT: 103,
|
||||||
DC_EVENT_WARNING: 300,
|
DC_EVENT_WARNING: 300,
|
||||||
DC_EVENT_WEBXDC_INSTANCE_DELETED: 2121,
|
DC_EVENT_WEBXDC_INSTANCE_DELETED: 2121,
|
||||||
DC_EVENT_WEBXDC_REALTIME_DATA: 2150,
|
|
||||||
DC_EVENT_WEBXDC_STATUS_UPDATE: 2120,
|
DC_EVENT_WEBXDC_STATUS_UPDATE: 2120,
|
||||||
DC_GCL_ADD_ALLDONE_HINT: 4,
|
DC_GCL_ADD_ALLDONE_HINT: 4,
|
||||||
DC_GCL_ADD_SELF: 2,
|
DC_GCL_ADD_SELF: 2,
|
||||||
@@ -112,7 +108,6 @@ module.exports = {
|
|||||||
DC_MSG_IMAGE: 20,
|
DC_MSG_IMAGE: 20,
|
||||||
DC_MSG_STICKER: 23,
|
DC_MSG_STICKER: 23,
|
||||||
DC_MSG_TEXT: 10,
|
DC_MSG_TEXT: 10,
|
||||||
DC_MSG_VCARD: 90,
|
|
||||||
DC_MSG_VIDEO: 50,
|
DC_MSG_VIDEO: 50,
|
||||||
DC_MSG_VIDEOCHAT_INVITATION: 70,
|
DC_MSG_VIDEOCHAT_INVITATION: 70,
|
||||||
DC_MSG_VOICE: 41,
|
DC_MSG_VOICE: 41,
|
||||||
@@ -128,13 +123,11 @@ module.exports = {
|
|||||||
DC_QR_ASK_VERIFYCONTACT: 200,
|
DC_QR_ASK_VERIFYCONTACT: 200,
|
||||||
DC_QR_ASK_VERIFYGROUP: 202,
|
DC_QR_ASK_VERIFYGROUP: 202,
|
||||||
DC_QR_BACKUP: 251,
|
DC_QR_BACKUP: 251,
|
||||||
DC_QR_BACKUP2: 252,
|
|
||||||
DC_QR_ERROR: 400,
|
DC_QR_ERROR: 400,
|
||||||
DC_QR_FPR_MISMATCH: 220,
|
DC_QR_FPR_MISMATCH: 220,
|
||||||
DC_QR_FPR_OK: 210,
|
DC_QR_FPR_OK: 210,
|
||||||
DC_QR_FPR_WITHOUT_ADDR: 230,
|
DC_QR_FPR_WITHOUT_ADDR: 230,
|
||||||
DC_QR_LOGIN: 520,
|
DC_QR_LOGIN: 520,
|
||||||
DC_QR_PROXY: 271,
|
|
||||||
DC_QR_REVIVE_VERIFYCONTACT: 510,
|
DC_QR_REVIVE_VERIFYCONTACT: 510,
|
||||||
DC_QR_REVIVE_VERIFYGROUP: 512,
|
DC_QR_REVIVE_VERIFYGROUP: 512,
|
||||||
DC_QR_TEXT: 330,
|
DC_QR_TEXT: 330,
|
||||||
@@ -178,7 +171,6 @@ module.exports = {
|
|||||||
DC_STR_CONFIGURATION_FAILED: 84,
|
DC_STR_CONFIGURATION_FAILED: 84,
|
||||||
DC_STR_CONNECTED: 107,
|
DC_STR_CONNECTED: 107,
|
||||||
DC_STR_CONNTECTING: 108,
|
DC_STR_CONNTECTING: 108,
|
||||||
DC_STR_CONTACT: 200,
|
|
||||||
DC_STR_CONTACT_NOT_VERIFIED: 36,
|
DC_STR_CONTACT_NOT_VERIFIED: 36,
|
||||||
DC_STR_CONTACT_SETUP_CHANGED: 37,
|
DC_STR_CONTACT_SETUP_CHANGED: 37,
|
||||||
DC_STR_CONTACT_VERIFIED: 35,
|
DC_STR_CONTACT_VERIFIED: 35,
|
||||||
@@ -272,8 +264,6 @@ module.exports = {
|
|||||||
DC_STR_REMOVE_MEMBER_BY_YOU: 130,
|
DC_STR_REMOVE_MEMBER_BY_YOU: 130,
|
||||||
DC_STR_REPLY_NOUN: 90,
|
DC_STR_REPLY_NOUN: 90,
|
||||||
DC_STR_SAVED_MESSAGES: 69,
|
DC_STR_SAVED_MESSAGES: 69,
|
||||||
DC_STR_SECUREJOIN_WAIT: 190,
|
|
||||||
DC_STR_SECUREJOIN_WAIT_TIMEOUT: 191,
|
|
||||||
DC_STR_SECURE_JOIN_GROUP_QR_DESC: 120,
|
DC_STR_SECURE_JOIN_GROUP_QR_DESC: 120,
|
||||||
DC_STR_SECURE_JOIN_REPLIES: 118,
|
DC_STR_SECURE_JOIN_REPLIES: 118,
|
||||||
DC_STR_SECURE_JOIN_STARTED: 117,
|
DC_STR_SECURE_JOIN_STARTED: 117,
|
||||||
|
|||||||
@@ -37,9 +37,5 @@ module.exports = {
|
|||||||
2111: 'DC_EVENT_CONFIG_SYNCED',
|
2111: 'DC_EVENT_CONFIG_SYNCED',
|
||||||
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
|
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
|
||||||
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED',
|
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED',
|
||||||
2150: 'DC_EVENT_WEBXDC_REALTIME_DATA',
|
2200: 'DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE'
|
||||||
2200: 'DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE',
|
|
||||||
2300: 'DC_EVENT_CHATLIST_CHANGED',
|
|
||||||
2301: 'DC_EVENT_CHATLIST_ITEM_CHANGED',
|
|
||||||
2400: 'DC_EVENT_CHANNEL_OVERFLOW'
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ export enum C {
|
|||||||
DC_DOWNLOAD_IN_PROGRESS = 1000,
|
DC_DOWNLOAD_IN_PROGRESS = 1000,
|
||||||
DC_DOWNLOAD_UNDECIPHERABLE = 30,
|
DC_DOWNLOAD_UNDECIPHERABLE = 30,
|
||||||
DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE = 2200,
|
DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE = 2200,
|
||||||
DC_EVENT_CHANNEL_OVERFLOW = 2400,
|
|
||||||
DC_EVENT_CHATLIST_CHANGED = 2300,
|
|
||||||
DC_EVENT_CHATLIST_ITEM_CHANGED = 2301,
|
|
||||||
DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED = 2021,
|
DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED = 2021,
|
||||||
DC_EVENT_CHAT_MODIFIED = 2020,
|
DC_EVENT_CHAT_MODIFIED = 2020,
|
||||||
DC_EVENT_CONFIGURE_PROGRESS = 2041,
|
DC_EVENT_CONFIGURE_PROGRESS = 2041,
|
||||||
@@ -67,7 +64,6 @@ export enum C {
|
|||||||
DC_EVENT_SMTP_MESSAGE_SENT = 103,
|
DC_EVENT_SMTP_MESSAGE_SENT = 103,
|
||||||
DC_EVENT_WARNING = 300,
|
DC_EVENT_WARNING = 300,
|
||||||
DC_EVENT_WEBXDC_INSTANCE_DELETED = 2121,
|
DC_EVENT_WEBXDC_INSTANCE_DELETED = 2121,
|
||||||
DC_EVENT_WEBXDC_REALTIME_DATA = 2150,
|
|
||||||
DC_EVENT_WEBXDC_STATUS_UPDATE = 2120,
|
DC_EVENT_WEBXDC_STATUS_UPDATE = 2120,
|
||||||
DC_GCL_ADD_ALLDONE_HINT = 4,
|
DC_GCL_ADD_ALLDONE_HINT = 4,
|
||||||
DC_GCL_ADD_SELF = 2,
|
DC_GCL_ADD_SELF = 2,
|
||||||
@@ -112,7 +108,6 @@ export enum C {
|
|||||||
DC_MSG_IMAGE = 20,
|
DC_MSG_IMAGE = 20,
|
||||||
DC_MSG_STICKER = 23,
|
DC_MSG_STICKER = 23,
|
||||||
DC_MSG_TEXT = 10,
|
DC_MSG_TEXT = 10,
|
||||||
DC_MSG_VCARD = 90,
|
|
||||||
DC_MSG_VIDEO = 50,
|
DC_MSG_VIDEO = 50,
|
||||||
DC_MSG_VIDEOCHAT_INVITATION = 70,
|
DC_MSG_VIDEOCHAT_INVITATION = 70,
|
||||||
DC_MSG_VOICE = 41,
|
DC_MSG_VOICE = 41,
|
||||||
@@ -128,13 +123,11 @@ export enum C {
|
|||||||
DC_QR_ASK_VERIFYCONTACT = 200,
|
DC_QR_ASK_VERIFYCONTACT = 200,
|
||||||
DC_QR_ASK_VERIFYGROUP = 202,
|
DC_QR_ASK_VERIFYGROUP = 202,
|
||||||
DC_QR_BACKUP = 251,
|
DC_QR_BACKUP = 251,
|
||||||
DC_QR_BACKUP2 = 252,
|
|
||||||
DC_QR_ERROR = 400,
|
DC_QR_ERROR = 400,
|
||||||
DC_QR_FPR_MISMATCH = 220,
|
DC_QR_FPR_MISMATCH = 220,
|
||||||
DC_QR_FPR_OK = 210,
|
DC_QR_FPR_OK = 210,
|
||||||
DC_QR_FPR_WITHOUT_ADDR = 230,
|
DC_QR_FPR_WITHOUT_ADDR = 230,
|
||||||
DC_QR_LOGIN = 520,
|
DC_QR_LOGIN = 520,
|
||||||
DC_QR_PROXY = 271,
|
|
||||||
DC_QR_REVIVE_VERIFYCONTACT = 510,
|
DC_QR_REVIVE_VERIFYCONTACT = 510,
|
||||||
DC_QR_REVIVE_VERIFYGROUP = 512,
|
DC_QR_REVIVE_VERIFYGROUP = 512,
|
||||||
DC_QR_TEXT = 330,
|
DC_QR_TEXT = 330,
|
||||||
@@ -178,7 +171,6 @@ export enum C {
|
|||||||
DC_STR_CONFIGURATION_FAILED = 84,
|
DC_STR_CONFIGURATION_FAILED = 84,
|
||||||
DC_STR_CONNECTED = 107,
|
DC_STR_CONNECTED = 107,
|
||||||
DC_STR_CONNTECTING = 108,
|
DC_STR_CONNTECTING = 108,
|
||||||
DC_STR_CONTACT = 200,
|
|
||||||
DC_STR_CONTACT_NOT_VERIFIED = 36,
|
DC_STR_CONTACT_NOT_VERIFIED = 36,
|
||||||
DC_STR_CONTACT_SETUP_CHANGED = 37,
|
DC_STR_CONTACT_SETUP_CHANGED = 37,
|
||||||
DC_STR_CONTACT_VERIFIED = 35,
|
DC_STR_CONTACT_VERIFIED = 35,
|
||||||
@@ -272,8 +264,6 @@ export enum C {
|
|||||||
DC_STR_REMOVE_MEMBER_BY_YOU = 130,
|
DC_STR_REMOVE_MEMBER_BY_YOU = 130,
|
||||||
DC_STR_REPLY_NOUN = 90,
|
DC_STR_REPLY_NOUN = 90,
|
||||||
DC_STR_SAVED_MESSAGES = 69,
|
DC_STR_SAVED_MESSAGES = 69,
|
||||||
DC_STR_SECUREJOIN_WAIT = 190,
|
|
||||||
DC_STR_SECUREJOIN_WAIT_TIMEOUT = 191,
|
|
||||||
DC_STR_SECURE_JOIN_GROUP_QR_DESC = 120,
|
DC_STR_SECURE_JOIN_GROUP_QR_DESC = 120,
|
||||||
DC_STR_SECURE_JOIN_REPLIES = 118,
|
DC_STR_SECURE_JOIN_REPLIES = 118,
|
||||||
DC_STR_SECURE_JOIN_STARTED = 117,
|
DC_STR_SECURE_JOIN_STARTED = 117,
|
||||||
@@ -342,9 +332,5 @@ export const EventId2EventName: { [key: number]: string } = {
|
|||||||
2111: 'DC_EVENT_CONFIG_SYNCED',
|
2111: 'DC_EVENT_CONFIG_SYNCED',
|
||||||
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
|
2120: 'DC_EVENT_WEBXDC_STATUS_UPDATE',
|
||||||
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED',
|
2121: 'DC_EVENT_WEBXDC_INSTANCE_DELETED',
|
||||||
2150: 'DC_EVENT_WEBXDC_REALTIME_DATA',
|
|
||||||
2200: 'DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE',
|
2200: 'DC_EVENT_ACCOUNTS_BACKGROUND_FETCH_DONE',
|
||||||
2300: 'DC_EVENT_CHATLIST_CHANGED',
|
|
||||||
2301: 'DC_EVENT_CHATLIST_ITEM_CHANGED',
|
|
||||||
2400: 'DC_EVENT_CHANNEL_OVERFLOW',
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -475,6 +475,47 @@ export class Context extends EventEmitter {
|
|||||||
return binding.dcn_get_msg_html(this.dcn_context, Number(messageId))
|
return binding.dcn_get_msg_html(this.dcn_context, Number(messageId))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getNextMediaMessage(
|
||||||
|
messageId: number,
|
||||||
|
msgType1: number,
|
||||||
|
msgType2: number,
|
||||||
|
msgType3: number
|
||||||
|
) {
|
||||||
|
debug(
|
||||||
|
`getNextMediaMessage ${messageId} ${msgType1} ${msgType2} ${msgType3}`
|
||||||
|
)
|
||||||
|
return this._getNextMedia(messageId, 1, msgType1, msgType2, msgType3)
|
||||||
|
}
|
||||||
|
|
||||||
|
getPreviousMediaMessage(
|
||||||
|
messageId: number,
|
||||||
|
msgType1: number,
|
||||||
|
msgType2: number,
|
||||||
|
msgType3: number
|
||||||
|
) {
|
||||||
|
debug(
|
||||||
|
`getPreviousMediaMessage ${messageId} ${msgType1} ${msgType2} ${msgType3}`
|
||||||
|
)
|
||||||
|
return this._getNextMedia(messageId, -1, msgType1, msgType2, msgType3)
|
||||||
|
}
|
||||||
|
|
||||||
|
_getNextMedia(
|
||||||
|
messageId: number,
|
||||||
|
dir: number,
|
||||||
|
msgType1: number,
|
||||||
|
msgType2: number,
|
||||||
|
msgType3: number
|
||||||
|
): number {
|
||||||
|
return binding.dcn_get_next_media(
|
||||||
|
this.dcn_context,
|
||||||
|
Number(messageId),
|
||||||
|
dir,
|
||||||
|
msgType1 || 0,
|
||||||
|
msgType2 || 0,
|
||||||
|
msgType3 || 0
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
getSecurejoinQrCode(chatId: number): string {
|
getSecurejoinQrCode(chatId: number): string {
|
||||||
debug(`getSecurejoinQrCode ${chatId}`)
|
debug(`getSecurejoinQrCode ${chatId}`)
|
||||||
return binding.dcn_get_securejoin_qr(this.dcn_context, Number(chatId))
|
return binding.dcn_get_securejoin_qr(this.dcn_context, Number(chatId))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#define NAPI_VERSION 4
|
#define NAPI_VERSION 4
|
||||||
|
#define NAPI_EXPERIMENTAL
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -1053,6 +1054,27 @@ NAPI_METHOD(dcn_get_msg_html) {
|
|||||||
NAPI_RETURN_AND_UNREF_STRING(msg_html);
|
NAPI_RETURN_AND_UNREF_STRING(msg_html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAPI_METHOD(dcn_get_next_media) {
|
||||||
|
NAPI_ARGV(6);
|
||||||
|
NAPI_DCN_CONTEXT();
|
||||||
|
NAPI_ARGV_UINT32(msg_id, 1);
|
||||||
|
NAPI_ARGV_INT32(dir, 2);
|
||||||
|
NAPI_ARGV_INT32(msg_type1, 3);
|
||||||
|
NAPI_ARGV_INT32(msg_type2, 4);
|
||||||
|
NAPI_ARGV_INT32(msg_type3, 5);
|
||||||
|
|
||||||
|
//TRACE("calling..");
|
||||||
|
uint32_t next_id = dc_get_next_media(dcn_context->dc_context,
|
||||||
|
msg_id,
|
||||||
|
dir,
|
||||||
|
msg_type1,
|
||||||
|
msg_type2,
|
||||||
|
msg_type3);
|
||||||
|
//TRACE("result %d", next_id);
|
||||||
|
|
||||||
|
NAPI_RETURN_UINT32(next_id);
|
||||||
|
}
|
||||||
|
|
||||||
NAPI_METHOD(dcn_set_chat_visibility) {
|
NAPI_METHOD(dcn_set_chat_visibility) {
|
||||||
NAPI_ARGV(3);
|
NAPI_ARGV(3);
|
||||||
NAPI_DCN_CONTEXT();
|
NAPI_DCN_CONTEXT();
|
||||||
@@ -3422,6 +3444,7 @@ NAPI_INIT() {
|
|||||||
NAPI_EXPORT_FUNCTION(dcn_get_msg_cnt);
|
NAPI_EXPORT_FUNCTION(dcn_get_msg_cnt);
|
||||||
NAPI_EXPORT_FUNCTION(dcn_get_msg_info);
|
NAPI_EXPORT_FUNCTION(dcn_get_msg_info);
|
||||||
NAPI_EXPORT_FUNCTION(dcn_get_msg_html);
|
NAPI_EXPORT_FUNCTION(dcn_get_msg_html);
|
||||||
|
NAPI_EXPORT_FUNCTION(dcn_get_next_media);
|
||||||
NAPI_EXPORT_FUNCTION(dcn_set_chat_visibility);
|
NAPI_EXPORT_FUNCTION(dcn_set_chat_visibility);
|
||||||
NAPI_EXPORT_FUNCTION(dcn_get_securejoin_qr);
|
NAPI_EXPORT_FUNCTION(dcn_get_securejoin_qr);
|
||||||
NAPI_EXPORT_FUNCTION(dcn_get_securejoin_qr_svg);
|
NAPI_EXPORT_FUNCTION(dcn_get_securejoin_qr_svg);
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ function createTempUser(chatmailDomain) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('static tests', function () {
|
describe('static tests', function () {
|
||||||
this.timeout(60 * 5 * 1000) // increase timeout to 5 min
|
|
||||||
|
|
||||||
it('reverse lookup of events', function () {
|
it('reverse lookup of events', function () {
|
||||||
const eventKeys = Object.keys(EventId2EventName).map((k) => Number(k))
|
const eventKeys = Object.keys(EventId2EventName).map((k) => Number(k))
|
||||||
const eventValues = Object.values(EventId2EventName)
|
const eventValues = Object.values(EventId2EventName)
|
||||||
@@ -271,7 +269,7 @@ describe('Basic offline Tests', function () {
|
|||||||
'sync_msgs',
|
'sync_msgs',
|
||||||
'sentbox_watch',
|
'sentbox_watch',
|
||||||
'show_emails',
|
'show_emails',
|
||||||
'proxy_enabled',
|
'socks5_enabled',
|
||||||
'sqlite_version',
|
'sqlite_version',
|
||||||
'uptime',
|
'uptime',
|
||||||
'used_account_settings',
|
'used_account_settings',
|
||||||
@@ -703,7 +701,7 @@ describe('Offline Tests with unconfigured account', function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('Integration tests', function () {
|
describe('Integration tests', function () {
|
||||||
this.timeout(60 * 5 * 1000) // increase timeout to 5 min
|
this.timeout(60 * 3000) // increase timeout to 1min
|
||||||
|
|
||||||
let [dc, context, accountId, directory, account] = [
|
let [dc, context, accountId, directory, account] = [
|
||||||
null,
|
null,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
"chai": "~4.3.10",
|
"chai": "~4.3.10",
|
||||||
"chai-as-promised": "^7.1.1",
|
"chai-as-promised": "^7.1.1",
|
||||||
"mocha": "^8.2.1",
|
"mocha": "^8.2.1",
|
||||||
"node-gyp": "~10.1.0",
|
"node-gyp": "^10.0.0",
|
||||||
"prebuildify": "^5.0.1",
|
"prebuildify": "^5.0.1",
|
||||||
"prebuildify-ci": "^1.0.5",
|
"prebuildify-ci": "^1.0.5",
|
||||||
"prettier": "^3.0.3",
|
"prettier": "^3.0.3",
|
||||||
@@ -55,5 +55,5 @@
|
|||||||
"test:mocha": "mocha node/test/test.mjs --growl --reporter=spec --bail --exit"
|
"test:mocha": "mocha node/test/test.mjs --growl --reporter=spec --bail --exit"
|
||||||
},
|
},
|
||||||
"types": "node/dist/index.d.ts",
|
"types": "node/dist/index.d.ts",
|
||||||
"version": "1.147.0"
|
"version": "1.137.2"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ def test_group_tracking_plugin(acfactory, lp):
|
|||||||
|
|
||||||
ac1, ac2 = acfactory.get_online_accounts(2)
|
ac1, ac2 = acfactory.get_online_accounts(2)
|
||||||
|
|
||||||
|
botproc.fnmatch_lines(
|
||||||
|
"""
|
||||||
|
*ac_configure_completed*
|
||||||
|
""",
|
||||||
|
)
|
||||||
ac1.add_account_plugin(FFIEventLogger(ac1))
|
ac1.add_account_plugin(FFIEventLogger(ac1))
|
||||||
ac2.add_account_plugin(FFIEventLogger(ac2))
|
ac2.add_account_plugin(FFIEventLogger(ac2))
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "deltachat"
|
name = "deltachat"
|
||||||
version = "1.147.0"
|
version = "1.137.2"
|
||||||
description = "Python bindings for the Delta Chat Core library using CFFI against the Rust-implemented libdeltachat"
|
description = "Python bindings for the Delta Chat Core library using CFFI against the Rust-implemented libdeltachat"
|
||||||
readme = "README.rst"
|
readme = "README.rst"
|
||||||
requires-python = ">=3.7"
|
requires-python = ">=3.7"
|
||||||
@@ -46,7 +46,7 @@ deltachat = [
|
|||||||
line-length = 120
|
line-length = 120
|
||||||
|
|
||||||
[tool.ruff]
|
[tool.ruff]
|
||||||
lint.select = ["E", "F", "W", "YTT", "C4", "ISC", "ICN", "TID", "DTZ", "PLC", "PLE", "PLW", "PIE", "COM", "UP004", "UP010", "UP031", "UP032", "ANN204"]
|
select = ["E", "F", "W", "YTT", "C4", "ISC", "ICN", "TID", "DTZ", "PLC", "PLE", "PLW", "PIE", "COM", "UP004", "UP010", "UP031", "UP032", "ANN204"]
|
||||||
line-length = 120
|
line-length = 120
|
||||||
|
|
||||||
[tool.isort]
|
[tool.isort]
|
||||||
|
|||||||
@@ -194,13 +194,15 @@ class Account:
|
|||||||
assert res != ffi.NULL, f"config value not found for: {name!r}"
|
assert res != ffi.NULL, f"config value not found for: {name!r}"
|
||||||
return from_dc_charpointer(res)
|
return from_dc_charpointer(res)
|
||||||
|
|
||||||
def _preconfigure_keypair(self, secret: str) -> None:
|
def _preconfigure_keypair(self, addr: str, secret: str) -> None:
|
||||||
"""See dc_preconfigure_keypair() in deltachat.h.
|
"""See dc_preconfigure_keypair() in deltachat.h.
|
||||||
|
|
||||||
In other words, you don't need this.
|
In other words, you don't need this.
|
||||||
"""
|
"""
|
||||||
res = lib.dc_preconfigure_keypair(
|
res = lib.dc_preconfigure_keypair(
|
||||||
self._dc_context,
|
self._dc_context,
|
||||||
|
as_dc_charpointer(addr),
|
||||||
|
ffi.NULL,
|
||||||
as_dc_charpointer(secret),
|
as_dc_charpointer(secret),
|
||||||
)
|
)
|
||||||
if res == 0:
|
if res == 0:
|
||||||
|
|||||||
@@ -8,19 +8,19 @@ import io
|
|||||||
import pathlib
|
import pathlib
|
||||||
import ssl
|
import ssl
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from typing import List, TYPE_CHECKING
|
from typing import List
|
||||||
|
|
||||||
from imap_tools import (
|
from imap_tools import (
|
||||||
AND,
|
AND,
|
||||||
Header,
|
Header,
|
||||||
MailBox,
|
MailBox,
|
||||||
|
MailBoxTls,
|
||||||
MailMessage,
|
MailMessage,
|
||||||
MailMessageFlags,
|
MailMessageFlags,
|
||||||
errors,
|
errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
from deltachat import Account, const
|
||||||
from deltachat import Account
|
|
||||||
|
|
||||||
FLAGS = b"FLAGS"
|
FLAGS = b"FLAGS"
|
||||||
FETCH = b"FETCH"
|
FETCH = b"FETCH"
|
||||||
@@ -28,7 +28,7 @@ ALL = "1:*"
|
|||||||
|
|
||||||
|
|
||||||
class DirectImap:
|
class DirectImap:
|
||||||
def __init__(self, account: "Account") -> None:
|
def __init__(self, account: Account) -> None:
|
||||||
self.account = account
|
self.account = account
|
||||||
self.logid = account.get_config("displayname") or id(account)
|
self.logid = account.get_config("displayname") or id(account)
|
||||||
self._idling = False
|
self._idling = False
|
||||||
@@ -36,13 +36,27 @@ class DirectImap:
|
|||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
host = self.account.get_config("configured_mail_server")
|
host = self.account.get_config("configured_mail_server")
|
||||||
port = 993
|
port = int(self.account.get_config("configured_mail_port"))
|
||||||
|
security = int(self.account.get_config("configured_mail_security"))
|
||||||
|
|
||||||
user = self.account.get_config("addr")
|
user = self.account.get_config("addr")
|
||||||
host = user.rsplit("@")[-1]
|
|
||||||
pw = self.account.get_config("mail_pw")
|
pw = self.account.get_config("mail_pw")
|
||||||
|
|
||||||
self.conn = MailBox(host, port, ssl_context=ssl.create_default_context())
|
if security == const.DC_SOCKET_PLAIN:
|
||||||
|
ssl_context = None
|
||||||
|
else:
|
||||||
|
ssl_context = ssl.create_default_context()
|
||||||
|
|
||||||
|
# don't check if certificate hostname doesn't match target hostname
|
||||||
|
ssl_context.check_hostname = False
|
||||||
|
|
||||||
|
# don't check if the certificate is trusted by a certificate authority
|
||||||
|
ssl_context.verify_mode = ssl.CERT_NONE
|
||||||
|
|
||||||
|
if security == const.DC_SOCKET_STARTTLS:
|
||||||
|
self.conn = MailBoxTls(host, port, ssl_context=ssl_context)
|
||||||
|
elif security == const.DC_SOCKET_PLAIN or security == const.DC_SOCKET_SSL:
|
||||||
|
self.conn = MailBox(host, port, ssl_context=ssl_context)
|
||||||
self.conn.login(user, pw)
|
self.conn.login(user, pw)
|
||||||
|
|
||||||
self.select_folder("INBOX")
|
self.select_folder("INBOX")
|
||||||
|
|||||||
@@ -328,12 +328,10 @@ class EventThread(threading.Thread):
|
|||||||
elif name == "DC_EVENT_REACTIONS_CHANGED":
|
elif name == "DC_EVENT_REACTIONS_CHANGED":
|
||||||
assert ffi_event.data1 > 0
|
assert ffi_event.data1 > 0
|
||||||
msg = account.get_message_by_id(ffi_event.data2)
|
msg = account.get_message_by_id(ffi_event.data2)
|
||||||
if msg is not None:
|
yield "ac_reactions_changed", {"message": msg}
|
||||||
yield "ac_reactions_changed", {"message": msg}
|
|
||||||
elif name == "DC_EVENT_MSG_DELIVERED":
|
elif name == "DC_EVENT_MSG_DELIVERED":
|
||||||
msg = account.get_message_by_id(ffi_event.data2)
|
msg = account.get_message_by_id(ffi_event.data2)
|
||||||
if msg is not None:
|
yield "ac_message_delivered", {"message": msg}
|
||||||
yield "ac_message_delivered", {"message": msg}
|
|
||||||
elif name == "DC_EVENT_CHAT_MODIFIED":
|
elif name == "DC_EVENT_CHAT_MODIFIED":
|
||||||
chat = account.get_chat_by_id(ffi_event.data1)
|
chat = account.get_chat_by_id(ffi_event.data1)
|
||||||
yield "ac_chat_modified", {"chat": chat}
|
yield "ac_chat_modified", {"chat": chat}
|
||||||
|
|||||||
@@ -364,9 +364,6 @@ class Message:
|
|||||||
else:
|
else:
|
||||||
# load message from db to get a fresh/current state
|
# load message from db to get a fresh/current state
|
||||||
dc_msg = ffi.gc(lib.dc_get_msg(self.account._dc_context, self.id), lib.dc_msg_unref)
|
dc_msg = ffi.gc(lib.dc_get_msg(self.account._dc_context, self.id), lib.dc_msg_unref)
|
||||||
# Message could be trashed, use the cached object if so.
|
|
||||||
if dc_msg == ffi.NULL:
|
|
||||||
dc_msg = self._dc_msg
|
|
||||||
return lib.dc_msg_get_state(dc_msg)
|
return lib.dc_msg_get_state(dc_msg)
|
||||||
|
|
||||||
def is_in_fresh(self):
|
def is_in_fresh(self):
|
||||||
@@ -395,7 +392,7 @@ class Message:
|
|||||||
|
|
||||||
def is_outgoing(self):
|
def is_outgoing(self):
|
||||||
"""Return True if Message is outgoing."""
|
"""Return True if Message is outgoing."""
|
||||||
return lib.dc_msg_get_state(self._dc_msg) in (
|
return self._msgstate in (
|
||||||
const.DC_STATE_OUT_PREPARING,
|
const.DC_STATE_OUT_PREPARING,
|
||||||
const.DC_STATE_OUT_PENDING,
|
const.DC_STATE_OUT_PENDING,
|
||||||
const.DC_STATE_OUT_FAILED,
|
const.DC_STATE_OUT_FAILED,
|
||||||
@@ -487,9 +484,6 @@ class Message:
|
|||||||
|
|
||||||
# load message from db to get a fresh/current state
|
# load message from db to get a fresh/current state
|
||||||
dc_msg = ffi.gc(lib.dc_get_msg(self.account._dc_context, self.id), lib.dc_msg_unref)
|
dc_msg = ffi.gc(lib.dc_get_msg(self.account._dc_context, self.id), lib.dc_msg_unref)
|
||||||
# Message could be trashed, use the cached object if so.
|
|
||||||
if dc_msg == ffi.NULL:
|
|
||||||
dc_msg = self._dc_msg
|
|
||||||
return lib.dc_msg_get_download_state(dc_msg)
|
return lib.dc_msg_get_download_state(dc_msg)
|
||||||
|
|
||||||
def download_full(self) -> None:
|
def download_full(self) -> None:
|
||||||
|
|||||||
@@ -275,7 +275,6 @@ class ACSetup:
|
|||||||
def __init__(self, testprocess, init_time) -> None:
|
def __init__(self, testprocess, init_time) -> None:
|
||||||
self._configured_events = Queue()
|
self._configured_events = Queue()
|
||||||
self._account2state: Dict[Account, str] = {}
|
self._account2state: Dict[Account, str] = {}
|
||||||
self._account2config: Dict[Account, Dict[str, str]] = {}
|
|
||||||
self._imap_cleaned: Set[str] = set()
|
self._imap_cleaned: Set[str] = set()
|
||||||
self.testprocess = testprocess
|
self.testprocess = testprocess
|
||||||
self.init_time = init_time
|
self.init_time = init_time
|
||||||
@@ -337,8 +336,6 @@ class ACSetup:
|
|||||||
if not success:
|
if not success:
|
||||||
pytest.fail(f"configuring online account {acc} failed: {comment}")
|
pytest.fail(f"configuring online account {acc} failed: {comment}")
|
||||||
self._account2state[acc] = self.CONFIGURED
|
self._account2state[acc] = self.CONFIGURED
|
||||||
if acc in self._account2config:
|
|
||||||
acc.update_config(self._account2config[acc])
|
|
||||||
return acc
|
return acc
|
||||||
|
|
||||||
def _onconfigure_start_io(self, acc):
|
def _onconfigure_start_io(self, acc):
|
||||||
@@ -462,7 +459,7 @@ class ACFactory:
|
|||||||
def remove_preconfigured_keys(self) -> None:
|
def remove_preconfigured_keys(self) -> None:
|
||||||
self._preconfigured_keys = []
|
self._preconfigured_keys = []
|
||||||
|
|
||||||
def _preconfigure_key(self, account):
|
def _preconfigure_key(self, account, addr):
|
||||||
# Only set a preconfigured key if we haven't used it yet for another account.
|
# Only set a preconfigured key if we haven't used it yet for another account.
|
||||||
try:
|
try:
|
||||||
keyname = self._preconfigured_keys.pop(0)
|
keyname = self._preconfigured_keys.pop(0)
|
||||||
@@ -471,9 +468,9 @@ class ACFactory:
|
|||||||
else:
|
else:
|
||||||
fname_sec = self.data.read_path(f"key/{keyname}-secret.asc")
|
fname_sec = self.data.read_path(f"key/{keyname}-secret.asc")
|
||||||
if fname_sec:
|
if fname_sec:
|
||||||
account._preconfigure_keypair(fname_sec)
|
account._preconfigure_keypair(addr, fname_sec)
|
||||||
return True
|
return True
|
||||||
print("WARN: could not use preconfigured keys")
|
print(f"WARN: could not use preconfigured keys for {addr!r}")
|
||||||
|
|
||||||
def get_pseudo_configured_account(self, passphrase: Optional[str] = None) -> Account:
|
def get_pseudo_configured_account(self, passphrase: Optional[str] = None) -> Account:
|
||||||
# do a pseudo-configured account
|
# do a pseudo-configured account
|
||||||
@@ -492,7 +489,7 @@ class ACFactory:
|
|||||||
"configured": "1",
|
"configured": "1",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
self._preconfigure_key(ac)
|
self._preconfigure_key(ac, addr)
|
||||||
self._acsetup.init_logging(ac)
|
self._acsetup.init_logging(ac)
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
@@ -525,10 +522,8 @@ class ACFactory:
|
|||||||
configdict.setdefault("mvbox_move", False)
|
configdict.setdefault("mvbox_move", False)
|
||||||
configdict.setdefault("sentbox_watch", False)
|
configdict.setdefault("sentbox_watch", False)
|
||||||
configdict.setdefault("sync_msgs", False)
|
configdict.setdefault("sync_msgs", False)
|
||||||
configdict.setdefault("delete_server_after", 0)
|
|
||||||
ac.update_config(configdict)
|
ac.update_config(configdict)
|
||||||
self._acsetup._account2config[ac] = configdict
|
self._preconfigure_key(ac, configdict["addr"])
|
||||||
self._preconfigure_key(ac)
|
|
||||||
return ac
|
return ac
|
||||||
|
|
||||||
def wait_configured(self, account) -> None:
|
def wait_configured(self, account) -> None:
|
||||||
@@ -553,15 +548,6 @@ class ACFactory:
|
|||||||
|
|
||||||
bot_cfg = self.get_next_liveconfig()
|
bot_cfg = self.get_next_liveconfig()
|
||||||
bot_ac = self.prepare_account_from_liveconfig(bot_cfg)
|
bot_ac = self.prepare_account_from_liveconfig(bot_cfg)
|
||||||
self._acsetup.start_configure(bot_ac)
|
|
||||||
self.wait_configured(bot_ac)
|
|
||||||
bot_ac.start_io()
|
|
||||||
# Wait for DC_EVENT_IMAP_INBOX_IDLE so that all emails appeared in the bot's Inbox later are
|
|
||||||
# considered new and not existing ones, and thus processed by the bot.
|
|
||||||
print(bot_ac._logid, "waiting for inbox IDLE to become ready")
|
|
||||||
bot_ac._evtracker.wait_idle_inbox_ready()
|
|
||||||
bot_ac.stop_io()
|
|
||||||
self._acsetup._account2state[bot_ac] = self._acsetup.IDLEREADY
|
|
||||||
|
|
||||||
# Forget ac as it will be opened by the bot subprocess
|
# Forget ac as it will be opened by the bot subprocess
|
||||||
# but keep something in the list to not confuse account generation
|
# but keep something in the list to not confuse account generation
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ def test_db_busy_error(acfactory):
|
|||||||
|
|
||||||
# make a number of accounts
|
# make a number of accounts
|
||||||
accounts = acfactory.get_many_online_accounts(3)
|
accounts = acfactory.get_many_online_accounts(3)
|
||||||
log(f"created {len(accounts)} accounts")
|
log("created %s accounts" % len(accounts))
|
||||||
|
|
||||||
# put a bigfile into each account
|
# put a bigfile into each account
|
||||||
for acc in accounts:
|
for acc in accounts:
|
||||||
acc.bigfile = os.path.join(acc.get_blobdir(), "bigfile")
|
acc.bigfile = os.path.join(acc.get_blobdir(), "bigfile")
|
||||||
with open(acc.bigfile, "wb") as f:
|
with open(acc.bigfile, "wb") as f:
|
||||||
f.write(b"01234567890" * 1000_000)
|
f.write(b"01234567890" * 1000_000)
|
||||||
log(f"created {len(accounts)} bigfiles")
|
log("created %s bigfiles" % len(accounts))
|
||||||
|
|
||||||
contact_addrs = [acc.get_self_contact().addr for acc in accounts]
|
contact_addrs = [acc.get_self_contact().addr for acc in accounts]
|
||||||
chat = accounts[0].create_group_chat("stress-group")
|
chat = accounts[0].create_group_chat("stress-group")
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user