From 47e0f224ca6d7acecc7e9e1db47731ea701df6c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 10 Jun 2021 06:26:18 +0000 Subject: [PATCH 01/25] cargo: bump itertools from 0.10.0 to 0.10.1 Bumps [itertools](https://github.com/rust-itertools/itertools) from 0.10.0 to 0.10.1. - [Release notes](https://github.com/rust-itertools/itertools/releases) - [Changelog](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-itertools/itertools/compare/v0.10.0...v0.10.1) --- updated-dependencies: - dependency-name: itertools dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1e569e0a..6fc72e732 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -865,7 +865,7 @@ dependencies = [ "clap", "criterion-plot", "csv", - "itertools 0.10.0", + "itertools 0.10.1", "lazy_static", "num-traits", "oorandom", @@ -1136,7 +1136,7 @@ dependencies = [ "hex", "image", "indexmap", - "itertools 0.10.0", + "itertools 0.10.1", "kamadak-exif", "lettre_email", "libc", @@ -2028,9 +2028,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" +checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" dependencies = [ "either", ] diff --git a/Cargo.toml b/Cargo.toml index dae10fdbe..3a7cfd998 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ futures = "0.3.15" hex = "0.4.0" image = { version = "0.23.5", default-features=false, features = ["gif", "jpeg", "ico", "png", "pnm", "webp", "bmp"] } indexmap = "1.3.0" -itertools = "0.10.0" +itertools = "0.10.1" kamadak-exif = "0.5" lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" } libc = "0.2.95" From 50f680a00b06d3dfc02da88e8db86bcf67c6618c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Jun 2021 06:17:13 +0000 Subject: [PATCH 02/25] cargo: bump anyhow from 1.0.40 to 1.0.41 Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.40 to 1.0.41. - [Release notes](https://github.com/dtolnay/anyhow/releases) - [Commits](https://github.com/dtolnay/anyhow/compare/1.0.40...1.0.41) --- updated-dependencies: - dependency-name: anyhow dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- deltachat-ffi/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1e569e0a..f13bdeb46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,9 +138,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" +checksum = "15af2628f6890fe2609a3b91bef4c83450512802e59489f9c1cb1fa5df064a61" [[package]] name = "arrayvec" diff --git a/Cargo.toml b/Cargo.toml index dae10fdbe..6756ef124 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ lto = true deltachat_derive = { path = "./deltachat_derive" } ansi_term = { version = "0.12.1", optional = true } -anyhow = "1.0.40" +anyhow = "1.0.41" async-imap = "0.5.0" async-native-tls = { version = "0.3.3" } async-smtp = { git = "https://github.com/async-email/async-smtp", rev="2275fd8d13e39b2c58d6605c786ff06ff9e05708" } diff --git a/deltachat-ffi/Cargo.toml b/deltachat-ffi/Cargo.toml index ba499c923..d8eacc5d0 100644 --- a/deltachat-ffi/Cargo.toml +++ b/deltachat-ffi/Cargo.toml @@ -21,7 +21,7 @@ human-panic = "1.0.1" num-traits = "0.2.6" serde_json = "1.0" async-std = "1.9.0" -anyhow = "1.0.40" +anyhow = "1.0.41" thiserror = "1.0.25" rand = "0.7.3" From c616b65ce49e4966e878af2b447d67294644293a Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 10 Jun 2021 14:41:14 +0200 Subject: [PATCH 03/25] allow sending stickers via repl tool --- examples/repl/cmdline.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index e6baac1fe..fdaeb88a1 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -372,6 +372,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu getlocations []\n\ send \n\ sendimage []\n\ + sendsticker []\n\ sendfile []\n\ sendhtml []\n\ videochat\n\ @@ -865,12 +866,14 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu ensure!(sel_chat.is_some(), "No chat selected."); chat::send_text_msg(&context, sel_chat.as_ref().unwrap().get_id(), "".into()).await?; } - "sendimage" | "sendfile" => { + "sendimage" | "sendsticker" | "sendfile" => { ensure!(sel_chat.is_some(), "No chat selected."); ensure!(!arg1.is_empty(), "No file given."); let mut msg = Message::new(if arg0 == "sendimage" { Viewtype::Image + } else if arg0 == "sendsticker" { + Viewtype::Sticker } else { Viewtype::File }); From 6c530b4c771e760b43fbe61eeb0646f17222b198 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 10 Jun 2021 16:40:06 +0200 Subject: [PATCH 04/25] test sending and receiving stickers --- src/chat.rs | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/chat.rs b/src/chat.rs index a3d53e65f..a52213094 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3066,6 +3066,8 @@ mod tests { use crate::contact::Contact; use crate::dc_receive_imf::dc_receive_imf; use crate::test_utils::TestContext; + use async_std::fs::File; + use async_std::prelude::*; #[async_std::test] async fn test_chat_info() { @@ -4023,4 +4025,65 @@ mod tests { Ok(()) } + + async fn test_sticker(filename: &str, bytes: &[u8], w: i32, h: i32) -> Result<()> { + let alice = TestContext::new_alice().await; + let bob = TestContext::new_bob().await; + let alice_chat = alice.create_chat(&bob).await; + let bob_chat = bob.create_chat(&alice).await; + + let file = alice.get_blobdir().join(filename); + File::create(&file).await?.write_all(bytes).await?; + + let mut msg = Message::new(Viewtype::Sticker); + msg.set_file(file.to_str().unwrap(), None); + + let sent_msg = alice.send_msg(alice_chat.id, &mut msg).await; + let mime = sent_msg.payload(); + assert_eq!(mime.match_indices("Chat-Content: sticker").count(), 1); + + bob.recv_msg(&sent_msg).await; + let msg = bob.get_last_msg().await; + assert_eq!(msg.chat_id, bob_chat.id); + assert_eq!(msg.get_viewtype(), Viewtype::Sticker); + assert_eq!(msg.get_filename(), Some(filename.to_string())); + assert_eq!(msg.get_width(), w); + assert_eq!(msg.get_height(), h); + assert!(msg.get_filebytes(&bob).await > 250); + + Ok(()) + } + + #[async_std::test] + async fn test_sticker_png() -> Result<()> { + test_sticker( + "sticker.png", + include_bytes!("../test-data/image/avatar64x64.png"), + 64, + 64, + ) + .await + } + + #[async_std::test] + async fn test_sticker_jpeg() -> Result<()> { + test_sticker( + "sticker.jpg", + include_bytes!("../test-data/image/avatar1000x1000.jpg"), + 1000, + 1000, + ) + .await + } + + #[async_std::test] + async fn test_sticker_gif() -> Result<()> { + test_sticker( + "sticker.gif", + include_bytes!("../test-data/image/image100x50.gif"), + 100, + 50, + ) + .await + } } From 4fe3a80f968a26ebcd93bc2e5842f05c82a6f0ee Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 10 Jun 2021 20:19:37 +0200 Subject: [PATCH 05/25] allow stickers with gif-images --- src/mimeparser.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mimeparser.rs b/src/mimeparser.rs index e9cdd363a..d64c856f9 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -398,7 +398,7 @@ impl MimeMessage { if part.typ == Viewtype::Audio && self.get(HeaderDef::ChatVoiceMessage).is_some() { part.typ = Viewtype::Voice; } - if part.typ == Viewtype::Image { + if part.typ == Viewtype::Image || part.typ == Viewtype::Gif { if let Some(value) = self.get(HeaderDef::ChatContent) { if value == "sticker" { part.typ = Viewtype::Sticker; From 056721b916c28aea86d073af44afe242f20d5ce2 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 10 Jun 2021 13:24:57 +0200 Subject: [PATCH 06/25] update spec to new Chat-User-Avatar usage --- spec.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec.md b/spec.md index 1747cef2b..6f4831143 100644 --- a/spec.md +++ b/spec.md @@ -1,6 +1,6 @@ # chat-mail specification -Version: 0.32.0 +Version: 0.33.0 Status: In-progress Format: [Semantic Line Breaks](https://sembr.org/) @@ -301,9 +301,9 @@ to add a `Chat-Group-Avatar` only on image changes. A user MAY have a profile-image that MAY be distributed to their contacts. To change or set the profile-image, -the messenger MUST attach an image file to a message -and MUST add the header `Chat-User-Avatar` -with the value set to the image name. +the messenger MUST add the header `Chat-User-Avatar: base64:IMAGEDATA`. +To bypass limits of headers, it is recommended not to use the outer header +and to limit the size to 20k. To remove the profile-image, the messenger MUST add the header `Chat-User-Avatar: 0`. @@ -320,19 +320,14 @@ The messenger SHOULD NOT send an explicit mail to normal MUAs. From: sender@domain To: rcpt@domain Chat-Version: 1.0 - Chat-User-Avatar: photo.jpg Subject: Chat: Hello, ... Content-Type: multipart/mixed; boundary="==break==" --==break== Content-Type: text/plain + Chat-User-Avatar: base64:AKCgkJi3j4l5kjoldfUAKCgkJi3j4lldfHjgWICwgIEBQY ... Hello, I've changed my profile image. - --==break== - Content-Type: image/jpeg - Content-Disposition: attachment; filename="photo.jpg" - - AKCgkJi3j4l5kjoldfUAKCgkJi3j4lldfHjgWICwgIEBQYFBA ... --==break==-- The image format SHOULD be image/jpeg or image/png. @@ -342,6 +337,11 @@ in the same message. To save data, it is RECOMMENDED to add a `Chat-User-Avatar` header only on image changes. +In older specs, the profile-image was sent as an attachment +and `Chat-User-Avatar:` specified its name. +However, it turned out that these attachements are kind of unuexpected to users, +therefore the profile-image go to the header now. + # Locations From 67f8fb4b66a2568d60d3567071d234d9af915ca1 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 10 Jun 2021 13:42:37 +0200 Subject: [PATCH 07/25] update spec to Chat-Content: sticker --- spec.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/spec.md b/spec.md index 6f4831143..565a1c53c 100644 --- a/spec.md +++ b/spec.md @@ -401,6 +401,40 @@ it is fine if the location is detected on forwarding etc. +# Stickers + +Stickers are send as normal images +with the additional header `Chat-Content: sticker`. + +It is discouraged to send stickers together with user generated text, +however, stickers can be used as a reply to a message +and also the footer should be set as usual. + + From: alice@example.org + To: bob@example.com + Chat-Version: 1.0 + Chat-Content: sticker + Message-ID: Mr.12345uvwxyZ.0005@example.org + Subject: Message from Alice + Content-Type: multipart/mixed; boundary="==break==" + + --==break== + Content-Type: text/plain + + -- + Hi there! I am using this new messenger! + --==break== + Content-Type: image/png + Content-Disposition: attachment; filename="sticker.png" + + R0lGODlhpAGkAfe9AP+zd2eQkZhrI//z9v++PMb///+scrdDT3BtbtrZ2f/LQSsREcdIVf9 ... + --==break==-- + +Typical sticker formats are `image/png`, `image/gif` and `image/webp`. +Animated stickers are supported +by just using an image format that supports animation. + + # Miscellaneous Messengers SHOULD use the header `In-Reply-To` as usual. From c07c5bb358a50543005e22961359f4e94f1c9263 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 10 Jun 2021 13:44:44 +0200 Subject: [PATCH 08/25] create own topic for Voice messages, update year --- spec.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spec.md b/spec.md index 565a1c53c..54893eff7 100644 --- a/spec.md +++ b/spec.md @@ -435,9 +435,7 @@ Animated stickers are supported by just using an image format that supports animation. -# Miscellaneous - -Messengers SHOULD use the header `In-Reply-To` as usual. +# Voice messages Messengers SHOULD add a `Chat-Voice-message: 1` header if an attached audio file is a voice message. @@ -451,6 +449,11 @@ This allows the receiver to show the time without knowing the file format. Chat-Voice-Message: 1 Chat-Duration: 10000 + +# Miscellaneous + +Messengers SHOULD use the header `In-Reply-To` as usual. + Messengers MAY send and receive Message Disposition Notifications (MDNs, [RFC 8098](https://tools.ietf.org/html/rfc8098), [RFC 3503](https://tools.ietf.org/html/rfc3503)) @@ -471,4 +474,4 @@ as the sending time of the message as indicated by its Date header, or the time of first receipt if that date is in the future or unavailable. -Copyright © 2017-2020 Delta Chat contributors. +Copyright © 2017-2021 Delta Chat contributors. From 368fa9fc44b9f4bdfe21098a4907151ad51480ce Mon Sep 17 00:00:00 2001 From: Hocuri Date: Thu, 10 Jun 2021 18:52:09 +0200 Subject: [PATCH 09/25] Test image rotation --- src/blob.rs | 157 +++++++++++++----- .../rectangle2000x1800-rotated.jpg.xml | 7 + .../rectangle200x180-rotated.jpg.xml | 7 + .../image/rectangle2000x1800-rotated.jpg | Bin 0 -> 45773 bytes test-data/image/rectangle200x180-rotated.jpg | Bin 0 -> 2147 bytes 5 files changed, 134 insertions(+), 37 deletions(-) create mode 100644 test-data/image/.comments/rectangle2000x1800-rotated.jpg.xml create mode 100644 test-data/image/.comments/rectangle200x180-rotated.jpg.xml create mode 100644 test-data/image/rectangle2000x1800-rotated.jpg create mode 100644 test-data/image/rectangle200x180-rotated.jpg diff --git a/src/blob.rs b/src/blob.rs index d8c7d56cf..d13a33343 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -622,6 +622,7 @@ mod tests { use super::*; use crate::{message::Message, test_utils::TestContext}; + use image::Pixel; #[async_std::test] async fn test_create() { @@ -921,47 +922,129 @@ mod tests { } #[async_std::test] - async fn test_media_quality() -> anyhow::Result<()> { - for (media_quality_config, image_size) in vec![ - (Some("0"), 1000), // BALANCED_IMAGE_SIZE > 1000, the original image size, so the image is not scaled down - (Some("1"), WORSE_IMAGE_SIZE), - ] - .into_iter() - { - let alice = TestContext::new_alice().await; - let bob = TestContext::new_bob().await; - alice - .set_config(Config::MediaQuality, media_quality_config) - .await?; + async fn test_recode_image() { + let bytes = include_bytes!("../test-data/image/avatar1000x1000.jpg"); + // BALANCED_IMAGE_SIZE > 1000, the original image size, so the image is not scaled down: + send_image_check_mediaquality(Some("0"), bytes, 1000, 1000, 0, 1000, 1000) + .await + .unwrap(); + send_image_check_mediaquality( + Some("1"), + bytes, + 1000, + 1000, + 0, + WORSE_IMAGE_SIZE, + WORSE_IMAGE_SIZE, + ) + .await + .unwrap(); - let file = alice.get_blobdir().join("file.jpg"); - let bytes = include_bytes!("../test-data/image/avatar1000x1000.jpg"); - File::create(&file).await?.write_all(bytes).await?; + let bytes = include_bytes!("../test-data/image/rectangle2000x1800-rotated.jpg"); + let img_rotated = send_image_check_mediaquality( + Some("0"), + bytes, + 2000, + 1800, + 270, + BALANCED_IMAGE_SIZE * 1800 / 2000, + BALANCED_IMAGE_SIZE, + ) + .await + .unwrap(); - let img = image::open(&file)?; - assert_eq!(img.width(), 1000); - assert_eq!(img.height(), 1000); + assert_correct_rotataion(&img_rotated); - let mut msg = Message::new(Viewtype::Image); - msg.set_file(file.to_str().unwrap(), None); - let chat = alice.create_chat(&bob).await; - let sent = alice.send_msg(chat.id, &mut msg).await; + let mut bytes = vec![]; + img_rotated + .write_to(&mut bytes, image::ImageFormat::Jpeg) + .unwrap(); + let img_rotated = send_image_check_mediaquality( + Some("0"), + &bytes, + BALANCED_IMAGE_SIZE * 1800 / 2000, + BALANCED_IMAGE_SIZE, + 0, + BALANCED_IMAGE_SIZE * 1800 / 2000, + BALANCED_IMAGE_SIZE, + ) + .await + .unwrap(); - let alice_msg = alice.get_last_msg().await; - assert_eq!(alice_msg.get_width() as u32, image_size); - assert_eq!(alice_msg.get_height() as u32, image_size); - let img = image::open(alice_msg.get_file(&alice).unwrap())?; - assert_eq!(img.width() as u32, image_size); - assert_eq!(img.height() as u32, image_size); + assert_correct_rotataion(&img_rotated); - bob.recv_msg(&sent).await; - let bob_msg = bob.get_last_msg().await; - assert_eq!(bob_msg.get_width() as u32, image_size); - assert_eq!(bob_msg.get_height() as u32, image_size); - let img = image::open(bob_msg.get_file(&bob).unwrap())?; - assert_eq!(img.width() as u32, image_size); - assert_eq!(img.height() as u32, image_size); - } - Ok(()) + let bytes = include_bytes!("../test-data/image/rectangle200x180-rotated.jpg"); + let img_rotated = send_image_check_mediaquality(Some("0"), bytes, 200, 180, 270, 180, 200) + .await + .unwrap(); + + assert_correct_rotataion(&img_rotated); + } + + fn assert_correct_rotataion(img: &DynamicImage) { + // The test images are black in the bottom left corner after correctly applying + // the EXIF orientation + + let [luma] = img.get_pixel(10, 10).to_luma().0; + assert_eq!(luma, 255); + let [luma] = img.get_pixel(img.width() - 10, 10).to_luma().0; + assert_eq!(luma, 255); + let [luma] = img + .get_pixel(img.width() - 10, img.height() - 10) + .to_luma() + .0; + assert_eq!(luma, 255); + let [luma] = img.get_pixel(10, img.height() - 10).to_luma().0; + assert_eq!(luma, 0); + } + + async fn send_image_check_mediaquality( + media_quality_config: Option<&str>, + bytes: &[u8], + original_width: u32, + original_height: u32, + orientation: i32, + compressed_width: u32, + compressed_height: u32, + ) -> anyhow::Result { + let alice = TestContext::new_alice().await; + let bob = TestContext::new_bob().await; + alice + .set_config(Config::MediaQuality, media_quality_config) + .await?; + let file = alice.get_blobdir().join("file.jpg"); + + File::create(&file).await?.write_all(bytes).await?; + let img = image::open(&file)?; + assert_eq!(img.width(), original_width); + assert_eq!(img.height(), original_height); + + let blob = BlobObject::new_from_path(&alice, &file).await?; + assert_eq!(blob.get_exif_orientation(&alice).unwrap_or(0), orientation); + + let mut msg = Message::new(Viewtype::Image); + msg.set_file(file.to_str().unwrap(), None); + let chat = alice.create_chat(&bob).await; + let sent = alice.send_msg(chat.id, &mut msg).await; + let alice_msg = alice.get_last_msg().await; + assert_eq!(alice_msg.get_width() as u32, compressed_width); + assert_eq!(alice_msg.get_height() as u32, compressed_height); + let img = image::open(alice_msg.get_file(&alice).unwrap())?; + assert_eq!(img.width() as u32, compressed_width); + assert_eq!(img.height() as u32, compressed_height); + + bob.recv_msg(&sent).await; + let bob_msg = bob.get_last_msg().await; + assert_eq!(bob_msg.get_width() as u32, compressed_width); + assert_eq!(bob_msg.get_height() as u32, compressed_height); + let file = bob_msg.get_file(&bob).unwrap(); + + let blob = BlobObject::new_from_path(&bob, &file).await?; + assert_eq!(blob.get_exif_orientation(&bob).unwrap_or(0), 0); + + let img = image::open(file)?; + assert_eq!(img.width() as u32, compressed_width); + assert_eq!(img.height() as u32, compressed_height); + Ok(img) } } diff --git a/test-data/image/.comments/rectangle2000x1800-rotated.jpg.xml b/test-data/image/.comments/rectangle2000x1800-rotated.jpg.xml new file mode 100644 index 000000000..815de21f6 --- /dev/null +++ b/test-data/image/.comments/rectangle2000x1800-rotated.jpg.xml @@ -0,0 +1,7 @@ + + + + Created with GIMP + + + diff --git a/test-data/image/.comments/rectangle200x180-rotated.jpg.xml b/test-data/image/.comments/rectangle200x180-rotated.jpg.xml new file mode 100644 index 000000000..815de21f6 --- /dev/null +++ b/test-data/image/.comments/rectangle200x180-rotated.jpg.xml @@ -0,0 +1,7 @@ + + + + Created with GIMP + + + diff --git a/test-data/image/rectangle2000x1800-rotated.jpg b/test-data/image/rectangle2000x1800-rotated.jpg new file mode 100644 index 0000000000000000000000000000000000000000..286ae36089130c5bb81f7cb638feb69490faa7d6 GIT binary patch literal 45773 zcmeI4eQZ-z7{=dw+pZt$pdH;9M6uIp2(m~(kwkHf$*^RTIvMg6-PV0D!^YT(pb|lX zVuA@UB!bawiU~v{A%egkCVUzaBM})V8EWL1c)9P!0|Tv2*s$Li{yn4VHn$r9<~ z;GcR?8{a0Cuc`b!uaRfrE6>nf^6D!}!xiQJCDq~i{;7e&Ah#K3(Avo}EkBUYEs8Q) z8BL_!pdrFYtwY@z$jf^vSTsF9P%wpi^Y3n65UOdgjv=b44c8Y65Hb{DdiOnA%0JO?lmb?S0CoMgyZo`!gYGQ ziDO@AerY+!pL0CAo^O!jQ@UQ(9beSrsz|JJBwziEqC9?YK92oWed4k{acF*h4flDJ z`(%~Z)bjl5tnRp6kC*9j&4R^zZ;_&ZAnuCV;^+CA#ozbPR0>cb1<6lkw3w=C0fi}> zueGc+P!YFJmW&@B86V_PWjv~yLOkMWT1Yii8W~UeXTW{9MA8^)Qniwo_n%vdQf3nkIZou7+s%#J^mf|vBhd_IRd9@G^9Mu^Rq@>OB=1{a z@V(sP_PNPV`-$?%qN@6fi2{gOZay=^pP8 zUs_t4d+^YVbYDiQFU_YoW7Lg6yI$Z?GSk#c8C4AMe&mARV-dbJ3>Pv z8K-mTEe@xh8+>|h#TKoV+!lpYkHy2wcVld0yqb%?jMpq_tI!v7Vnvyh-key^zP;Sr z`_|&eBh{1fJD9a98%xY&Q_V(mR+u)#702ouN`j?1nRnjXElI^I5+34HUQW1gwBt8B zqwy^wbw&21TXZpL9yZfNlt@9_Hc3ky*)r-toYvSTq(UqYvl>#tj7qGAREXtaR>M=l zjEX_SQ^5elq>8742^50_gJb|=QiVY>fntzgkPJXfsxU|br>X(iBW+; zG7=H%cd0>g&Jb@^ru=5VlYcdn%?2F=KmY_l00ck)1V8`;KmY_l00ck)1V8`;KmY_l z00ck)1V8`;KmY_l00ck)1V8`;KmY_l00ck)1V8`;{yzln`>yk}q9AF3^ zW@bEKEqT|wa!kJC;N2F6x1Bxw&-7hK^s{BX#-1} zSx8a&$IYTzAN#bUF8qaJN!5?h9h>`H?*dKAQEzl?FZg-G#8EAemwz{H_p#ICPV5-> zO2JFzQgSj|T076~f1~UA)q%MbOG?o7 z*)7U@CtsM5ck$BloJs3#Ij)YA{l1ea;l2n3$l%x_2 zq%4)N$;ik!WoxNFbYKT|83Bn711Wjx!9YrOBy2L0RDyw&q!J9IB$Z$wWvPTsMn=Xd zTTA_+4=ncnxI-Bh=pXDkqK?b0tt*N%8{=|EimsFak~l+E!=(~Hx))Gha~YP*!9o&FDx^1PA& literal 0 HcmV?d00001 diff --git a/test-data/image/rectangle200x180-rotated.jpg b/test-data/image/rectangle200x180-rotated.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3e5a1a00316f6f04cac4747680e37af1b8bdd90d GIT binary patch literal 2147 zcmcgsZD?C%6n@@&bCWb5?Y-$u*J^*H(oGi9QFTro!*-2p$!IjBt#od><*RL=NlTJC zVGaX+bkskkL+zZyeMrYPky*!tF?Gy|qautA?B+zPGEh()RfiDQ>v?aRrdr#wKRtPK z&Xe=~o_lVztJ?S2v+22b2jKU^4ZsWo0}O;n;38wQ_*8#<7C*`y5Op6jaZbX}D-cLJ z=(}x*vXJB%bn>QRp-e35+8NJuxte_b0NMVVL7RZQxzX217REfx187qyofoP7Ae{7h zz1su9CmMato5-7LAMB1K(uP_fk<6rmO%1O0El;^jH(-Q?J{714Mbf<+1A*pzL-XaW zucq6*Qp0o2w=b%(M`P&--N{8>^^x9GhVTx;>vm>(IUXjgM!G^#!tWCHq^Lo{SGhhs zjep^|Q^$OcP*bfzFWpTg?CP9@!*g(?E0rLhwd7MBO(ZG5&_0c$96!%-qPvfJ(}_P2 zTP)euLb95^m1u$wegxn`7=4JN8yVD)Op+#zAlVxhh`&pZ4^UK?qT+~9#AE0|0wFyf z{27oBQDL^}jtB17Rm|1^NZ)GO?<)b*Uf}kirsWQ4+U>)D_ziF_S%~jB2t52J=?4qC z>bHTCmw?k33cBzcz=!=n`L*6qDx}xpODc5GdQTn&>|21+OMqqT^xVkC?Km4a zzXbNZ39Ra*+}jqoH(&VKxh?85Ge7M*ybuL}A0h)C$t+0*gJdz8jAom~X0uwXR(r8S zwiheKR;yelE2XN_>9m!sC@)jX9ja61Ntj462B}Drid4JRuHG?e=b@N!3KvDDKv0;d zFzo`$^*4_3LFCC~E|SQi@|Wx1q^tV+gC&9F0U45-FO9L~Lfl0zou#_CwfqAo(gWfe6p7zJj~-vgdTfV8&$ z#l0U~rfpLkRkguT{tCuAA$PYsy!!RA;epub$UXbIkL?-Rx|kvtert_!VD ze?R=$t7RlQ23m(k+2vnd`Q_E$dU?oKy&Q*kX;_XzGuOFyiRF-&UXB?TK5bejet{Wc qN>z5wwB=84T~D0mr|0nl>oY%JIZ9$ze6#Vrmu1iTmVVm8YySY?7Q>MM literal 0 HcmV?d00001 From b727190da5fb29a75c1610da71adb28249c6e4d4 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Thu, 10 Jun 2021 19:17:44 +0200 Subject: [PATCH 10/25] test low media quality a little more --- src/blob.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/blob.rs b/src/blob.rs index d13a33343..9f1e41407 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -952,8 +952,7 @@ mod tests { ) .await .unwrap(); - - assert_correct_rotataion(&img_rotated); + assert_correct_rotation(&img_rotated); let mut bytes = vec![]; img_rotated @@ -970,18 +969,35 @@ mod tests { ) .await .unwrap(); + assert_correct_rotation(&img_rotated); - assert_correct_rotataion(&img_rotated); + let img_rotated = send_image_check_mediaquality( + Some("1"), + &bytes, + BALANCED_IMAGE_SIZE * 1800 / 2000, + BALANCED_IMAGE_SIZE, + 0, + WORSE_IMAGE_SIZE * 1800 / 2000, + WORSE_IMAGE_SIZE, + ) + .await + .unwrap(); + assert_correct_rotation(&img_rotated); let bytes = include_bytes!("../test-data/image/rectangle200x180-rotated.jpg"); let img_rotated = send_image_check_mediaquality(Some("0"), bytes, 200, 180, 270, 180, 200) .await .unwrap(); + assert_correct_rotation(&img_rotated); - assert_correct_rotataion(&img_rotated); + let bytes = include_bytes!("../test-data/image/rectangle200x180-rotated.jpg"); + let img_rotated = send_image_check_mediaquality(Some("1"), bytes, 200, 180, 270, 180, 200) + .await + .unwrap(); + assert_correct_rotation(&img_rotated); } - fn assert_correct_rotataion(img: &DynamicImage) { + fn assert_correct_rotation(img: &DynamicImage) { // The test images are black in the bottom left corner after correctly applying // the EXIF orientation From 751b9add09a50c17213f61de44f6f5950039f879 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Thu, 10 Jun 2021 19:59:15 +0200 Subject: [PATCH 11/25] remove unneeded files --- .../image/.comments/rectangle2000x1800-rotated.jpg.xml | 7 ------- test-data/image/.comments/rectangle200x180-rotated.jpg.xml | 7 ------- 2 files changed, 14 deletions(-) delete mode 100644 test-data/image/.comments/rectangle2000x1800-rotated.jpg.xml delete mode 100644 test-data/image/.comments/rectangle200x180-rotated.jpg.xml diff --git a/test-data/image/.comments/rectangle2000x1800-rotated.jpg.xml b/test-data/image/.comments/rectangle2000x1800-rotated.jpg.xml deleted file mode 100644 index 815de21f6..000000000 --- a/test-data/image/.comments/rectangle2000x1800-rotated.jpg.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - Created with GIMP - - - diff --git a/test-data/image/.comments/rectangle200x180-rotated.jpg.xml b/test-data/image/.comments/rectangle200x180-rotated.jpg.xml deleted file mode 100644 index 815de21f6..000000000 --- a/test-data/image/.comments/rectangle200x180-rotated.jpg.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - Created with GIMP - - - From 25fed9ab52588556a445728cb3d83d4ade7d6ae1 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Thu, 10 Jun 2021 21:23:30 +0200 Subject: [PATCH 12/25] comment --- src/blob.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/blob.rs b/src/blob.rs index 9f1e41407..819461f18 100644 --- a/src/blob.rs +++ b/src/blob.rs @@ -940,6 +940,7 @@ mod tests { .await .unwrap(); + // The "-rotated" files are rotated by 270 degrees using the Exif metadata let bytes = include_bytes!("../test-data/image/rectangle2000x1800-rotated.jpg"); let img_rotated = send_image_check_mediaquality( Some("0"), From 8f2cb1e8ab1790a933f87fe8e68b59c7ffba52d2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Jun 2021 22:19:07 +0000 Subject: [PATCH 13/25] cargo: bump libc from 0.2.95 to 0.2.97 Bumps [libc](https://github.com/rust-lang/libc) from 0.2.95 to 0.2.97. - [Release notes](https://github.com/rust-lang/libc/releases) - [Commits](https://github.com/rust-lang/libc/compare/0.2.95...0.2.97) --- updated-dependencies: - dependency-name: libc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7198aa478..7ca5a27c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2128,9 +2128,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.95" +version = "0.2.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" +checksum = "12b8adadd720df158f4d70dfe7ccc6adb0472d7c55ca83445f6a5ab3e36f8fb6" [[package]] name = "libm" diff --git a/Cargo.toml b/Cargo.toml index 0bc762f05..9afcd6ebc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,7 @@ indexmap = "1.3.0" itertools = "0.10.1" kamadak-exif = "0.5" lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" } -libc = "0.2.95" +libc = "0.2.97" log = {version = "0.4.8", optional = true } mailparse = "0.13.4" native-tls = "0.2.3" From 4b625009891c95864f2007095a19519ac26e24d8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 11 Jun 2021 22:19:21 +0000 Subject: [PATCH 14/25] cargo: bump syn from 1.0.72 to 1.0.73 Bumps [syn](https://github.com/dtolnay/syn) from 1.0.72 to 1.0.73. - [Release notes](https://github.com/dtolnay/syn/releases) - [Commits](https://github.com/dtolnay/syn/compare/1.0.72...1.0.73) --- updated-dependencies: - dependency-name: syn dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- deltachat_derive/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7198aa478..d54e392f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3636,9 +3636,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.72" +version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82" +checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7" dependencies = [ "proc-macro2", "quote", diff --git a/deltachat_derive/Cargo.toml b/deltachat_derive/Cargo.toml index 4aef5f942..43526cef9 100644 --- a/deltachat_derive/Cargo.toml +++ b/deltachat_derive/Cargo.toml @@ -9,5 +9,5 @@ license = "MPL-2.0" proc-macro = true [dependencies] -syn = "1.0.72" +syn = "1.0.73" quote = "1.0.2" From 1870684c43ce60b93f98032b75cf927a622fd1f0 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 11 Jun 2021 14:29:58 +0200 Subject: [PATCH 15/25] add a test that catches some cases where dbversion was forgotten to update --- src/sql.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/sql.rs b/src/sql.rs index 68b745e65..70dc45c17 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -802,4 +802,21 @@ mod test { Ok(()) } + + #[async_std::test] + async fn test_migration_flags() -> Result<()> { + let t = TestContext::new().await; + + // as migrations::run() was already executed on context creation, + // another call should not result in any action needed. + // this test catches some bugs where dbversion was forgotten to be persisted. + let (recalc_fingerprints, update_icons, disable_server_delete, recode_avatar) = + migrations::run(&t, &t.sql).await?; + assert!(!recalc_fingerprints); + assert!(!update_icons); + assert!(!disable_server_delete); + assert!(!recode_avatar); + + Ok(()) + } } From 5dee1efa59943d0ed55b3c2ff424fc0e3196f912 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 11 Jun 2021 14:30:35 +0200 Subject: [PATCH 16/25] add missing dbversion update --- src/sql/migrations.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index 590314cfd..1f5e168b9 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -466,6 +466,7 @@ paramsv![] if dbversion < 77 { info!(context, "[migration] v77"); recode_avatar = true; + sql.set_db_version(77).await?; } Ok(( From 991d15615e057cbbbefacb44c2217f8356e131ab Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Fri, 11 Jun 2021 14:35:13 +0200 Subject: [PATCH 17/25] fix minor dbversion inconsistencies probably they come in by the latest sqlx<->rusqlite moves, however, as they are followed by subsequent migrations, that should not have been a big bug in the past (maybe unless the app was killed at a bad moment) --- src/sql/migrations.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sql/migrations.rs b/src/sql/migrations.rs index 1f5e168b9..c14054061 100644 --- a/src/sql/migrations.rs +++ b/src/sql/migrations.rs @@ -167,7 +167,7 @@ CREATE TABLE tokens ( ALTER TABLE acpeerstates ADD COLUMN verified_key; ALTER TABLE acpeerstates ADD COLUMN verified_key_fingerprint TEXT DEFAULT ''; CREATE INDEX acpeerstates_index5 ON acpeerstates (verified_key_fingerprint);"#, - 38, + 39, ) .await?; } @@ -454,7 +454,7 @@ paramsv![] info!(context, "[migration] v75"); sql.execute_migration( "ALTER TABLE contacts ADD COLUMN status TEXT DEFAULT '';", - 74, + 75, ) .await?; } From d12d9d94d6b227d458cce9a98e08f51e37ed039d Mon Sep 17 00:00:00 2001 From: Hocuri Date: Fri, 11 Jun 2021 16:28:39 +0200 Subject: [PATCH 18/25] Improve test_migration_flags, add EvTracker to test_utils --- src/sql.rs | 18 +++++++++++++++++- src/test_utils.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/sql.rs b/src/sql.rs index 70dc45c17..9e794b729 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -198,7 +198,7 @@ impl Sql { } } - info!(context, "Opened {:?}.", dbfile); + info!(context, "Opened database {:?}.", dbfile); Ok(()) } @@ -806,6 +806,8 @@ mod test { #[async_std::test] async fn test_migration_flags() -> Result<()> { let t = TestContext::new().await; + let events = t.new_evtracker().await; + events.get_info_contains("Opened database").await; // as migrations::run() was already executed on context creation, // another call should not result in any action needed. @@ -817,6 +819,20 @@ mod test { assert!(!disable_server_delete); assert!(!recode_avatar); + info!(&t, "test_migration_flags: XXX"); + + loop { + if let EventType::Info(info) = events.recv().await.unwrap() { + assert!( + !info.contains("[migration]"), + "Migrations were run twice, you probably forgot to update the db version" + ); + if info.contains("test_migration_flags: XXX") { + break; + } + } + } + Ok(()) } } diff --git a/src/test_utils.rs b/src/test_utils.rs index 1d6c11d8d..533177c6c 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -9,6 +9,7 @@ use std::{collections::BTreeMap, panic}; use std::{fmt, thread}; use ansi_term::Color; +use async_std::channel::Receiver; use async_std::path::PathBuf; use async_std::sync::{Arc, RwLock}; use async_std::{channel, pin::Pin}; @@ -183,6 +184,21 @@ impl TestContext { sinks.push(Box::new(move |evt| Box::pin(sink(evt)))); } + pub async fn new_evtracker(&self) -> EvTracker { + let (sender, receiver) = channel::unbounded(); + let sender = Arc::new(sender); + self.add_event_sink(move |event| { + let sender = sender.clone(); + async move { + sender.send(event.typ).await.ok(); + // If sending fails, probably the EvTracker was simply dropped, + // so we call ok() to ignore the error + } + }) + .await; + EvTracker(receiver) + } + /// Configure with alice@example.com. /// /// The context will be fake-configured as the alice user, with a pre-generated secret @@ -568,6 +584,28 @@ pub fn bob_keypair() -> key::KeyPair { } } +pub struct EvTracker(Receiver); + +impl EvTracker { + pub async fn get_info_contains(&self, s: &str) -> EventType { + loop { + let event = self.0.recv().await.unwrap(); + if let EventType::Info(i) = &event { + if i.contains(s) { + return event; + } + } + } + } +} + +impl Deref for EvTracker { + type Target = Receiver; + fn deref(&self) -> &Self::Target { + &self.0 + } +} + /// Gets a specific message from a chat and asserts that the chat has a specific length. /// /// Panics if the length of the chat is not `asserted_msgs_count` or if the chat item at `index` is not a Message. From b16785bb62c057b0ce405be8ecbe8b4d46b02cf3 Mon Sep 17 00:00:00 2001 From: Hocuri Date: Sat, 12 Jun 2021 15:06:16 +0200 Subject: [PATCH 19/25] Tweak test --- src/sql.rs | 5 ++--- src/test_utils.rs | 26 ++++++++------------------ 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/src/sql.rs b/src/sql.rs index 9e794b729..c4bed5d37 100644 --- a/src/sql.rs +++ b/src/sql.rs @@ -806,8 +806,7 @@ mod test { #[async_std::test] async fn test_migration_flags() -> Result<()> { let t = TestContext::new().await; - let events = t.new_evtracker().await; - events.get_info_contains("Opened database").await; + t.evtracker.get_info_contains("Opened database").await; // as migrations::run() was already executed on context creation, // another call should not result in any action needed. @@ -822,7 +821,7 @@ mod test { info!(&t, "test_migration_flags: XXX"); loop { - if let EventType::Info(info) = events.recv().await.unwrap() { + if let EventType::Info(info) = t.evtracker.recv().await.unwrap() { assert!( !info.contains("[migration]"), "Migrations were run twice, you probably forgot to update the db version" diff --git a/src/test_utils.rs b/src/test_utils.rs index 533177c6c..7a0a9fd32 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -48,6 +48,7 @@ static CONTEXT_NAMES: Lazy>> = pub(crate) struct TestContext { pub ctx: Context, pub dir: TempDir, + pub evtracker: EvTracker, /// Counter for fake IMAP UIDs in [recv_msg], for private use in that function only. recv_idx: RwLock, /// Functions to call for events received. @@ -104,6 +105,8 @@ impl TestContext { let event_sinks: Arc>>> = Arc::new(RwLock::new(Vec::new())); let sinks = Arc::clone(&event_sinks); let (poison_sender, poison_receiver) = channel::bounded(1); + let (evtracker_sender, evtracker_receiver) = channel::unbounded(); + async_std::task::spawn(async move { // Make sure that the test fails if there is a panic on this thread here: let current_id = task::current().id(); @@ -123,13 +126,15 @@ impl TestContext { sink(event.clone()).await; } } - receive_event(event); + receive_event(&event); + evtracker_sender.send(event.typ).await.ok(); } }); Self { ctx, dir, + evtracker: EvTracker(evtracker_receiver), recv_idx: RwLock::new(0), event_sinks, poison_receiver, @@ -184,21 +189,6 @@ impl TestContext { sinks.push(Box::new(move |evt| Box::pin(sink(evt)))); } - pub async fn new_evtracker(&self) -> EvTracker { - let (sender, receiver) = channel::unbounded(); - let sender = Arc::new(sender); - self.add_event_sink(move |event| { - let sender = sender.clone(); - async move { - sender.send(event.typ).await.ok(); - // If sending fails, probably the EvTracker was simply dropped, - // so we call ok() to ignore the error - } - }) - .await; - EvTracker(receiver) - } - /// Configure with alice@example.com. /// /// The context will be fake-configured as the alice user, with a pre-generated secret @@ -629,12 +619,12 @@ pub(crate) async fn get_chat_msg( /// Pretty-print an event to stdout /// /// Done during tests this is captured by `cargo test` and associated with the test itself. -fn receive_event(event: Event) { +fn receive_event(event: &Event) { let green = Color::Green.normal(); let yellow = Color::Yellow.normal(); let red = Color::Red.normal(); - let msg = match event.typ { + let msg = match &event.typ { EventType::Info(msg) => format!("INFO: {}", msg), EventType::SmtpConnected(msg) => format!("[SMTP_CONNECTED] {}", msg), EventType::ImapConnected(msg) => format!("[IMAP_CONNECTED] {}", msg), From ad7c7e90b3748adb16f292a7ab5643a4a99cfd3a Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 13 Jun 2021 01:33:54 +0300 Subject: [PATCH 20/25] Resultify Contact::block --- deltachat-ffi/src/lib.rs | 8 +++- examples/repl/cmdline.rs | 4 +- src/contact.rs | 90 ++++++++++++++++++++-------------------- src/dc_receive_imf.rs | 4 +- src/message.rs | 6 ++- 5 files changed, 62 insertions(+), 50 deletions(-) diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index 4d91df384..3a1efbc5b 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -1737,9 +1737,13 @@ pub unsafe extern "C" fn dc_block_contact( let ctx = &*context; block_on(async move { if block == 0 { - Contact::unblock(&ctx, contact_id).await; + Contact::unblock(&ctx, contact_id) + .await + .ok_or_log_msg(&ctx, "Can't unblock contact"); } else { - Contact::block(&ctx, contact_id).await; + Contact::block(&ctx, contact_id) + .await + .ok_or_log_msg(&ctx, "Can't block contact"); } }); } diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index fdaeb88a1..30723e5e6 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -1137,12 +1137,12 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu "block" => { ensure!(!arg1.is_empty(), "Argument missing."); let contact_id = arg1.parse()?; - Contact::block(&context, contact_id).await; + Contact::block(&context, contact_id).await?; } "unblock" => { ensure!(!arg1.is_empty(), "Argument missing."); let contact_id = arg1.parse()?; - Contact::unblock(&context, contact_id).await; + Contact::unblock(&context, contact_id).await?; } "listblocked" => { let contacts = Contact::get_all_blocked(&context).await?; diff --git a/src/contact.rs b/src/contact.rs index b058f26f3..ba4791e2a 100644 --- a/src/contact.rs +++ b/src/contact.rs @@ -236,13 +236,13 @@ impl Contact { } /// Block the given contact. - pub async fn block(context: &Context, id: u32) { - set_block_contact(context, id, true).await; + pub async fn block(context: &Context, id: u32) -> Result<()> { + set_block_contact(context, id, true).await } /// Unblock the given contact. - pub async fn unblock(context: &Context, id: u32) { - set_block_contact(context, id, false).await; + pub async fn unblock(context: &Context, id: u32) -> Result<()> { + set_block_contact(context, id, false).await } /// Add a single contact as a result of an _explicit_ user action. @@ -270,7 +270,7 @@ impl Contact { } } if blocked { - Contact::unblock(context, contact_id).await; + Contact::unblock(context, contact_id).await?; } Ok(contact_id) @@ -1162,56 +1162,58 @@ fn sanitize_name_and_addr(name: &str, addr: &str) -> (String, String) { } } -async fn set_block_contact(context: &Context, contact_id: u32, new_blocking: bool) { - if contact_id <= DC_CONTACT_ID_LAST_SPECIAL { - return; - } +async fn set_block_contact(context: &Context, contact_id: u32, new_blocking: bool) -> Result<()> { + ensure!( + contact_id > DC_CONTACT_ID_LAST_SPECIAL, + "Can't block special contact {}", + contact_id + ); - if let Ok(contact) = Contact::load_from_db(context, contact_id).await { - if contact.blocked != new_blocking - && context - .sql - .execute( - "UPDATE contacts SET blocked=? WHERE id=?;", - paramsv![new_blocking as i32, contact_id as i32], - ) - .await - .is_ok() - { - // also (un)block all chats with _only_ this contact - we do not delete them to allow a - // non-destructive blocking->unblocking. - // (Maybe, beside normal chats (type=100) we should also block group chats with only this user. - // However, I'm not sure about this point; it may be confusing if the user wants to add other people; - // this would result in recreating the same group...) - if context - .sql - .execute( - r#" + let contact = Contact::load_from_db(context, contact_id).await?; + + if contact.blocked != new_blocking { + context + .sql + .execute( + "UPDATE contacts SET blocked=? WHERE id=?;", + paramsv![new_blocking as i32, contact_id as i32], + ) + .await?; + + // also (un)block all chats with _only_ this contact - we do not delete them to allow a + // non-destructive blocking->unblocking. + // (Maybe, beside normal chats (type=100) we should also block group chats with only this user. + // However, I'm not sure about this point; it may be confusing if the user wants to add other people; + // this would result in recreating the same group...) + if context + .sql + .execute( + r#" UPDATE chats SET blocked=? WHERE type=? AND id IN ( SELECT chat_id FROM chats_contacts WHERE contact_id=? ); "#, - paramsv![new_blocking, Chattype::Single, contact_id], - ) - .await - .is_ok() - { - Contact::mark_noticed(context, contact_id).await; - context.emit_event(EventType::ContactsChanged(Some(contact_id))); - } + paramsv![new_blocking, Chattype::Single, contact_id], + ) + .await + .is_ok() + { + Contact::mark_noticed(context, contact_id).await; + context.emit_event(EventType::ContactsChanged(Some(contact_id))); + } - // also unblock mailinglist - // if the contact is a mailinglist address explicitly created to allow unblocking - if !new_blocking && contact.origin == Origin::MailinglistAddress { - if let Ok((chat_id, _, _)) = chat::get_chat_id_by_grpid(context, contact.addr).await - { - chat_id.set_blocked(context, Blocked::Not).await; - } + // also unblock mailinglist + // if the contact is a mailinglist address explicitly created to allow unblocking + if !new_blocking && contact.origin == Origin::MailinglistAddress { + if let Ok((chat_id, _, _)) = chat::get_chat_id_by_grpid(context, contact.addr).await { + chat_id.set_blocked(context, Blocked::Not).await; } } } + + Ok(()) } /// Set profile image for a contact. diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 4248f3755..1a2c147f7 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -3018,7 +3018,9 @@ mod tests { assert_eq!(msgs.len(), 0); // Unblock contact and check if the next message arrives in real chat - Contact::unblock(&t, *blocked.first().unwrap()).await; + Contact::unblock(&t, *blocked.first().unwrap()) + .await + .unwrap(); let blocked = Contact::get_all_blocked(&t).await.unwrap(); assert_eq!(blocked.len(), 0); diff --git a/src/message.rs b/src/message.rs index dace3be95..47c1172b9 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1196,7 +1196,11 @@ pub async fn decide_on_contact_request( Err(e) => warn!(context, "decide_on_contact_request error: {}", e), }, - (Block, false) => Contact::block(context, msg.from_id).await, + (Block, false) => { + if let Err(e) = Contact::block(context, msg.from_id).await { + warn!(context, "Can't block contact: {}", e); + } + } (Block, true) => { if !msg.chat_id.set_blocked(context, Blocked::Manually).await { warn!(context, "Block mailing list failed.") From 62388514dd5c02eacf9b7709a3de4321cf6c3329 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 13 Jun 2021 20:54:30 +0300 Subject: [PATCH 21/25] chat: make get_msg_cnt() and get_fresh_msg_cnt() work for deaddrop Also do not count hidden messages in get_msg_cnt(). --- python/tests/test_account.py | 2 +- src/chat.rs | 56 ++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/python/tests/test_account.py b/python/tests/test_account.py index 3ef0945d3..efae43263 100644 --- a/python/tests/test_account.py +++ b/python/tests/test_account.py @@ -983,7 +983,7 @@ class TestOnlineAccount: chat2 = msg2.chat assert msg2 in chat2.get_messages() assert chat2.is_deaddrop() - assert chat2.count_fresh_messages() == 0 + assert chat2.count_fresh_messages() == 1 assert msg2.time_received >= msg1.time_sent lp.sec("create new chat with contact and verify it's proper") diff --git a/src/chat.rs b/src/chat.rs index a52213094..1a93ef623 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -574,10 +574,26 @@ impl ChatId { /// Returns number of messages in a chat. pub async fn get_msg_cnt(self, context: &Context) -> Result { - let count = context - .sql - .count("SELECT COUNT(*) FROM msgs WHERE chat_id=?", paramsv![self]) - .await?; + let count = if self.is_deaddrop() { + context + .sql + .count( + "SELECT COUNT(*) + FROM msgs + WHERE hidden=0 + AND chat_id IN (SELECT id FROM chats WHERE blocked=?)", + paramsv![Blocked::Deaddrop], + ) + .await? + } else { + context + .sql + .count( + "SELECT COUNT(*) FROM msgs WHERE hidden=0 AND chat_id=?", + paramsv![self], + ) + .await? + }; Ok(count as usize) } @@ -592,17 +608,31 @@ impl ChatId { // the times are average, no matter if there are fresh messages or not - // and have to be multiplied by the number of items shown at once on the chatlist, // so savings up to 2 seconds are possible on older devices - newer ones will feel "snappier" :) - let count = context - .sql - .count( - "SELECT COUNT(*) + let count = if self.is_deaddrop() { + context + .sql + .count( + "SELECT COUNT(*) + FROM msgs + WHERE state=? + AND hidden=0 + AND chat_id IN (SELECT id FROM chats WHERE blocked=?)", + paramsv![MessageState::InFresh, Blocked::Deaddrop], + ) + .await? + } else { + context + .sql + .count( + "SELECT COUNT(*) FROM msgs - WHERE state=10 + WHERE state=? AND hidden=0 AND chat_id=?;", - paramsv![self], - ) - .await?; + paramsv![MessageState::InFresh, self], + ) + .await? + }; Ok(count as usize) } @@ -4005,6 +4035,8 @@ mod tests { let chats = Chatlist::try_load(&t, 0, None, None).await?; assert_eq!(chats.len(), 1); assert_eq!(chats.get_chat_id(0), DC_CHAT_ID_DEADDROP); + assert_eq!(DC_CHAT_ID_DEADDROP.get_msg_cnt(&t).await?, 1); + assert_eq!(DC_CHAT_ID_DEADDROP.get_fresh_msg_cnt(&t).await?, 1); let msgs = get_chat_msgs(&t, DC_CHAT_ID_DEADDROP, 0, None).await?; assert_eq!(msgs.len(), 1); let msg_id = match msgs.first().unwrap() { From 15664be4f6527bbe7be89530255d53edae95597d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Jun 2021 08:07:26 +0000 Subject: [PATCH 22/25] cargo: bump once_cell from 1.7.2 to 1.8.0 Bumps [once_cell](https://github.com/matklad/once_cell) from 1.7.2 to 1.8.0. - [Release notes](https://github.com/matklad/once_cell/releases) - [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md) - [Commits](https://github.com/matklad/once_cell/compare/v1.7.2...v1.8.0) --- updated-dependencies: - dependency-name: once_cell dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46be9ef8a..bf292c54c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2449,9 +2449,9 @@ checksum = "1a5b3dd1c072ee7963717671d1ca129f1048fda25edea6b752bfc71ac8854170" [[package]] name = "once_cell" -version = "1.7.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" +checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "oorandom" diff --git a/Cargo.toml b/Cargo.toml index 9afcd6ebc..070ca3ffc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ native-tls = "0.2.3" num_cpus = "1.13.0" num-derive = "0.3.0" num-traits = "0.2.6" -once_cell = "1.4.1" +once_cell = "1.8.0" percent-encoding = "2.0" pgp = { version = "0.7.0", default-features = false } pretty_env_logger = { version = "0.4.0", optional = true } From d821cdf1c8214bfe4f8da75a995e52a9a7264be1 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 12 Jun 2021 03:11:53 +0300 Subject: [PATCH 23/25] Improve drafts detection systemli.org seems not to include Received: header in messages sent to self, including BCC-self and messages sent to Saved message chat. This results in all these messages not being displayed on other devices in multi-device setting. To work around this problem we restrict draft detection based on Received: header to classical mails. Delta Chat already implements proper draft detection based on the \Draft message flag and \Drafts folder flag. However, Thunderbird does not set \Draft flag when message is stored as "Template". To make draft detection for Thunderbird more robust, in case Received: header check is removed altogether later, we check for X-Mozilla-Draft-Info header which Thunderbird sets both for "Drafts" and "Templates". --- src/dc_receive_imf.rs | 21 ++++++++++++++++++--- src/headerdef.rs | 6 ++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 1a2c147f7..cc60cb460 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -685,11 +685,26 @@ async fn add_parts( } } - if !context.is_sentbox(server_folder).await? + // If the message is outgoing AND there is no Received header AND it's not in the sentbox, + // then ignore the email. + // + // We only apply this heuristic to classical emails, as it is not reliable (some servers + // such as systemli.org in June 2021 remove their own Received headers on incoming mails) + // and we know Delta Chat never stores drafts on IMAP servers. + let is_draft = !context.is_sentbox(server_folder).await? && mime_parser.get(HeaderDef::Received).is_none() - { + && mime_parser.get(HeaderDef::ChatVersion).is_none(); + + // Mozilla Thunderbird does not set \Draft flag on "Templates", but sets + // X-Mozilla-Draft-Info header, which can be used to detect both drafts and templates + // created by Thunderbird. + // + // This check is not necessary now, but may become useful if the `Received:` header check + // is removed completely later. + let is_draft = is_draft || mime_parser.get(HeaderDef::XMozillaDraftInfo).is_some(); + + if is_draft { // Most mailboxes have a "Drafts" folder where constantly new emails appear but we don't actually want to show them - // So: If it's outgoing AND there is no Received header AND it's not in the sentbox, then ignore the email. info!(context, "Email is probably just a draft (TRASH)"); *chat_id = DC_CHAT_ID_TRASH; allow_creation = false; diff --git a/src/headerdef.rs b/src/headerdef.rs index 28fb4877d..87dba1a4c 100644 --- a/src/headerdef.rs +++ b/src/headerdef.rs @@ -25,6 +25,12 @@ pub enum HeaderDef { /// we need to check that header as well. XMicrosoftOriginalMessageId, + /// Thunderbird header used to store Draft information. + /// + /// Thunderbird 78.11.0 does not set \Draft flag on messages saved as "Template", but sets this + /// header, so it can be used to ignore such messages. + XMozillaDraftInfo, + ListId, References, InReplyTo, From a638259c36cb7d185eba68d3ca7487a3baf42a1d Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 14 Jun 2021 14:54:44 +0200 Subject: [PATCH 24/25] add a test to make sure, the selected account is persisted on reopening --- src/accounts.rs | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/accounts.rs b/src/accounts.rs index 4882e7648..53313cb07 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -537,4 +537,85 @@ mod tests { assert_eq!(ids.get(i), Some(&expected_id)); } } + + #[async_std::test] + async fn test_accounts_ids_unique_increasing_and_persisted() -> Result<()> { + let dir = tempfile::tempdir()?; + let p: PathBuf = dir.path().join("accounts").into(); + let dummy_accounts = 10; + + let (id0, id1, id2) = { + let accounts = Accounts::new("my_os".into(), p.clone()).await?; + let ids = accounts.get_all().await; + assert_eq!(ids.len(), 1); // Accounts::new() creates a default account + + let id0 = *ids.get(0).unwrap(); + let ctx = accounts.get_account(id0).await.unwrap(); + ctx.set_config(crate::config::Config::Addr, Some("one@example.org")) + .await?; + + let id1 = accounts.add_account().await?; + let ctx = accounts.get_account(id1).await.unwrap(); + ctx.set_config(crate::config::Config::Addr, Some("two@example.org")) + .await?; + + // add and remove some accounts and force a gap (ids must not be reused) + for _ in 0..dummy_accounts { + let to_delete = accounts.add_account().await?; + accounts.remove_account(to_delete).await?; + } + + let id2 = accounts.add_account().await?; + let ctx = accounts.get_account(id2).await.unwrap(); + ctx.set_config(crate::config::Config::Addr, Some("three@example.org")) + .await?; + + accounts.select_account(id1).await?; + + (id0, id1, id2) + }; + assert!(id0 > 0); + assert!(id1 > id0); + assert!(id2 > id1 + dummy_accounts); + + let (id0_reopened, id1_reopened, id2_reopened) = { + let accounts = Accounts::new("my_os".into(), p.clone()).await?; + let ctx = accounts.get_selected_account().await; + assert_eq!( + ctx.get_config(crate::config::Config::Addr).await?, + Some("two@example.org".to_string()) + ); + + let ids = accounts.get_all().await; + assert_eq!(ids.len(), 3); + + let id0 = *ids.get(0).unwrap(); + let ctx = accounts.get_account(id0).await.unwrap(); + assert_eq!( + ctx.get_config(crate::config::Config::Addr).await?, + Some("one@example.org".to_string()) + ); + + let id1 = *ids.get(1).unwrap(); + let t = accounts.get_account(id1).await.unwrap(); + assert_eq!( + t.get_config(crate::config::Config::Addr).await?, + Some("two@example.org".to_string()) + ); + + let id2 = *ids.get(2).unwrap(); + let ctx = accounts.get_account(id2).await.unwrap(); + assert_eq!( + ctx.get_config(crate::config::Config::Addr).await?, + Some("three@example.org".to_string()) + ); + + (id0, id1, id2) + }; + assert_eq!(id0, id0_reopened); + assert_eq!(id1, id1_reopened); + assert_eq!(id2, id2_reopened); + + Ok(()) + } } From cf8736da48d29c7b4572f2d9ba167dd8cf99d760 Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 30 May 2021 05:59:55 +0300 Subject: [PATCH 25/25] Concourse CI pipeline to replace Circle CI --- .circleci/config.yml | 77 ---------- scripts/ci_upload.sh | 75 ---------- scripts/concourse/README.md | 21 +++ scripts/concourse/docs_wheels.yml | 217 +++++++++++++++++++++++++++++ scripts/remote_python_packaging.sh | 67 --------- 5 files changed, 238 insertions(+), 219 deletions(-) delete mode 100644 .circleci/config.yml delete mode 100755 scripts/ci_upload.sh create mode 100644 scripts/concourse/README.md create mode 100644 scripts/concourse/docs_wheels.yml delete mode 100755 scripts/remote_python_packaging.sh diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 47b55539c..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,77 +0,0 @@ -version: 2.1 -executors: - default: - docker: - - image: filecoin/rust:latest - working_directory: /mnt/crate - doxygen: - docker: - - image: hrektts/doxygen - -jobs: - build_doxygen: - executor: doxygen - steps: - - checkout - - run: bash scripts/run-doxygen.sh - - run: mkdir -p workspace/c-docs - - run: cp -av deltachat-ffi/{html,xml} workspace/c-docs/ - - persist_to_workspace: - root: workspace - paths: - - c-docs - - remote_python_packaging: - machine: true - steps: - - checkout - # the following commands on success produces - # workspace/{wheelhouse,py-docs} as artefact directories - - run: - # building aarch64 packages under qemu is very slow - no_output_timeout: 60m - command: bash scripts/remote_python_packaging.sh - - persist_to_workspace: - root: workspace - paths: - # - c-docs - - py-docs - - wheelhouse - - upload_docs_wheels: - machine: true - steps: - - checkout - - attach_workspace: - at: workspace - - run: ls -laR workspace - - run: scripts/ci_upload.sh workspace/py-docs workspace/wheelhouse workspace/c-docs - -workflows: - version: 2.1 - - test: - jobs: - - remote_python_packaging: - filters: - tags: - only: /.+/ - branches: - ignore: /.*/ - - - build_doxygen: - filters: - tags: - only: /.+/ - branches: - ignore: /.*/ - - - upload_docs_wheels: - requires: - - remote_python_packaging - - build_doxygen - filters: - tags: - only: /.+/ - branches: - ignore: /.*/ diff --git a/scripts/ci_upload.sh b/scripts/ci_upload.sh deleted file mode 100755 index f478bdeef..000000000 --- a/scripts/ci_upload.sh +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/bash - -if [ -z "$DEVPI_LOGIN" ] ; then - echo "required: password for 'dc' user on https://m.devpi/net/dc index" - exit 0 -fi - -set -xe - -PYDOCDIR=${1:?directory with python docs} -WHEELHOUSEDIR=${2:?directory with pre-built wheels} -DOXYDOCDIR=${3:?directory where doxygen docs to be found} -SSHTARGET=ci@b1.delta.chat - - -# if CIRCLE_BRANCH is not set we are called for a tag with empty CIRCLE_BRANCH variable. -export BRANCH=${CIRCLE_BRANCH:master} - -export BUILDDIR=ci_builds/$REPONAME/$BRANCH/${CIRCLE_JOB:?jobname}/${CIRCLE_BUILD_NUM:?circle-build-number}/wheelhouse - - -# python docs to py.delta.chat -ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null delta@py.delta.chat mkdir -p build/${BRANCH} -rsync -avz \ - --delete \ - -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \ - "$PYDOCDIR/html/" \ - delta@py.delta.chat:build/${BRANCH} - -# C docs to c.delta.chat -ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null delta@c.delta.chat mkdir -p build-c/${BRANCH} -rsync -avz \ - --delete \ - -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \ - "$DOXYDOCDIR/html/" \ - delta@c.delta.chat:build-c/${BRANCH} - -echo ----------------------- -echo upload wheels -echo ----------------------- - -# Bundle external shared libraries into the wheels - -ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $SSHTARGET mkdir -p $BUILDDIR -scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null scripts/cleanup_devpi_indices.py $SSHTARGET:$BUILDDIR -rsync -avz \ - -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \ - $WHEELHOUSEDIR \ - $SSHTARGET:$BUILDDIR - -ssh $SSHTARGET <<_HERE - set +x -e - # make sure all processes exit when ssh dies - shopt -s huponexit - - # we rely on the "venv" virtualenv on the remote account to exist - source venv/bin/activate - cd $BUILDDIR - - devpi use https://m.devpi.net - devpi login dc --password $DEVPI_LOGIN - - N_BRANCH=${BRANCH//[\/]} - - devpi use dc/\$N_BRANCH || { - devpi index -c \$N_BRANCH - devpi use dc/\$N_BRANCH - } - devpi index \$N_BRANCH bases=/root/pypi - devpi upload wheelhouse/deltachat* - - # remove devpi non-master dc indices if thy are too old - # this script was copied above - python cleanup_devpi_indices.py -_HERE diff --git a/scripts/concourse/README.md b/scripts/concourse/README.md new file mode 100644 index 000000000..b022d9bc4 --- /dev/null +++ b/scripts/concourse/README.md @@ -0,0 +1,21 @@ +# Concourse CI pipeline + +`docs_wheels.yml` is a pipeline for [Concourse CI](https://concourse-ci.org/) +that builds C documentation, Python documentation, Python wheels for `x86_64` +and `aarch64` and Python source packages, and uploads them. + +To setup the pipeline run +``` +fly -t set-pipeline -c docs_wheels.yml -p docs_wheels -l secret.yml +``` +where `secret.yml` contains the following secrets: +``` +c.delta.chat: + private_key: | + -----BEGIN RSA PRIVATE KEY----- + ... + -----END RSA PRIVATE KEY----- +devpi: + login: dc + password: ... +``` diff --git a/scripts/concourse/docs_wheels.yml b/scripts/concourse/docs_wheels.yml new file mode 100644 index 000000000..0a1d53730 --- /dev/null +++ b/scripts/concourse/docs_wheels.yml @@ -0,0 +1,217 @@ +resources: +- name: deltachat-core-rust + type: git + icon: github + source: + branch: master + uri: https://github.com/deltachat/deltachat-core-rust.git + +jobs: +- name: doxygen + plan: + - get: deltachat-core-rust + + # Build Doxygen documentation + - task: build-doxygen + config: + inputs: + - name: deltachat-core-rust + outputs: + - name: c-docs + image_resource: + source: + repository: hrektts/doxygen + type: registry-image + platform: linux + run: + path: bash + args: + - -exc + - | + cd deltachat-core-rust + bash scripts/run-doxygen.sh + cd .. + cp -av deltachat-core-rust/deltachat-ffi/{html,xml} c-docs/ + + - task: upload-c-docs + config: + inputs: + - name: c-docs + image_resource: + type: registry-image + source: + repository: alpine + platform: linux + run: + path: sh + args: + - -ec + - | + apk add --no-cache rsync openssh-client + mkdir -p ~/.ssh + chmod 700 ~/.ssh + echo "(("c.delta.chat".private_key))" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + rsync -e "ssh -o StrictHostKeyChecking=no" -avz --delete c-docs/html/ delta@c.delta.chat:build-c/master + +- name: python-x86_64 + plan: + - get: deltachat-core-rust + + # Build manylinux image with additional dependencies + - task: build-coredeps + privileged: true + config: + inputs: + - name: deltachat-core-rust + image_resource: + source: + repository: vito/oci-build-task + type: registry-image + outputs: + - name: coredeps-image + path: image + params: + CONTEXT: deltachat-core-rust/scripts/docker-coredeps + UNPACK_ROOTFS: "true" + platform: linux + caches: + - path: cache + run: + path: build + + # Use built image to build python wheels + - task: build-wheels + image: coredeps-image + config: + inputs: + - name: deltachat-core-rust + path: . + outputs: + - name: py-docs + path: ./python/doc/_build/ + # Source packages + - name: py-dist + path: ./python/.docker-tox/dist/ + # Binary wheels + - name: py-wheels + path: ./python/.docker-tox/wheelhouse/ + platform: linux + run: + path: bash + args: + - -exc + - | + scripts/run_all.sh + + # Upload python docs to py.delta.chat + - task: upload-py-docs + config: + inputs: + - name: py-docs + image_resource: + type: registry-image + source: + repository: alpine + platform: linux + run: + path: sh + args: + - -ec + - | + apk add --no-cache rsync openssh-client + mkdir -p ~/.ssh + chmod 700 ~/.ssh + echo "(("c.delta.chat".private_key))" > ~/.ssh/id_ed25519 + chmod 600 ~/.ssh/id_ed25519 + rsync -e "ssh -o StrictHostKeyChecking=no" -avz --delete py-docs/html/ delta@py.delta.chat:build/master + + # Upload x86_64 wheels and source packages + - task: upload-wheels + config: + inputs: + - name: py-wheels + - name: py-dist + image_resource: + type: registry-image + source: + repository: debian + platform: linux + run: + path: sh + args: + - -ec + - | + apt-get update -y + apt-get install -y --no-install-recommends python3-pip python3-setuptools + pip3 install devpi + devpi use https://m.devpi.net/dc/master + devpi login ((devpi.login)) --password ((devpi.password)) + devpi upload py-wheels/*manylinux201* + devpi upload py-dist/* + +- name: python-aarch64 + plan: + - get: deltachat-core-rust + + # Build manylinux image with additional dependencies + - task: build-coredeps + privileged: true + config: + inputs: + - name: deltachat-core-rust + image_resource: + source: + repository: vito/oci-build-task + type: registry-image + outputs: + - name: coredeps-image + path: image + params: + CONTEXT: deltachat-core-rust/scripts/docker-coredeps-arm64 + UNPACK_ROOTFS: "true" + platform: linux + caches: + - path: cache + run: + path: build + + # Use built image to build python wheels + - task: build-wheels + image: coredeps-image + config: + inputs: + - name: deltachat-core-rust + path: . + outputs: + - name: py-wheels + path: ./python/.docker-tox/wheelhouse/ + platform: linux + run: + path: bash + args: + - -exc + - | + scripts/run_all.sh + + # Upload aarch64 wheels + - task: upload-wheels + config: + inputs: + - name: py-wheels + image_resource: + type: registry-image + source: + repository: debian + platform: linux + run: + path: sh + args: + - -ec + - | + apt-get update -y + apt-get install -y --no-install-recommends python3-pip python3-setuptools + pip3 install devpi + devpi use https://m.devpi.net/dc/master + devpi login ((devpi.login)) --password ((devpi.password)) + devpi upload py-wheels/*manylinux201* diff --git a/scripts/remote_python_packaging.sh b/scripts/remote_python_packaging.sh deleted file mode 100755 index bbd86941f..000000000 --- a/scripts/remote_python_packaging.sh +++ /dev/null @@ -1,67 +0,0 @@ -#!/bin/bash - -export BRANCH=${CIRCLE_BRANCH:-master} -export REPONAME=${CIRCLE_PROJECT_REPONAME:-deltachat-core-rust} -export SSHTARGET=${SSHTARGET-ci@b1.delta.chat} - -export BUILDDIR=ci_builds/$REPONAME/$BRANCH/${CIRCLE_JOB:?jobname}/${CIRCLE_BUILD_NUM:?circle-build-number} - -echo "--- Copying files to $SSHTARGET:$BUILDDIR" - -set -xe - -ssh -oBatchMode=yes -oStrictHostKeyChecking=no $SSHTARGET mkdir -p "$BUILDDIR" -git ls-files >.rsynclist -# we seem to need .git for setuptools_scm versioning -find .git >>.rsynclist -rsync --delete --files-from=.rsynclist -az ./ "$SSHTARGET:$BUILDDIR" -rsync --delete --files-from=.rsynclist -az ./ "$SSHTARGET:$BUILDDIR-arm64" - -set +x - -# we have to create a remote file for the remote-docker run -# so we can do a simple ssh command with a TTY -# so that when our job dies, all container-runs are aborted. -# sidenote: the circle-ci machinery will kill ongoing jobs -# if there are new commits and we want to ensure that -# everything is terminated/cleaned up and we have no orphaned -# useless still-running docker-containers consuming resources. - -for arch in "" "-arm64"; do - -ssh $SSHTARGET bash -c "cat >${BUILDDIR}${arch}/exec_docker_run" <<_HERE - set +x -e - shopt -s huponexit - cd ${BUILDDIR}${arch} - export DCC_NEW_TMP_EMAIL=$DCC_NEW_TMP_EMAIL - set -x - - # run everything else inside docker - docker run -e DCC_NEW_TMP_EMAIL \ - --rm -it -v \$(pwd):/mnt -w /mnt \ - deltachat/coredeps${arch} scripts/run_all.sh - -_HERE - -done - -echo "--- Running $CIRCLE_JOB remotely" - -echo "--- Building aarch64 wheels" -ssh -o ServerAliveInterval=30 -t $SSHTARGET bash "$BUILDDIR-arm64/exec_docker_run" - -echo "--- Building x86_64 wheels" -ssh -o ServerAliveInterval=30 -t $SSHTARGET bash "$BUILDDIR/exec_docker_run" - -mkdir -p workspace - -# Wheels -for arch in "" "-arm64"; do -rsync -avz "$SSHTARGET:$BUILDDIR${arch}/python/.docker-tox/wheelhouse/*manylinux201*" workspace/wheelhouse/ -done - -# Source packages -rsync -avz "$SSHTARGET:$BUILDDIR${arch}/python/.docker-tox/dist/*" workspace/wheelhouse/ - -# Documentation -rsync -avz "$SSHTARGET:$BUILDDIR/python/doc/_build/" workspace/py-docs