Skip to content

Commit fc215ce

Browse files
committed
Merge v1.112.8
2 parents 3a8df3e + 2701c13 commit fc215ce

File tree

19 files changed

+310
-81
lines changed

19 files changed

+310
-81
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
- Fix python bindings README documentation on installing the bindings from source.
3939
- Remove confusing log line "ignoring unsolicited response Recent(…)". #3934
4040

41+
## [1.112.8] - 2023-04-20
42+
43+
### Changes
44+
- Add `get_http_response` JSON-RPC API.
45+
- Add C API to get HTTP responses.
46+
4147
## [1.112.7] - 2023-04-17
4248

4349
### Fixes

Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ kamadak-exif = "0.5"
5757
lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" }
5858
libc = "0.2"
5959
mailparse = "0.14"
60+
mime = "0.3.17"
6061
num_cpus = "1.15"
6162
num-derive = "0.3"
6263
num-traits = "0.2"

deltachat-ffi/deltachat.h

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ typedef struct _dc_event dc_event_t;
2525
typedef struct _dc_event_emitter dc_event_emitter_t;
2626
typedef struct _dc_jsonrpc_instance dc_jsonrpc_instance_t;
2727
typedef struct _dc_backup_provider dc_backup_provider_t;
28+
typedef struct _dc_http_response dc_http_response_t;
2829

2930
// Alias for backwards compatibility, use dc_event_emitter_t instead.
3031
typedef struct _dc_event_emitter dc_accounts_event_emitter_t;
@@ -5127,6 +5128,72 @@ int dc_provider_get_status (const dc_provider_t* prov
51275128
void dc_provider_unref (dc_provider_t* provider);
51285129

51295130

5131+
/**
5132+
* Return an HTTP(S) GET response.
5133+
* This function can be used to download remote content for HTML emails.
5134+
*
5135+
* @memberof dc_context_t
5136+
* @param context The context object to take proxy settings from.
5137+
* @param url HTTP or HTTPS URL.
5138+
* @return The response must be released using dc_http_response_unref() after usage.
5139+
* NULL is returned on errors.
5140+
*/
5141+
dc_http_response_t* dc_get_http_response (const dc_context_t* context, const char* url);
5142+
5143+
5144+
/**
5145+
* @class dc_http_response_t
5146+
*
5147+
* An object containing an HTTP(S) GET response.
5148+
* Created by dc_get_http_response().
5149+
*/
5150+
5151+
5152+
/**
5153+
* Returns HTTP response MIME type as a string, e.g. "text/plain" or "text/html".
5154+
*
5155+
* @memberof dc_http_response_t
5156+
* @param response HTTP response as returned by dc_get_http_response().
5157+
* @return The string which must be released using dc_str_unref() after usage. May be NULL.
5158+
*/
5159+
char* dc_http_response_get_mimetype (const dc_http_response_t* response);
5160+
5161+
/**
5162+
* Returns HTTP response encoding, e.g. "utf-8".
5163+
*
5164+
* @memberof dc_http_response_t
5165+
* @param response HTTP response as returned by dc_get_http_response().
5166+
* @return The string which must be released using dc_str_unref() after usage. May be NULL.
5167+
*/
5168+
char* dc_http_response_get_encoding (const dc_http_response_t* response);
5169+
5170+
/**
5171+
* Returns HTTP response contents.
5172+
*
5173+
* @memberof dc_http_response_t
5174+
* @param response HTTP response as returned by dc_get_http_response().
5175+
* @return The blob which must be released using dc_str_unref() after usage. NULL is never returned.
5176+
*/
5177+
uint8_t* dc_http_response_get_blob (const dc_http_response_t* response);
5178+
5179+
/**
5180+
* Returns HTTP response content size.
5181+
*
5182+
* @memberof dc_http_response_t
5183+
* @param response HTTP response as returned by dc_get_http_response().
5184+
* @return The blob size.
5185+
*/
5186+
size_t dc_http_response_get_size (const dc_http_response_t* response);
5187+
5188+
/**
5189+
* Free an HTTP response object.
5190+
*
5191+
* @memberof dc_http_response_t
5192+
* @param response HTTP response as returned by dc_get_http_response().
5193+
*/
5194+
void dc_http_response_unref (const dc_http_response_t* response);
5195+
5196+
51305197
/**
51315198
* @class dc_lot_t
51325199
*
@@ -5604,7 +5671,6 @@ void dc_reactions_unref (dc_reactions_t* reactions);
56045671
*/
56055672

56065673

5607-
56085674
/**
56095675
* @class dc_jsonrpc_instance_t
56105676
*

deltachat-ffi/src/lib.rs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use deltachat::ephemeral::Timer as EphemeralTimer;
3131
use deltachat::imex::BackupProvider;
3232
use deltachat::key::DcKey;
3333
use deltachat::message::MsgId;
34+
use deltachat::net::read_url_blob;
3435
use deltachat::qr_code_generator::{generate_backup_qr, get_securejoin_qr_svg};
3536
use deltachat::reaction::{get_msg_reactions, send_reaction, Reactions};
3637
use deltachat::stock_str::StockMessage;
@@ -4572,6 +4573,93 @@ pub unsafe extern "C" fn dc_provider_unref(provider: *mut dc_provider_t) {
45724573
// this may change once we start localizing string.
45734574
}
45744575

4576+
// dc_http_response_t
4577+
4578+
pub type dc_http_response_t = net::HttpResponse;
4579+
4580+
#[no_mangle]
4581+
pub unsafe extern "C" fn dc_get_http_response(
4582+
context: *const dc_context_t,
4583+
url: *const libc::c_char,
4584+
) -> *mut dc_http_response_t {
4585+
if context.is_null() || url.is_null() {
4586+
eprintln!("ignoring careless call to dc_get_http_response()");
4587+
return ptr::null_mut();
4588+
}
4589+
4590+
let context = &*context;
4591+
let url = to_string_lossy(url);
4592+
if let Ok(response) = block_on(read_url_blob(context, &url)).log_err(context, "read_url_blob") {
4593+
Box::into_raw(Box::new(response))
4594+
} else {
4595+
ptr::null_mut()
4596+
}
4597+
}
4598+
4599+
#[no_mangle]
4600+
pub unsafe extern "C" fn dc_http_response_get_mimetype(
4601+
response: *const dc_http_response_t,
4602+
) -> *mut libc::c_char {
4603+
if response.is_null() {
4604+
eprintln!("ignoring careless call to dc_http_response_get_mimetype()");
4605+
return ptr::null_mut();
4606+
}
4607+
4608+
let response = &*response;
4609+
response.mimetype.strdup()
4610+
}
4611+
4612+
#[no_mangle]
4613+
pub unsafe extern "C" fn dc_http_response_get_encoding(
4614+
response: *const dc_http_response_t,
4615+
) -> *mut libc::c_char {
4616+
if response.is_null() {
4617+
eprintln!("ignoring careless call to dc_http_response_get_encoding()");
4618+
return ptr::null_mut();
4619+
}
4620+
4621+
let response = &*response;
4622+
response.encoding.strdup()
4623+
}
4624+
4625+
#[no_mangle]
4626+
pub unsafe extern "C" fn dc_http_response_get_blob(
4627+
response: *const dc_http_response_t,
4628+
) -> *mut libc::c_char {
4629+
if response.is_null() {
4630+
eprintln!("ignoring careless call to dc_http_response_get_blob()");
4631+
return ptr::null_mut();
4632+
}
4633+
4634+
let response = &*response;
4635+
let blob_len = response.blob.len();
4636+
let ptr = libc::malloc(blob_len);
4637+
libc::memcpy(ptr, response.blob.as_ptr() as *mut libc::c_void, blob_len);
4638+
ptr as *mut libc::c_char
4639+
}
4640+
4641+
#[no_mangle]
4642+
pub unsafe extern "C" fn dc_http_response_get_size(
4643+
response: *const dc_http_response_t,
4644+
) -> libc::size_t {
4645+
if response.is_null() {
4646+
eprintln!("ignoring careless call to dc_http_response_get_size()");
4647+
return 0;
4648+
}
4649+
4650+
let response = &*response;
4651+
response.blob.len()
4652+
}
4653+
4654+
#[no_mangle]
4655+
pub unsafe extern "C" fn dc_http_response_unref(response: *mut dc_http_response_t) {
4656+
if response.is_null() {
4657+
eprintln!("ignoring careless call to dc_http_response_unref()");
4658+
return;
4659+
}
4660+
drop(Box::from_raw(response));
4661+
}
4662+
45754663
// -- Accounts
45764664

45774665
/// Reader-writer lock wrapper for accounts manager to guarantee thread safety when using

deltachat-jsonrpc/src/api/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use types::account::Account;
4343
use types::chat::FullChat;
4444
use types::chat_list::ChatListEntry;
4545
use types::contact::ContactObject;
46+
use types::http::HttpResponse;
4647
use types::message::MessageData;
4748
use types::message::MessageObject;
4849
use types::provider_info::ProviderInfo;
@@ -1656,6 +1657,15 @@ impl CommandApi {
16561657
Ok(general_purpose::STANDARD_NO_PAD.encode(blob))
16571658
}
16581659

1660+
/// Makes an HTTP GET request and returns a response.
1661+
///
1662+
/// `url` is the HTTP or HTTPS URL.
1663+
async fn get_http_response(&self, account_id: u32, url: String) -> Result<HttpResponse> {
1664+
let ctx = self.get_context(account_id).await?;
1665+
let response = deltachat::net::read_url_blob(&ctx, &url).await?.into();
1666+
Ok(response)
1667+
}
1668+
16591669
/// Forward messages to another chat.
16601670
///
16611671
/// All types of messages can be forwarded,
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use deltachat::net::HttpResponse as CoreHttpResponse;
2+
use serde::Serialize;
3+
use typescript_type_def::TypeDef;
4+
5+
#[derive(Serialize, TypeDef)]
6+
pub struct HttpResponse {
7+
/// base64-encoded response body.
8+
blob: String,
9+
10+
/// MIME type, e.g. "text/plain" or "text/html".
11+
mimetype: Option<String>,
12+
13+
/// Encoding, e.g. "utf-8".
14+
encoding: Option<String>,
15+
}
16+
17+
impl From<CoreHttpResponse> for HttpResponse {
18+
fn from(response: CoreHttpResponse) -> Self {
19+
use base64::{engine::general_purpose, Engine as _};
20+
let blob = general_purpose::STANDARD_NO_PAD.encode(response.blob);
21+
let mimetype = response.mimetype;
22+
let encoding = response.encoding;
23+
HttpResponse {
24+
blob,
25+
mimetype,
26+
encoding,
27+
}
28+
}
29+
}

deltachat-jsonrpc/src/api/types/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod account;
22
pub mod chat;
33
pub mod chat_list;
44
pub mod contact;
5+
pub mod http;
56
pub mod location;
67
pub mod message;
78
pub mod provider_info;

release-date.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2023-04-18
1+
2023-04-20

src/configure.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
1212
mod auto_mozilla;
1313
mod auto_outlook;
14-
mod read_url;
1514
mod server_params;
1615

1716
use anyhow::{bail, ensure, Context as _, Result};

0 commit comments

Comments
 (0)