MCPcopy Create free account
hub / github.com/chatmail/core / get_html

Method get_html

src/html.rs:262–328  ·  view source on GitHub ↗

Get HTML by database message id. Returns `Some` at least if `Message.has_html()` is true. NB: we do not save raw mime unconditionally in the database to save space. The corresponding ffi-function is `dc_get_msg_html()`.

(self, context: &Context)

Source from the content-addressed store, hash-verified

260 /// NB: we do not save raw mime unconditionally in the database to save space.
261 /// The corresponding ffi-function is `dc_get_msg_html()`.
262 pub async fn get_html(self, context: &Context) -> Result<Option<String>> {
263 let (param, headers, compressed) = context
264 .sql
265 .query_row(
266 "SELECT param, mime_headers, mime_compressed FROM msgs WHERE id=?",
267 (self,),
268 |row| {
269 let param: String = row.get(0)?;
270 let param: Params = param.parse().unwrap_or_default();
271 let headers = sql::row_get_vec(row, 1)?;
272 let compressed: bool = row.get(2)?;
273 Ok((param, headers, compressed))
274 },
275 )
276 .await?;
277 if let Some(html) = param.get(SendHtml) {
278 return Ok(Some(html.to_string()));
279 }
280 let from_rawmime = |rawmime: Vec<u8>| {
281 if !rawmime.is_empty() {
282 match HtmlMsgParser::from_bytes(context, &rawmime) {
283 Err(err) => {
284 warn!(context, "get_html: parser error: {:#}", err);
285 Ok(None)
286 }
287 Ok((parser, _)) => Ok(Some(parser.html)),
288 }
289 } else {
290 warn!(context, "get_html: no mime for {}", self);
291 Ok(None)
292 }
293 };
294
295 if compressed {
296 return from_rawmime(buf_decompress(&headers)?);
297 }
298 let headers2 = headers.clone();
299 let compressed = match tokio::task::block_in_place(move || buf_compress(&headers2)) {
300 Err(e) => {
301 warn!(context, "get_mime_headers: buf_compress() failed: {}", e);
302 return from_rawmime(headers);
303 }
304 Ok(o) => o,
305 };
306 let update = |conn: &mut rusqlite::Connection| {
307 match conn.execute(
308 "
309UPDATE msgs SET mime_headers=?, mime_compressed=1
310WHERE id=? AND mime_headers!='' AND mime_compressed=0",
311 (compressed, self),
312 ) {
313 Ok(rows_updated) => ensure!(rows_updated <= 1),
314 Err(e) => {
315 warn!(context, "get_mime_headers: UPDATE failed: {}", e);
316 return Err(e.into());
317 }
318 }
319 Ok(())

Callers 15

cmdlineFunction · 0.80
dc_get_msg_htmlFunction · 0.80
get_message_htmlMethod · 0.80
render_messageMethod · 0.80
forward_msgs_2ctxFunction · 0.80
test_html_forwardingFunction · 0.80
check_senderFunction · 0.80
check_receiverFunction · 0.80
test_html_save_msgFunction · 0.80
test_set_htmlFunction · 0.80
test_cp1252_htmlFunction · 0.80

Calls 10

row_get_vecFunction · 0.85
buf_decompressFunction · 0.85
buf_compressFunction · 0.85
query_rowMethod · 0.80
parseMethod · 0.80
cloneMethod · 0.80
executeMethod · 0.80
call_writeMethod · 0.80
getMethod · 0.45
is_emptyMethod · 0.45