c_path stringclasses 26
values | c_func stringlengths 79 17.1k | rust_path stringlengths 34 53 | rust_func stringlengths 53 16.4k | rust_context stringlengths 0 36.3k | rust_imports stringlengths 0 2.09k | rustrepotrans_file stringlengths 56 77 |
|---|---|---|---|---|---|---|
projects/deltachat-core/c/dc_oauth2.c | char* dc_get_oauth2_addr(dc_context_t* context, const char* addr,
const char* code)
{
char* access_token = NULL;
char* addr_out = NULL;
oauth2_t* oauth2 = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC
|| (oauth2=get_info(addr))==NULL || oauth2->get_userinfo==NULL) {... | projects/deltachat-core/rust/oauth2.rs | pub(crate) async fn get_oauth2_addr(
context: &Context,
addr: &str,
code: &str,
) -> Result<Option<String>> {
let socks5_enabled = context.get_config_bool(Config::Socks5Enabled).await?;
let oauth2 = match Oauth2::from_address(context, addr, socks5_enabled).await {
Some(o) => o,
None ... | pub async fn get_config_bool(&self, key: Config) -> Result<bool> {
Ok(self.get_config_bool_opt(key).await?.unwrap_or_default())
}
async fn get_addr(&self, context: &Context, access_token: &str) -> Option<String> {
let userinfo_url = self.get_userinfo.unwrap_or("");
let userinfo_url = replac... | use std::collections::HashMap;
use anyhow::Result;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use serde::Deserialize;
use crate::config::Config;
use crate::context::Context;
use crate::provider;
use crate::provider::Oauth2Authorizer;
use crate::socks::Socks5Config;
use crate::tools::time;
use super:... | projects__deltachat-core__rust__oauth2__.rs__function__3.txt |
projects/deltachat-core/c/dc_tools.c | int dc_get_filemeta(const void* buf_start, size_t buf_bytes, uint32_t* ret_width, uint32_t *ret_height)
{
/* Strategy:
reading GIF dimensions requires the first 10 bytes of the file
reading PNG dimensions requires the first 24 bytes of the file
reading JPEG dimensions requires scanning through jpeg chunks
In all f... | projects/deltachat-core/rust/tools.rs | pub fn get_filemeta(buf: &[u8]) -> Result<(u32, u32)> {
let image = image::io::Reader::new(Cursor::new(buf)).with_guessed_format()?;
let dimensions = image.into_dimensions()?;
Ok(dimensions)
} | use std::borrow::Cow;
use std::io::{Cursor, Write};
use std::mem;
use std::path::{Path, PathBuf};
use std::str::from_utf8;
use std::time::Duration;
use std::time::SystemTime as Time;
use std::time::SystemTime;
use anyhow::{bail, Context as _, Result};
use base64::Engine as _;
use chrono::{Local, NaiveDateTime, NaiveTim... | projects__deltachat-core__rust__tools__.rs__function__17.txt | |
projects/deltachat-core/c/dc_chatlist.c | dc_lot_t* dc_chatlist_get_summary(const dc_chatlist_t* chatlist, size_t index, dc_chat_t* chat /*may be NULL*/)
{
/* The summary is created by the chat, not by the last message.
This is because we may want to display drafts here or stuff as
"is typing".
Also, sth. as "No messages" would not work if the summary come... | projects/deltachat-core/rust/chatlist.rs | pub async fn get_summary(
&self,
context: &Context,
index: usize,
chat: Option<&Chat>,
) -> Result<Summary> {
// The summary is created by the chat, not by the last message.
// This is because we may want to display drafts here or stuff as
// "is typing".
... | pub fn get(&self, key: Param) -> Option<&str> {
self.inner.get(&key).map(|s| s.as_str())
}
pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
pub struct Chatlist {
/// Stores pairs of `chat_id, message_id`
ids: Vec<(ChatId, Option<MsgId>)>,
}
pub async fn get_summary2(
contex... | use anyhow::{ensure, Context as _, Result};
use once_cell::sync::Lazy;
use crate::chat::{update_special_chat_names, Chat, ChatId, ChatVisibility};
use crate::constants::{
Blocked, Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, DC_GCL_ADD_ALLDONE_HINT,
DC_GCL_ARCHIVED_ONLY, DC_GCL_FOR_FORWARDING, D... | projects__deltachat-core__rust__chatlist__.rs__function__7.txt |
projects/deltachat-core/c/dc_configure.c | * Frees the process allocated with dc_alloc_ongoing() - independingly of dc_shall_stop_ongoing.
* If dc_alloc_ongoing() fails, this function MUST NOT be called.
*/
void dc_free_ongoing(dc_context_t* context)
{
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
return;
}
context->ongoing_running = 0;
c... | projects/deltachat-core/rust/context.rs | pub(crate) async fn free_ongoing(&self) {
let mut s = self.running_state.write().await;
if let RunningState::ShallStop { request } = *s {
info!(self, "Ongoing stopped in {:?}", time_elapsed(&request));
}
*s = RunningState::Stopped;
} | macro_rules! info {
($ctx:expr, $msg:expr) => {
info!($ctx, $msg,)
};
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{
let formatted = format!($msg, $($args),*);
let full = format!("{file}:{line}: {msg}",
file = file!(),
line ... | use std::collections::{BTreeMap, HashMap};
use std::ffi::OsString;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
us... | projects__deltachat-core__rust__context__.rs__function__38.txt |
projects/deltachat-core/c/dc_param.c | int32_t dc_param_get_int(const dc_param_t* param, int key, int32_t def)
{
if (param==NULL || key==0) {
return def;
}
char* str = dc_param_get(param, key, NULL);
if (str==NULL) {
return def;
}
int32_t ret = atol(str);
free(str);
return ret;
} | projects/deltachat-core/rust/param.rs | pub fn get_int(&self, key: Param) -> Option<i32> {
self.get(key).and_then(|s| s.parse().ok())
} | pub fn get(&self, key: Param) -> Option<&str> {
self.inner.get(&key).map(|s| s.as_str())
}
pub struct Params {
inner: BTreeMap<Param, String>,
} | use std::collections::BTreeMap;
use std::fmt;
use std::path::PathBuf;
use std::str;
use anyhow::{bail, Error, Result};
use num_traits::FromPrimitive;
use serde::{Deserialize, Serialize};
use crate::blob::BlobObject;
use crate::context::Context;
use crate::mimeparser::SystemMessage;
use std::path::Path;
use std::str::Fr... | projects__deltachat-core__rust__param__.rs__function__11.txt |
projects/deltachat-core/c/dc_chat.c | static uint32_t get_draft_msg_id(dc_context_t* context, uint32_t chat_id)
{
uint32_t draft_msg_id = 0;
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql,
"SELECT id FROM msgs WHERE chat_id=? AND state=?;");
sqlite3_bind_int(stmt, 1, chat_id);
sqlite3_bind_int(stmt, 2, DC_STATE_OUT_DRAFT);
if (sqlite3_step(st... | projects/deltachat-core/rust/chat.rs | async fn get_draft_msg_id(self, context: &Context) -> Result<Option<MsgId>> {
let msg_id: Option<MsgId> = context
.sql
.query_get_value(
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
(self, MessageState::OutDraft),
)
.await?;
... | pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
ub struct InnerContext {
/// Blob directory path
pub(crate) blobdir: PathBuf,
pub(crate) sql: Sql,
pub(crate) smeared_timestamp: SmearedTimestamp,
/// The global "ongoing" process state.
///
/// This is a global mutex-like stat... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__32.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_is_info(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
int cmd = dc_param_get_int(msg->param, DC_PARAM_CMD, 0);
if (msg->from_id==DC_CONTACT_ID_INFO
|| msg->to_id==DC_CONTACT_ID_INFO
|| (cmd && cmd!=DC_CMD_AUTOCRYPT_SETUP_MESSAGE)) {
return 1;
}
return 0;
} | projects/deltachat-core/rust/message.rs | pub fn is_info(&self) -> bool {
let cmd = self.param.get_cmd();
self.from_id == ContactId::INFO
|| self.to_id == ContactId::INFO
|| cmd != SystemMessage::Unknown && cmd != SystemMessage::AutocryptSetupMessage
} | pub fn get_cmd(&self) -> SystemMessage {
self.get_int(Param::Cmd)
.and_then(SystemMessage::from_i32)
.unwrap_or_default()
}
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first con... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__56.txt |
projects/deltachat-core/c/dc_simplify.c | static int is_plain_quote(const char* buf)
{
if (buf[0]=='>') {
return 1;
}
return 0;
} | projects/deltachat-core/rust/simplify.rs | fn is_plain_quote(buf: &str) -> bool {
buf.starts_with('>')
} | projects__deltachat-core__rust__simplify__.rs__function__14.txt | ||
projects/deltachat-core/c/dc_chat.c | * If the group is already _promoted_ (any message was sent to the group),
* all group members are informed by a special status message that is sent automatically by this function.
*
* Sends out #DC_EVENT_CHAT_MODIFIED and #DC_EVENT_MSGS_CHANGED if a status message was sent.
*
* @memberof dc_context_t
* @param con... | projects/deltachat-core/rust/chat.rs | pub async fn remove_contact_from_chat(
context: &Context,
chat_id: ChatId,
contact_id: ContactId,
) -> Result<()> {
ensure!(
!chat_id.is_special(),
"bad chat_id, can not be special chat: {}",
chat_id
);
ensure!(
!contact_id.is_special() || contact_id == ContactId:... | async fn set_group_explicitly_left(context: &Context, grpid: &str) -> Result<()> {
if !is_group_explicitly_left(context, grpid).await? {
context
.sql
.execute("INSERT INTO leftgrps (grpid) VALUES(?);", (grpid,))
.await?;
}
Ok(())
}
pub async fn send_msg(context:... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__133.txt |
projects/deltachat-core/c/dc_chat.c | int dc_chat_is_self_talk(const dc_chat_t* chat)
{
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
return 0;
}
return dc_param_exists(chat->param, DC_PARAM_SELFTALK);
} | projects/deltachat-core/rust/chat.rs | pub fn is_self_talk(&self) -> bool {
self.param.exists(Param::Selftalk)
} | pub fn exists(&self, key: Param) -> bool {
self.inner.contains_key(&key)
}
pub struct Chat {
/// Database ID.
pub id: ChatId,
/// Chat type, e.g. 1:1 chat, group chat, mailing list.
pub typ: Chattype,
/// Chat name.
pub name: String,
/// Whether the chat is archived or pinned... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__61.txt |
projects/deltachat-core/c/dc_msg.c | void dc_msg_set_file(dc_msg_t* msg, const char* file, const char* filemime)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return;
}
dc_param_set(msg->param, DC_PARAM_FILE, file);
dc_param_set_optional(msg->param, DC_PARAM_MIMETYPE, filemime);
} | projects/deltachat-core/rust/message.rs | pub fn set_file(&mut self, file: impl ToString, filemime: Option<&str>) {
if let Some(name) = Path::new(&file.to_string()).file_name() {
if let Some(name) = name.to_str() {
self.param.set(Param::Filename, name);
}
}
self.param.set(Param::File, file);
... | pub fn set(&mut self, key: Param, value: impl ToString) -> &mut Self {
self.inner.insert(key, value.to_string());
self
}
pub fn set_optional(&mut self, key: Param, value: Option<impl ToString>) -> &mut Self {
if let Some(value) = value {
self.set(key, value)
} else {
... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__68.txt |
projects/deltachat-core/c/dc_chat.c | int dc_is_contact_in_chat(dc_context_t* context, uint32_t chat_id, uint32_t contact_id)
{
/* this function works for group and for normal chats, however, it is more useful for group chats.
DC_CONTACT_ID_SELF may be used to check, if the user itself is in a group chat (DC_CONTACT_ID_SELF is not added to normal chats) ... | projects/deltachat-core/rust/chat.rs | pub async fn is_contact_in_chat(
context: &Context,
chat_id: ChatId,
contact_id: ContactId,
) -> Result<bool> {
// this function works for group and for normal chats, however, it is more useful
// for group chats.
// ContactId::SELF may be used to check, if the user itself is in a group
// c... | pub async fn exists(&self, sql: &str, params: impl rusqlite::Params + Send) -> Result<bool> {
let count = self.count(sql, params).await?;
Ok(count > 0)
}
pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
pub struct InnerContext {
/// Blob directory path
pub(crate) blobdir: Pa... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__103.txt |
projects/deltachat-core/c/dc_context.c | * The returned string must be free()'d.
*/
char* dc_get_blobdir(const dc_context_t* context)
{
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
return dc_strdup(NULL);
}
return dc_strdup(context->blobdir);
} | projects/deltachat-core/rust/context.rs | pub fn get_blobdir(&self) -> &Path {
self.blobdir.as_path()
} | pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
pub struct InnerContext {
/// Blob directory path
pub(crate) blobdir: PathBuf,
pub(crate) sql: Sql,
pub(crate) smeared_timestamp: SmearedTimestamp,
/// The global "ongoing" process state.
///
/// This is a global mutex-like sta... | use std::collections::{BTreeMap, HashMap};
use std::ffi::OsString;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
us... | projects__deltachat-core__rust__context__.rs__function__29.txt |
projects/deltachat-core/c/dc_e2ee.c | static int has_decrypted_pgp_armor(const char* str__, int str_bytes)
{
const unsigned char* str_end = (const unsigned char*)str__+str_bytes;
const unsigned char* p=(const unsigned char*)str__;
while (p < str_end) {
if (*p > ' ') {
break;
}
p++;
str_bytes--;
}
if (str_bytes>26 && strncmp((const char*)p, ... | projects/deltachat-core/rust/decrypt.rs | fn has_decrypted_pgp_armor(input: &[u8]) -> bool {
if let Some(index) = input.iter().position(|b| *b > b' ') {
if input.len() - index > 26 {
let start = index;
let end = start + 27;
return &input[start..end] == b"-----BEGIN PGP MESSAGE-----";
}
}
false
} | use std::collections::HashSet;
use std::str::FromStr;
use anyhow::Result;
use deltachat_contact_tools::addr_cmp;
use mailparse::ParsedMail;
use crate::aheader::Aheader;
use crate::authres::handle_authres;
use crate::authres::{self, DkimResults};
use crate::context::Context;
use crate::headerdef::{HeaderDef, HeaderDefMa... | projects__deltachat-core__rust__decrypt__.rs__function__8.txt | |
projects/deltachat-core/c/dc_tools.c | int dc_write_file(dc_context_t* context, const char* pathNfilename, const void* buf, size_t buf_bytes)
{
int success = 0;
char* pathNfilename_abs = NULL;
if ((pathNfilename_abs=dc_get_abs_path(context, pathNfilename))==NULL) {
goto cleanup;
}
FILE* f = fopen(pathNfilename_abs, "wb");
if (f) {
if (fwrite(b... | projects/deltachat-core/rust/tools.rs | pub(crate) async fn write_file(
context: &Context,
path: impl AsRef<Path>,
buf: &[u8],
) -> Result<(), io::Error> {
let path_abs = get_abs_path(context, path.as_ref());
fs::write(&path_abs, buf).await.map_err(|err| {
warn!(
context,
"Cannot write {} bytes to \"{}\": {... | pub(crate) fn get_abs_path(context: &Context, path: &Path) -> PathBuf {
if let Ok(p) = path.strip_prefix("$BLOBDIR") {
context.get_blobdir().join(p)
} else {
path.into()
}
}
pub struct Context {
pub(crate) inner: Arc<InnerContext>,
} | use std::borrow::Cow;
use std::io::{Cursor, Write};
use std::mem;
use std::path::{Path, PathBuf};
use std::str::from_utf8;
use std::time::Duration;
use std::time::SystemTime as Time;
use std::time::SystemTime;
use anyhow::{bail, Context as _, Result};
use base64::Engine as _;
use chrono::{Local, NaiveDateTime, NaiveTim... | projects__deltachat-core__rust__tools__.rs__function__23.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_get_height(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
return dc_param_get_int(msg->param, DC_PARAM_HEIGHT, 0);
} | projects/deltachat-core/rust/message.rs | pub fn get_height(&self) -> i32 {
self.param.get_int(Param::Height).unwrap_or_default()
} | pub fn get_int(&self, key: Param) -> Option<i32> {
self.get(key).and_then(|s| s.parse().ok())
}
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
pub(crate) to_id: Cont... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__44.txt |
projects/deltachat-core/c/dc_chat.c | uint32_t dc_chat_get_id(const dc_chat_t* chat)
{
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
return 0;
}
return chat->id;
} | projects/deltachat-core/rust/chat.rs | pub fn get_id(&self) -> ChatId {
self.id
} | pub struct Chat {
/// Database ID.
pub id: ChatId,
/// Chat type, e.g. 1:1 chat, group chat, mailing list.
pub typ: Chattype,
/// Chat name.
pub name: String,
/// Whether the chat is archived or pinned.
pub visibility: ChatVisibility,
/// Group ID. For [`Chattype::Mailinglist`] -... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__69.txt |
projects/deltachat-core/c/dc_msg.c | void dc_msg_set_text(dc_msg_t* msg, const char* text)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return;
}
free(msg->text);
msg->text = dc_strdup(text);
} | projects/deltachat-core/rust/message.rs | pub fn set_text(&mut self, text: String) {
self.text = text;
} | pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
pub(crate) to_id: ContactId,
/// ID of the chat message belongs to.
pub(crate) chat_id: ChatId,
/// Type of the messa... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__66.txt |
projects/deltachat-core/c/dc_chat.c | uint32_t dc_get_chat_id_by_grpid(dc_context_t* context, const char* grpid, int* ret_blocked, int* ret_verified)
{
uint32_t chat_id = 0;
sqlite3_stmt* stmt = NULL;
if(ret_blocked) { *ret_blocked = 0; }
if(ret_verified) { *ret_verified = 0; }
if (context==NULL || grpid==NULL) {
goto cleanup;
}
stmt = d... | projects/deltachat-core/rust/chat.rs | pub(crate) async fn get_chat_id_by_grpid(
context: &Context,
grpid: &str,
) -> Result<Option<(ChatId, bool, Blocked)>> {
context
.sql
.query_row_optional(
"SELECT id, blocked, protected FROM chats WHERE grpid=?;",
(grpid,),
|row| {
let chat... | pub async fn query_row_optional<T, F>(
&self,
sql: &str,
params: impl rusqlite::Params + Send,
f: F,
) -> Result<Option<T>>
where
F: Send + FnOnce(&rusqlite::Row) -> rusqlite::Result<T>,
T: Send + 'static,
{
self.call(move |conn| match conn.query_row(s... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__142.txt |
projects/deltachat-core/c/dc_strencode.c | int dc_needs_ext_header(const char* to_check)
{
if (to_check) {
while (*to_check)
{
if (!isalnum(*to_check) && *to_check!='-' && *to_check!='_' && *to_check!='.' && *to_check!='~' && *to_check!='%') {
return 1;
}
to_check++;
}
}
return 0;
} | projects/deltachat-core/rust/mimefactory.rs | fn needs_encoding(to_check: &str) -> bool {
!to_check.chars().all(|c| {
c.is_ascii_alphanumeric() || c == '-' || c == '_' || c == '.' || c == '~' || c == '%'
})
} | use deltachat_contact_tools::ContactAddress;
use mailparse::{addrparse_header, MailHeaderMap};
use std::str;
use super::*;
use crate::chat::{
add_contact_to_chat, create_group_chat, remove_contact_from_chat, send_text_msg, ChatId,
ProtectionStatus,
};
use crate::chatlist::Chatlist;
use crate::consta... | projects__deltachat-core__rust__mimefactory__.rs__function__26.txt | |
projects/deltachat-core/c/dc_msg.c | void dc_set_msg_failed(dc_context_t* context, uint32_t msg_id, const char* error)
{
dc_msg_t* msg = dc_msg_new_untyped(context);
sqlite3_stmt* stmt = NULL;
if (!dc_msg_load_from_db(msg, context, msg_id)) {
goto cleanup;
}
if (DC_STATE_OUT_PREPARING==msg->state ||
DC_STATE_OUT_PENDING ==msg->state ||
... | projects/deltachat-core/rust/message.rs | pub(crate) async fn set_msg_failed(
context: &Context,
msg: &mut Message,
error: &str,
) -> Result<()> {
if msg.state.can_fail() {
msg.state = MessageState::OutFailed;
warn!(context, "{} failed: {}", msg.id, error);
} else {
warn!(
context,
"{} seems t... | pub fn can_fail(self) -> bool {
use MessageState::*;
matches!(
self,
OutPreparing | OutPending | OutDelivered | OutMdnRcvd // OutMdnRcvd can still fail because it could be a group message and only some recipients failed.
)
}
macro_rules! warn {
($ctx:expr, $msg:e... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__92.txt |
projects/deltachat-core/c/dc_chat.c | * using dc_set_chat_profile_image().
* For normal chats, this is the image set by each remote user on their own
* using dc_set_config(context, "selfavatar", image).
*
* @memberof dc_chat_t
* @param chat The chat object.
* @return Path and file if the profile image, if any.
* NULL otherwise.
* Must be fr... | projects/deltachat-core/rust/chat.rs | pub async fn get_profile_image(&self, context: &Context) -> Result<Option<PathBuf>> {
if let Some(image_rel) = self.param.get(Param::ProfileImage) {
if !image_rel.is_empty() {
return Ok(Some(get_abs_path(context, Path::new(&image_rel))));
}
} else if self.id.is_ar... | pub async fn get_chat_contacts(context: &Context, chat_id: ChatId) -> Result<Vec<ContactId>> {
// Normal chats do not include SELF. Group chats do (as it may happen that one is deleted from a
// groupchat but the chats stays visible, moreover, this makes displaying lists easier)
let list = context
... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__73.txt |
projects/deltachat-core/c/dc_location.c | dc_kml_t* dc_kml_parse(dc_context_t* context,
const char* content, size_t content_bytes)
{
dc_kml_t* kml = calloc(1, sizeof(dc_kml_t));
char* content_nullterminated = NULL;
dc_saxparser_t saxparser;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
i... | projects/deltachat-core/rust/location.rs | pub fn parse(to_parse: &[u8]) -> Result<Self> {
ensure!(to_parse.len() <= 1024 * 1024, "kml-file is too large");
let mut reader = quick_xml::Reader::from_reader(to_parse);
reader.trim_text(true);
let mut kml = Kml::new();
kml.locations = Vec::with_capacity(100);
let mu... | fn endtag_cb(&mut self, event: &BytesEnd) {
let tag = String::from_utf8_lossy(event.name().as_ref())
.trim()
.to_lowercase();
match self.tag {
KmlTag::PlacemarkTimestampWhen => {
if tag == "when" {
self.tag = KmlTag::PlacemarkTimes... | use std::time::Duration;
use anyhow::{ensure, Context as _, Result};
use async_channel::Receiver;
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
use tokio::time::timeout;
use crate::chat::{self, ChatId};
use crate::constants::DC_CHAT_ID_TRASH;
use crate::contact::ContactId;
use crate::context::Context;
use c... | projects__deltachat-core__rust__location__.rs__function__3.txt |
projects/deltachat-core/c/dc_oauth2.c | char* dc_get_oauth2_url(dc_context_t* context, const char* addr,
const char* redirect_uri)
{
#define CLIENT_ID "959970109878-4mvtgf6feshskf7695nfln6002mom908.apps.googleusercontent.com"
oauth2_t* oauth2 = NULL;
char* oauth2_url = NULL;
if (context==NULL || context->magic!=DC_CON... | projects/deltachat-core/rust/oauth2.rs | pub async fn get_oauth2_url(
context: &Context,
addr: &str,
redirect_uri: &str,
) -> Result<Option<String>> {
let socks5_enabled = context.get_config_bool(Config::Socks5Enabled).await?;
if let Some(oauth2) = Oauth2::from_address(context, addr, socks5_enabled).await {
context
.sql... | pub async fn get_config_bool(&self, key: Config) -> Result<bool> {
Ok(self.get_config_bool_opt(key).await?.unwrap_or_default())
}
fn replace_in_uri(uri: &str, key: &str, value: &str) -> String {
let value_urlencoded = utf8_percent_encode(value, NON_ALPHANUMERIC).to_string();
uri.replace(key, &value... | use std::collections::HashMap;
use anyhow::Result;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use serde::Deserialize;
use crate::config::Config;
use crate::context::Context;
use crate::provider;
use crate::provider::Oauth2Authorizer;
use crate::socks::Socks5Config;
use crate::tools::time;
use super:... | projects__deltachat-core__rust__oauth2__.rs__function__1.txt |
projects/deltachat-core/c/dc_msg.c | time_t dc_msg_get_timestamp(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
return msg->timestamp_sent? msg->timestamp_sent : msg->timestamp_sort;
} | projects/deltachat-core/rust/message.rs | pub fn get_timestamp(&self) -> i64 {
if 0 != self.timestamp_sent {
self.timestamp_sent
} else {
self.timestamp_sort
}
} | pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
pub(crate) to_id: ContactId,
/// ID of the chat message belongs to.
pub(crate) chat_id: ChatId,
/// Type of the messa... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__29.txt |
projects/deltachat-core/c/dc_chat.c | * so you have to free it using dc_msg_unref() as usual.
* @return The ID of the message that is being prepared.
*/
uint32_t dc_prepare_msg(dc_context_t* context, uint32_t chat_id, dc_msg_t* msg)
{
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || msg==NULL || chat_id<=DC_CHAT_ID_LAST_SPECIAL) {
return 0... | projects/deltachat-core/rust/chat.rs | pub async fn prepare_msg(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> {
ensure!(
!chat_id.is_special(),
"Cannot prepare message for special chat"
);
let msg_id = prepare_msg_common(context, chat_id, msg, MessageState::OutPreparing).await?;
context.emit_msgs_ch... | pub fn is_special(self) -> bool {
(0..=DC_CHAT_ID_LAST_SPECIAL.0).contains(&self.0)
}
pub fn emit_msgs_changed(&self, chat_id: ChatId, msg_id: MsgId) {
self.emit_event(EventType::MsgsChanged { chat_id, msg_id });
chatlist_events::emit_chatlist_changed(self);
chatlist_events::emit_ch... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__100.txt |
projects/deltachat-core/c/dc_tools.c | time_t dc_create_smeared_timestamp(dc_context_t* context)
{
time_t now = time(NULL);
time_t ret = now;
SMEAR_LOCK
context->last_smeared_timestamp = ret;
SMEAR_UNLOCK
return ret;
} | projects/deltachat-core/rust/tools.rs | pub(crate) fn create_smeared_timestamp(context: &Context) -> i64 {
let now = time();
context.smeared_timestamp.create(now)
} | pub fn create(&self, now: i64) -> i64 {
self.create_n(now, 1)
}
pub(crate) fn time() -> i64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64
}
pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
pub struct InnerCont... | use std::borrow::Cow;
use std::io::{Cursor, Write};
use std::mem;
use std::path::{Path, PathBuf};
use std::str::from_utf8;
use std::time::Duration;
use std::time::SystemTime as Time;
use std::time::SystemTime;
use anyhow::{bail, Context as _, Result};
use base64::Engine as _;
use chrono::{Local, NaiveDateTime, NaiveTim... | projects__deltachat-core__rust__tools__.rs__function__7.txt |
projects/deltachat-core/c/dc_imex.c | char* dc_initiate_key_transfer(dc_context_t* context)
{
int success = 0;
char* setup_code = NULL;
char* setup_file_content = NULL;
char* setup_file_name = NULL;
uint32_t chat_id = 0;
dc_msg_t* msg = NULL;
uint32_t msg_id = 0;
if (!dc_alloc_ongoing(context)) {
return 0; /* no cleanup as th... | projects/deltachat-core/rust/imex.rs | pub async fn initiate_key_transfer(context: &Context) -> Result<String> {
let setup_code = create_setup_code(context);
/* this may require a keypair to be created. this may take a second ... */
let setup_file_content = render_setup_file(context, &setup_code).await?;
/* encrypting may also take a while .... | pub async fn send_msg(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> {
if chat_id.is_unset() {
let forwards = msg.param.get(Param::PrepForwards);
if let Some(forwards) = forwards {
for forward in forwards.split(' ') {
if let Ok(msg_id) = forward.p... | use std::any::Any;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use deltachat_contact_tools::EmailAddress;
use futures::StreamExt;
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
use ... | projects__deltachat-core__rust__imex__.rs__function__3.txt |
projects/deltachat-core/c/dc_chatlist.c | int dc_get_archived_cnt(dc_context_t* context)
{
int ret = 0;
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql,
"SELECT COUNT(*) FROM chats WHERE blocked!=1 AND archived=1;");
if (sqlite3_step(stmt)==SQLITE_ROW) {
ret = sqlite3_column_int(stmt, 0);
}
sqlite3_finalize(stmt);
return ret;
} | projects/deltachat-core/rust/chatlist.rs | pub async fn get_archived_cnt(context: &Context) -> Result<usize> {
let count = context
.sql
.count(
"SELECT COUNT(*) FROM chats WHERE blocked!=? AND archived=?;",
(Blocked::Yes, ChatVisibility::Archived),
)
.await?;
Ok(count)
} | pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
pub struct InnerContext {
/// Blob directory path
pub(crate) blobdir: PathBuf,
pub(crate) sql: Sql,
pub(crate) smeared_timestamp: SmearedTimestamp,
/// The global "ongoing" process state.
///
/// This is a global mutex-like sta... | use anyhow::{ensure, Context as _, Result};
use once_cell::sync::Lazy;
use crate::chat::{update_special_chat_names, Chat, ChatId, ChatVisibility};
use crate::constants::{
Blocked, Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, DC_GCL_ADD_ALLDONE_HINT,
DC_GCL_ARCHIVED_ONLY, DC_GCL_FOR_FORWARDING, D... | projects__deltachat-core__rust__chatlist__.rs__function__11.txt |
projects/deltachat-core/c/dc_imex.c | static int export_key_to_asc_file(dc_context_t* context, const char* dir, int id, const dc_key_t* key, int is_default)
{
int success = 0;
char* file_name = NULL;
if (is_default) {
file_name = dc_mprintf("%s/%s-key-default.asc", dir, key->type==DC_KEY_PUBLIC? "public" : "private");
}
else {
file_name = dc_mp... | projects/deltachat-core/rust/imex.rs | async fn export_key_to_asc_file<T>(
context: &Context,
dir: &Path,
id: Option<i64>,
key: &T,
) -> Result<()>
where
T: DcKey + Any,
{
let file_name = {
let any_key = key as &dyn Any;
let kind = if any_key.downcast_ref::<SignedPublicKey>().is_some() {
"public"
}... | pub(crate) async fn write_file(
context: &Context,
path: impl AsRef<Path>,
buf: &[u8],
) -> Result<(), io::Error> {
let path_abs = get_abs_path(context, path.as_ref());
fs::write(&path_abs, buf).await.map_err(|err| {
warn!(
context,
"Cannot write {} bytes to \"{}\": {... | use std::any::Any;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use deltachat_contact_tools::EmailAddress;
use futures::StreamExt;
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
use ... | projects__deltachat-core__rust__imex__.rs__function__20.txt |
projects/deltachat-core/c/dc_imex.c | char* dc_render_setup_file(dc_context_t* context, const char* passphrase)
{
sqlite3_stmt* stmt = NULL;
char* self_addr = NULL;
dc_key_t* curr_private_key = dc_key_new();
char passphrase_begin[8];
char* encr_string = NULL;
char* ... | projects/deltachat-core/rust/imex.rs | pub async fn render_setup_file(context: &Context, passphrase: &str) -> Result<String> {
let passphrase_begin = if let Some(passphrase_begin) = passphrase.get(..2) {
passphrase_begin
} else {
bail!("Passphrase must be at least 2 chars long.");
};
let private_key = load_self_secret_key(con... | pub fn get(&self, key: Param) -> Option<&str> {
self.inner.get(&key).map(|s| s.as_str())
}
pub async fn get_config_bool(&self, key: Config) -> Result<bool> {
Ok(self.get_config_bool_opt(key).await?.unwrap_or_default())
}
pub(crate) async fn load_self_secret_key(context: &Context) -> Result<Sig... | use std::any::Any;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use deltachat_contact_tools::EmailAddress;
use futures::StreamExt;
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
use ... | projects__deltachat-core__rust__imex__.rs__function__4.txt |
projects/deltachat-core/c/dc_chat.c | uint32_t dc_chat_get_color(const dc_chat_t* chat)
{
uint32_t color = 0;
dc_array_t* contacts = NULL;
dc_contact_t* contact = NULL;
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
goto cleanup;
}
if(chat->type==DC_CHAT_TYPE_SINGLE) {
contacts = dc_get_chat_contacts(chat->context, chat->id);
if (cont... | projects/deltachat-core/rust/chat.rs | pub async fn get_color(&self, context: &Context) -> Result<u32> {
let mut color = 0;
if self.typ == Chattype::Single {
let contacts = get_chat_contacts(context, self.id).await?;
if let Some(contact_id) = contacts.first() {
if let Ok(contact) = Contact::get_by_id(... | pub async fn get_chat_contacts(context: &Context, chat_id: ChatId) -> Result<Vec<ContactId>> {
// Normal chats do not include SELF. Group chats do (as it may happen that one is deleted from a
// groupchat but the chats stays visible, moreover, this makes displaying lists easier)
let list = context
... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__74.txt |
projects/deltachat-core/c/dc_qr.c | dc_lot_t* dc_check_qr(dc_context_t* context, const char* qr)
{
char* payload = NULL;
char* addr = NULL; // must be normalized, if set
char* fingerprint = NULL; // must be normalized, if set
char* name = NULL;
char* invitenumber = NULL;
char* auth =... | projects/deltachat-core/rust/qr.rs | pub async fn check_qr(context: &Context, qr: &str) -> Result<Qr> {
let qrcode = if starts_with_ignore_case(qr, OPENPGP4FPR_SCHEME) {
decode_openpgp(context, qr)
.await
.context("failed to decode OPENPGP4FPR QR code")?
} else if qr.starts_with(IDELTACHAT_SCHEME) {
decode_i... | async fn decode_mailto(context: &Context, qr: &str) -> Result<Qr> {
let payload = &qr[MAILTO_SCHEME.len()..];
let (addr, query) = if let Some(query_index) = payload.find('?') {
(&payload[..query_index], &payload[query_index + 1..])
} else {
(payload, "")
};
let param: BTreeMap<&str... | use std::collections::BTreeMap;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use dclogin_scheme::LoginOptions;
use deltachat_contact_tools::{addr_normalize, may_be_valid_addr, ContactAddress};
use once_cell::sync::Lazy;
use percent_encoding::percent_decode_str;
use serde::Deserialize;
use self::dclogin_sch... | projects__deltachat-core__rust__qr__.rs__function__2.txt |
projects/deltachat-core/c/dc_chat.c | * If dc_prepare_msg() was called before, this parameter can be 0.
* @param msg Message object to send to the chat defined by the chat ID.
* On succcess, msg_id of the object is set up,
* The function does not take ownership of the object,
* so you have to free it using dc_msg_unref() as usual.
* @r... | projects/deltachat-core/rust/chat.rs | pub async fn send_msg(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> {
if chat_id.is_unset() {
let forwards = msg.param.get(Param::PrepForwards);
if let Some(forwards) = forwards {
for forward in forwards.split(' ') {
if let Ok(msg_id) = forward.p... | pub(crate) async fn update_param(&mut self, context: &Context) -> Result<()> {
context
.sql
.execute(
"UPDATE chats SET param=? WHERE id=?",
(self.param.to_string(), self.id),
)
.await?;
Ok(())
}
pub fn remove(&mut self... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__104.txt |
projects/deltachat-core/c/dc_chat.c | int dc_add_contact_to_chat_ex(dc_context_t* context, uint32_t chat_id, uint32_t contact_id, int flags)
{
int success = 0;
dc_contact_t* contact = dc_get_contact(context, contact_id);
dc_chat_t* chat = dc_chat_new(context);
dc_msg_t* msg = dc_msg_new_untyped(context);
char* s... | projects/deltachat-core/rust/chat.rs | pub(crate) async fn add_contact_to_chat_ex(
context: &Context,
mut sync: sync::Sync,
chat_id: ChatId,
contact_id: ContactId,
from_handshake: bool,
) -> Result<bool> {
ensure!(!chat_id.is_special(), "can not add member to special chats");
let contact = Contact::get_by_id(context, contact_id).... | pub fn is_special(self) -> bool {
(0..=DC_CHAT_ID_LAST_SPECIAL.0).contains(&self.0)
}
pub async fn get_by_id(context: &Context, contact_id: ContactId) -> Result<Self> {
let contact = Self::get_by_id_optional(context, contact_id)
.await?
.with_context(|| format!("contact {con... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__127.txt |
projects/deltachat-core/c/dc_securejoin.c | uint32_t dc_join_securejoin(dc_context_t* context, const char* qr)
{
/* ==========================================================
==== Bob - the joiner's side =====
==== Step 2 in "Setup verified contact" protocol =====
==========================================================... | projects/deltachat-core/rust/securejoin.rs | pub async fn join_securejoin(context: &Context, qr: &str) -> Result<ChatId> {
securejoin(context, qr).await.map_err(|err| {
warn!(context, "Fatal joiner error: {:#}", err);
// The user just scanned this QR code so has context on what failed.
error!(context, "QR process failed");
err
... | pub fn error(&self) -> Option<String> {
self.error.clone()
}
async fn securejoin(context: &Context, qr: &str) -> Result<ChatId> {
/*========================================================
==== Bob - the joiner's side =====
==== Step 2 in "Setup verified contact" proto... | use anyhow::{bail, Context as _, Error, Result};
use percent_encoding::{utf8_percent_encode, AsciiSet, NON_ALPHANUMERIC};
use crate::aheader::EncryptPreference;
use crate::chat::{self, Chat, ChatId, ChatIdBlocked, ProtectionStatus};
use crate::chatlist_events;
use crate::config::Config;
use crate::constants::Blocked;
u... | projects__deltachat-core__rust__securejoin__.rs__function__4.txt |
projects/deltachat-core/c/dc_contact.c | uint32_t dc_contact_get_color(const dc_contact_t* contact)
{
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
return 0x000000;
}
return dc_str_to_color(contact->addr);
} | projects/deltachat-core/rust/contact.rs | pub fn get_color(&self) -> u32 {
str_to_color(&self.addr.to_lowercase())
} | pub struct Contact {
/// The contact ID.
pub id: ContactId,
/// Contact name. It is recommended to use `Contact::get_name`,
/// `Contact::get_display_name` or `Contact::get_name_n_addr` to access this field.
/// May be empty, initially set to `authname`.
name: String,
/// Name authorized b... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__44.txt |
projects/deltachat-core/c/dc_chat.c | * If the group is already _promoted_ (any message was sent to the group),
* all group members are informed by a special status message that is sent automatically by this function.
*
* If the group is a verified group, only verified contacts can be added to the group.
*
* Sends out #DC_EVENT_CHAT_MODIFIED and #DC_E... | projects/deltachat-core/rust/chat.rs | pub async fn add_contact_to_chat(
context: &Context,
chat_id: ChatId,
contact_id: ContactId,
) -> Result<()> {
add_contact_to_chat_ex(context, Sync, chat_id, contact_id, false).await?;
Ok(())
} | pub(crate) async fn add_contact_to_chat_ex(
context: &Context,
mut sync: sync::Sync,
chat_id: ChatId,
contact_id: ContactId,
from_handshake: bool,
) -> Result<bool> {
ensure!(!chat_id.is_special(), "can not add member to special chats");
let contact = Contact::get_by_id(context, contact_id).... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__126.txt |
projects/deltachat-core/c/dc_param.c | void dc_param_set_int(dc_param_t* param, int key, int32_t value)
{
if (param==NULL || key==0) {
return;
}
char* value_str = dc_mprintf("%i", (int)value);
if (value_str==NULL) {
return;
}
dc_param_set(param, key, value_str);
free(value_str);
} | projects/deltachat-core/rust/param.rs | pub fn set_int(&mut self, key: Param, value: i32) -> &mut Self {
self.set(key, format!("{value}"));
self
} | pub fn set(&mut self, key: Param, value: impl ToString) -> &mut Self {
self.inner.insert(key, value.to_string());
self
}
pub struct Params {
inner: BTreeMap<Param, String>,
} | use std::collections::BTreeMap;
use std::fmt;
use std::path::PathBuf;
use std::str;
use anyhow::{bail, Error, Result};
use num_traits::FromPrimitive;
use serde::{Deserialize, Serialize};
use crate::blob::BlobObject;
use crate::context::Context;
use crate::mimeparser::SystemMessage;
use std::path::Path;
use std::str::Fr... | projects__deltachat-core__rust__param__.rs__function__20.txt |
projects/deltachat-core/c/dc_param.c | char* dc_param_get(const dc_param_t* param, int key, const char* def)
{
char* p1 = NULL;
char* p2 = NULL;
char bak = 0;
char* ret = NULL;
if (param==NULL || key==0) {
return def? dc_strdup(def) : NULL;
}
p1 = find_param(param->packed, key, &p2);
if (p1==NULL) {
return def? dc_strdup(def) : NULL;
}
p1 ... | projects/deltachat-core/rust/param.rs | pub fn get(&self, key: Param) -> Option<&str> {
self.inner.get(&key).map(|s| s.as_str())
} | pub struct Params {
inner: BTreeMap<Param, String>,
} | use std::collections::BTreeMap;
use std::fmt;
use std::path::PathBuf;
use std::str;
use anyhow::{bail, Error, Result};
use num_traits::FromPrimitive;
use serde::{Deserialize, Serialize};
use crate::blob::BlobObject;
use crate::context::Context;
use crate::mimeparser::SystemMessage;
use std::path::Path;
use std::str::Fr... | projects__deltachat-core__rust__param__.rs__function__4.txt |
projects/deltachat-core/c/dc_oauth2.c | static void replace_in_uri(char** uri, const char* key, const char* value)
{
if (uri && key && value) {
char* value_urlencoded = dc_urlencode(value);
dc_str_replace(uri, key, value_urlencoded);
free(value_urlencoded);
}
} | projects/deltachat-core/rust/oauth2.rs | fn replace_in_uri(uri: &str, key: &str, value: &str) -> String {
let value_urlencoded = utf8_percent_encode(value, NON_ALPHANUMERIC).to_string();
uri.replace(key, &value_urlencoded)
} | use std::collections::HashMap;
use anyhow::Result;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use serde::Deserialize;
use crate::config::Config;
use crate::context::Context;
use crate::provider;
use crate::provider::Oauth2Authorizer;
use crate::socks::Socks5Config;
use crate::tools::time;
use super:... | projects__deltachat-core__rust__oauth2__.rs__function__7.txt | |
projects/deltachat-core/c/dc_msg.c | uint32_t dc_msg_get_id(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
return msg->id;
} | projects/deltachat-core/rust/message.rs | pub fn get_id(&self) -> MsgId {
self.id
} | pub struct MsgId(u32);
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
pub(crate) to_id: ContactId,
/// ID of the chat message belongs to.
pub(crate) chat_id: ChatId,
... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__30.txt |
projects/deltachat-core/c/dc_chat.c | int dc_get_msg_cnt(dc_context_t* context, uint32_t chat_id)
{
int ret = 0;
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
stmt = dc_sqlite3_prepare(context->sql,
"SELECT COUNT(*) FROM msgs WHERE chat_id=?;");
sqlite3_bind_int(stmt, 1, chat_id);
... | projects/deltachat-core/rust/chat.rs | pub async fn get_msg_cnt(self, context: &Context) -> Result<usize> {
let count = context
.sql
.count(
"SELECT COUNT(*) FROM msgs WHERE hidden=0 AND chat_id=?",
(self,),
)
.await?;
Ok(count)
} | pub async fn count(&self, query: &str, params: impl rusqlite::Params + Send) -> Result<usize> {
let count: isize = self.query_row(query, params, |row| row.get(0)).await?;
Ok(usize::try_from(count)?)
}
pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
pub struct InnerContext {
///... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__36.txt |
projects/deltachat-core/c/dc_configure.c | static int get_folder_meaning_by_name(const char* folder_name)
{
// try to get the folder meaning by the name of the folder.
// only used if the server does not support XLIST.
int ret_meaning = MEANING_UNKNOWN;
// TODO: lots languages missing - maybe there is a list somewhere on other MUAs?
// however, if we fail... | projects/deltachat-core/rust/imap.rs | fn get_folder_meaning_by_name(folder_name: &str) -> FolderMeaning {
// source: <https://stackoverflow.com/questions/2185391/localized-gmail-imap-folders>
const SENT_NAMES: &[&str] = &[
"sent",
"sentmail",
"sent objects",
"gesendet",
"Sent Mail",
"Sendte e-mails",
... | pub enum FolderMeaning {
Unknown,
/// Spam folder.
Spam,
Inbox,
Mvbox,
Sent,
Trash,
Drafts,
/// Virtual folders.
///
/// On Gmail there are virtual folders marked as \\All, \\Important and \\Flagged.
/// Delta Chat ignores these folders because the same messages can be ... | use std::{
cmp::max,
cmp::min,
collections::{BTreeMap, BTreeSet, HashMap},
iter::Peekable,
mem::take,
sync::atomic::Ordering,
time::{Duration, UNIX_EPOCH},
};
use anyhow::{bail, format_err, Context as _, Result};
use async_channel::Receiver;
use async_imap::types::{Fetch, Flag, Name, NameAtt... | projects__deltachat-core__rust__imap__.rs__function__32.txt |
projects/deltachat-core/c/dc_chat.c | char* dc_chat_get_name(const dc_chat_t* chat)
{
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
return dc_strdup("Err");
}
return dc_strdup(chat->name);
} | projects/deltachat-core/rust/chat.rs | pub fn get_name(&self) -> &str {
&self.name
} | pub struct Chat {
/// Database ID.
pub id: ChatId,
/// Chat type, e.g. 1:1 chat, group chat, mailing list.
pub typ: Chattype,
/// Chat name.
pub name: String,
/// Whether the chat is archived or pinned.
pub visibility: ChatVisibility,
/// Group ID. For [`Chattype::Mailinglist`] -... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__71.txt |
projects/deltachat-core/c/dc_chat.c | int dc_get_fresh_msg_cnt(dc_context_t* context, uint32_t chat_id)
{
int ret = 0;
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
if (chat_id == DC_CHAT_ID_ARCHIVED_LINK){
stmt = dc_sqlite3_prepare(context->sql,
"SELECT COUNT... | projects/deltachat-core/rust/chat.rs | pub async fn get_fresh_msg_cnt(self, context: &Context) -> Result<usize> {
// this function is typically used to show a badge counter beside _each_ chatlist item.
// to make this as fast as possible, esp. on older devices, we added an combined index over the rows used for querying.
// so if you ... | pub async fn count(&self, query: &str, params: impl rusqlite::Params + Send) -> Result<usize> {
let count: isize = self.query_row(query, params, |row| row.get(0)).await?;
Ok(usize::try_from(count)?)
}
pub fn is_archived_link(self) -> bool {
self == DC_CHAT_ID_ARCHIVED_LINK
}
pub struct... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__37.txt |
projects/deltachat-core/c/dc_apeerstate.c | void dc_apeerstate_apply_header(dc_apeerstate_t* peerstate, const dc_aheader_t* header, time_t message_time)
{
if (peerstate==NULL || header==NULL
|| peerstate->addr==NULL
|| header->addr==NULL || header->public_key->binary==NULL
|| strcasecmp(peerstate->addr, header->addr)!=0) {
return;
}
if (message_time ... | projects/deltachat-core/rust/peerstate.rs | pub fn apply_header(&mut self, header: &Aheader, message_time: i64) {
if !addr_cmp(&self.addr, &header.addr) {
return;
}
if message_time >= self.last_seen {
self.last_seen = message_time;
self.last_seen_autocrypt = message_time;
if (header.prefer_... | pub fn recalc_fingerprint(&mut self) {
if let Some(ref public_key) = self.public_key {
let old_public_fingerprint = self.public_key_fingerprint.take();
self.public_key_fingerprint = Some(public_key.fingerprint());
if old_public_fingerprint.is_some()
&& old_pu... | use std::mem;
use anyhow::{Context as _, Error, Result};
use deltachat_contact_tools::{addr_cmp, ContactAddress};
use num_traits::FromPrimitive;
use crate::aheader::{Aheader, EncryptPreference};
use crate::chat::{self, Chat};
use crate::chatlist::Chatlist;
use crate::config::Config;
use crate::constants::Chattype;
use ... | projects__deltachat-core__rust__peerstate__.rs__function__10.txt |
projects/deltachat-core/c/dc_param.c | void dc_param_set(dc_param_t* param, int key, const char* value)
{
char* old1 = NULL;
char* old2 = NULL;
char* new1 = NULL;
if (param==NULL || key==0) {
return;
}
old1 = param->packed;
old2 = NULL;
/* remove existing parameter from packed string, if any */
if (old1) {
char *p1, *p2;
p1 = find_param(ol... | projects/deltachat-core/rust/param.rs | pub fn set(&mut self, key: Param, value: impl ToString) -> &mut Self {
self.inner.insert(key, value.to_string());
self
} | pub struct Params {
inner: BTreeMap<Param, String>,
} | use std::collections::BTreeMap;
use std::fmt;
use std::path::PathBuf;
use std::str;
use anyhow::{bail, Error, Result};
use num_traits::FromPrimitive;
use serde::{Deserialize, Serialize};
use crate::blob::BlobObject;
use crate::context::Context;
use crate::mimeparser::SystemMessage;
use std::path::Path;
use std::str::Fr... | projects__deltachat-core__rust__param__.rs__function__6.txt |
projects/deltachat-core/c/dc_sqlite3.c | int dc_sqlite3_table_exists(dc_sqlite3_t* sql, const char* name)
{
int ret = 0;
char* querystr = NULL;
sqlite3_stmt* stmt = NULL;
int sqlState = 0;
if ((querystr=sqlite3_mprintf("PRAGMA table_info(%s)", name))==NULL) { /* this statement cannot be used with binded variables */
dc_log_... | projects/deltachat-core/rust/sql.rs | pub async fn table_exists(&self, name: &str) -> Result<bool> {
self.call(move |conn| {
let mut exists = false;
conn.pragma(None, "table_info", name.to_string(), |_row| {
// will only be executed if the info was found
exists = true;
Ok(())
... | async fn call<'a, F, R>(&'a self, function: F) -> Result<R>
where
F: 'a + FnOnce(&mut Connection) -> Result<R> + Send,
R: Send + 'static,
{
let lock = self.pool.read().await;
let pool = lock.as_ref().context("no SQL connection")?;
let mut conn = pool.get().await?;
... | use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use anyhow::{bail, Context as _, Result};
use rusqlite::{config::DbConfig, types::ValueRef, Connection, OpenFlags, Row};
use tokio::sync::{Mutex, MutexGuard, RwLock};
use crate::blob::BlobObject;
use crate::chat::{self, add_device_msg, update_dev... | projects__deltachat-core__rust__sql__.rs__function__23.txt |
projects/deltachat-core/c/dc_chat.c | void dc_forward_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt, uint32_t chat_id)
{
dc_msg_t* msg = dc_msg_new_untyped(context);
dc_chat_t* chat = dc_chat_new(context);
dc_contact_t* contact = dc_contact_new(context);
int transaction_pending = 0;
carray* created_db_ent... | projects/deltachat-core/rust/chat.rs | pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId) -> Result<()> {
ensure!(!msg_ids.is_empty(), "empty msgs_ids: nothing to forward");
ensure!(!chat_id.is_special(), "can not forward to special chat");
let mut created_chats: Vec<ChatId> = Vec::new();
let mut created_msgs: ... | pub(crate) async fn update_param(&mut self, context: &Context) -> Result<()> {
context
.sql
.execute(
"UPDATE chats SET param=? WHERE id=?",
(self.param.to_string(), self.id),
)
.await?;
Ok(())
}
pub fn get_viewtype(&se... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__139.txt |
projects/deltachat-core/c/dc_contact.c | int dc_delete_contact(dc_context_t* context, uint32_t contact_id)
{
int success = 0;
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || contact_id<=DC_CONTACT_ID_LAST_SPECIAL) {
goto cleanup;
}
/* we can only delete contacts that are not in use anywhere; this function... | projects/deltachat-core/rust/contact.rs | pub async fn delete(context: &Context, contact_id: ContactId) -> Result<()> {
ensure!(!contact_id.is_special(), "Can not delete special contact");
context
.sql
.transaction(move |transaction| {
// make sure, the transaction starts with a write command and becomes... | pub fn emit_event(&self, event: EventType) {
{
let lock = self.debug_logging.read().expect("RwLock is poisoned");
if let Some(debug_logging) = &*lock {
debug_logging.log_event(event.clone());
}
}
self.events.emit(Event {
id: self.id... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__33.txt |
projects/deltachat-core/c/dc_chat.c | * After the creation with dc_create_group_chat() the chat is usually unpromoted
* until the first call to dc_send_text_msg() or another sending function.
*
* With unpromoted chats, members can be added
* and settings can be modified without the need of special status messages being sent.
*
* While the core takes ... | projects/deltachat-core/rust/chat.rs | pub(crate) async fn is_unpromoted(self, context: &Context) -> Result<bool> {
let param = self.get_param(context).await?;
let unpromoted = param.get_bool(Param::Unpromoted).unwrap_or_default();
Ok(unpromoted)
} | pub fn get_bool(&self, key: Param) -> Option<bool> {
self.get_int(key).map(|v| v != 0)
}
pub(crate) async fn get_param(self, context: &Context) -> Result<Params> {
let res: Option<String> = context
.sql
.query_get_value("SELECT param FROM chats WHERE id=?", (self,))
... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__42.txt |
projects/deltachat-core/c/dc_chat.c | * If the group is already _promoted_ (any message was sent to the group),
* all group members are informed by a special status message that is sent automatically by this function.
*
* Sends out #DC_EVENT_CHAT_MODIFIED and #DC_EVENT_MSGS_CHANGED if a status message was sent.
*
* @memberof dc_context_t
* @param cha... | projects/deltachat-core/rust/chat.rs | pub async fn set_chat_name(context: &Context, chat_id: ChatId, new_name: &str) -> Result<()> {
rename_ex(context, Sync, chat_id, new_name).await
} | async fn rename_ex(
context: &Context,
mut sync: sync::Sync,
chat_id: ChatId,
new_name: &str,
) -> Result<()> {
let new_name = improve_single_line_input(new_name);
/* the function only sets the names of group chats; normal chats get their names from the contacts */
let mut success = false;
... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__136.txt |
projects/deltachat-core/c/dc_chat.c | * See dc_set_draft() for more details about drafts.
*
* @memberof dc_context_t
* @param context The context as created by dc_context_new().
* @param chat_id The chat ID to get the draft for.
* @return Message object.
* Can be passed directly to dc_send_msg().
* Must be freed using dc_msg_unref() after us... | projects/deltachat-core/rust/chat.rs | pub async fn get_draft(self, context: &Context) -> Result<Option<Message>> {
if self.is_special() {
return Ok(None);
}
match self.get_draft_msg_id(context).await? {
Some(draft_msg_id) => {
let msg = Message::load_from_db(context, draft_msg_id).await?;
... | async fn get_draft_msg_id(self, context: &Context) -> Result<Option<MsgId>> {
let msg_id: Option<MsgId> = context
.sql
.query_get_value(
"SELECT id FROM msgs WHERE chat_id=? AND state=?;",
(self, MessageState::OutDraft),
)
.await?;
... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__33.txt |
projects/deltachat-core/c/dc_contact.c | * using dc_set_config(context, "selfavatar", image).
*
* @memberof dc_contact_t
* @param contact The contact object.
* @return Path and file if the profile image, if any.
* NULL otherwise.
* Must be free()'d after usage.
*/
char* dc_contact_get_profile_image(const dc_contact_t* contact)
{
char* selfavat... | projects/deltachat-core/rust/contact.rs | pub async fn get_profile_image(&self, context: &Context) -> Result<Option<PathBuf>> {
if self.id == ContactId::SELF {
if let Some(p) = context.get_config(Config::Selfavatar).await? {
return Ok(Some(PathBuf::from(p)));
}
} else if let Some(image_rel) = self.param.g... | pub fn get(&self, key: Param) -> Option<&str> {
self.inner.get(&key).map(|s| s.as_str())
}
pub async fn get_config(&self, key: Config) -> Result<Option<String>> {
let env_key = format!("DELTACHAT_{}", key.as_ref().to_uppercase());
if let Ok(value) = env::var(env_key) {
return Ok... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__43.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_is_increation(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->context==NULL) {
return 0;
}
return DC_MSG_NEEDS_ATTACHMENT(msg->type) && msg->state==DC_STATE_OUT_PREPARING;
} | projects/deltachat-core/rust/message.rs | pub fn is_increation(&self) -> bool {
self.viewtype.has_file() && self.state == MessageState::OutPreparing
} | pub fn has_file(&self) -> bool {
match self {
Viewtype::Unknown => false,
Viewtype::Text => false,
Viewtype::Image => true,
Viewtype::Gif => true,
Viewtype::Sticker => true,
Viewtype::Audio => true,
Viewtype::Voice => true,
... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__59.txt |
projects/deltachat-core/c/dc_location.c | char* dc_get_message_kml(dc_context_t* context, time_t timestamp, double latitude, double longitude)
{
char* timestamp_str = NULL;
char* latitude_str = NULL;
char* longitude_str = NULL;
char* ret = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
timestamp_str = get_kml_time... | projects/deltachat-core/rust/location.rs | pub fn get_message_kml(timestamp: i64, latitude: f64, longitude: f64) -> String {
format!(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n\
<Document>\n\
<Placemark>\
<Timestamp><when>{}</when></Timestamp>\
<Point><... | use std::time::Duration;
use anyhow::{ensure, Context as _, Result};
use async_channel::Receiver;
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
use tokio::time::timeout;
use crate::chat::{self, ChatId};
use crate::constants::DC_CHAT_ID_TRASH;
use crate::contact::ContactId;
use crate::context::Context;
use c... | projects__deltachat-core__rust__location__.rs__function__18.txt | |
projects/deltachat-core/c/dc_location.c | void dc_send_locations_to_chat(dc_context_t* context, uint32_t chat_id,
int seconds)
{
sqlite3_stmt* stmt = NULL;
time_t now = time(NULL);
dc_msg_t* msg = NULL;
char* stock_str = NULL;
int is_sending_locations_before = 0;
if (context==NULL || context->m... | projects/deltachat-core/rust/location.rs | pub async fn send_locations_to_chat(
context: &Context,
chat_id: ChatId,
seconds: i64,
) -> Result<()> {
ensure!(seconds >= 0);
ensure!(!chat_id.is_special());
let now = time();
let is_sending_locations_before = is_sending_locations_to_chat(context, Some(chat_id)).await?;
context
... | pub fn emit_event(&self, event: EventType) {
{
let lock = self.debug_logging.read().expect("RwLock is poisoned");
if let Some(debug_logging) = &*lock {
debug_logging.log_event(event.clone());
}
}
self.events.emit(Event {
id: self.id... | use std::time::Duration;
use anyhow::{ensure, Context as _, Result};
use async_channel::Receiver;
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
use tokio::time::timeout;
use crate::chat::{self, ChatId};
use crate::constants::DC_CHAT_ID_TRASH;
use crate::contact::ContactId;
use crate::context::Context;
use c... | projects__deltachat-core__rust__location__.rs__function__7.txt |
projects/deltachat-core/c/dc_location.c | dc_array_t* dc_get_locations(dc_context_t* context,
uint32_t chat_id, uint32_t contact_id,
time_t timestamp_from, time_t timestamp_to)
{
dc_array_t* ret = dc_array_new_typed(context, DC_ARRAY_LOCATIONS, 500);
sqlite3_stmt* stmt = NULL;
if (context==NULL |... | projects/deltachat-core/rust/location.rs | pub async fn get_range(
context: &Context,
chat_id: Option<ChatId>,
contact_id: Option<u32>,
timestamp_from: i64,
mut timestamp_to: i64,
) -> Result<Vec<Location>> {
if timestamp_to == 0 {
timestamp_to = time() + 10;
}
let (disable_chat_id, chat_id) = match chat_id {
Som... | fn is_marker(txt: &str) -> bool {
let mut chars = txt.chars();
if let Some(c) = chars.next() {
!c.is_whitespace() && chars.next().is_none()
} else {
false
}
}
pub(crate) fn time() -> i64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()... | use std::time::Duration;
use anyhow::{ensure, Context as _, Result};
use async_channel::Receiver;
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
use tokio::time::timeout;
use crate::chat::{self, ChatId};
use crate::constants::DC_CHAT_ID_TRASH;
use crate::contact::ContactId;
use crate::context::Context;
use c... | projects__deltachat-core__rust__location__.rs__function__10.txt |
projects/deltachat-core/c/dc_location.c | static int is_marker(const char* txt)
{
if (txt) {
int len = dc_utf8_strlen(txt);
if (len==1 && !isspace(txt[0])) {
return 1;
}
}
return 0;
} | projects/deltachat-core/rust/location.rs | fn is_marker(txt: &str) -> bool {
let mut chars = txt.chars();
if let Some(c) = chars.next() {
!c.is_whitespace() && chars.next().is_none()
} else {
false
}
} | use std::time::Duration;
use anyhow::{ensure, Context as _, Result};
use async_channel::Receiver;
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
use tokio::time::timeout;
use crate::chat::{self, ChatId};
use crate::constants::DC_CHAT_ID_TRASH;
use crate::contact::ContactId;
use crate::context::Context;
use c... | projects__deltachat-core__rust__location__.rs__function__11.txt | |
projects/deltachat-core/c/dc_configure.c | * function not under the control of the core (eg. #DC_EVENT_HTTP_GET). Another
* reason for dc_stop_ongoing_process() not to wait is that otherwise it
* would be GUI-blocking and should be started in another thread then; this
* would make things even more complicated.
*
* Typical ongoing processes are started by d... | projects/deltachat-core/rust/context.rs | pub async fn stop_ongoing(&self) {
let mut s = self.running_state.write().await;
match &*s {
RunningState::Running { cancel_sender } => {
if let Err(err) = cancel_sender.send(()).await {
warn!(self, "could not cancel ongoing: {:#}", err);
}... | macro_rules! info {
($ctx:expr, $msg:expr) => {
info!($ctx, $msg,)
};
($ctx:expr, $msg:expr, $($args:expr),* $(,)?) => {{
let formatted = format!($msg, $($args),*);
let full = format!("{file}:{line}: {msg}",
file = file!(),
line ... | use std::collections::{BTreeMap, HashMap};
use std::ffi::OsString;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
us... | projects__deltachat-core__rust__context__.rs__function__39.txt |
projects/deltachat-core/c/dc_msg.c | void dc_msg_set_location(dc_msg_t* msg, double latitude, double longitude)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || (latitude==0.0 && longitude==0.0)) {
return;
}
dc_param_set_float(msg->param, DC_PARAM_SET_LATITUDE, latitude);
dc_param_set_float(msg->param, DC_PARAM_SET_LONGITUDE, longitude);
} | projects/deltachat-core/rust/message.rs | pub fn set_location(&mut self, latitude: f64, longitude: f64) {
if latitude == 0.0 && longitude == 0.0 {
return;
}
self.param.set_float(Param::SetLatitude, latitude);
self.param.set_float(Param::SetLongitude, longitude);
} | pub fn set_float(&mut self, key: Param, value: f64) -> &mut Self {
self.set(key, format!("{value}"));
self
}
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
p... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__28.txt |
projects/deltachat-core/c/dc_contact.c | void dc_block_contact(dc_context_t* context, uint32_t contact_id, int new_blocking)
{
int send_event = 0;
dc_contact_t* contact = dc_contact_new(context);
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || contact_id<=DC_CONTACT_ID_LAST_SPECIAL) {
goto cleanup;
}
if... | projects/deltachat-core/rust/contact.rs | pub async fn block(context: &Context, id: ContactId) -> Result<()> {
set_blocked(context, Sync, id, true).await
} | pub(crate) async fn set_blocked(
context: &Context,
sync: sync::Sync,
contact_id: ContactId,
new_blocking: bool,
) -> Result<()> {
ensure!(
!contact_id.is_special(),
"Can't block special contact {}",
contact_id
);
let contact = Contact::get_by_id(context, contact_id).... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__18.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_get_showpadlock(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->context==NULL) {
return 0;
}
if (dc_param_get_int(msg->param, DC_PARAM_GUARANTEE_E2EE, 0)!=0) {
return 1;
}
return 0;
} | projects/deltachat-core/rust/message.rs | pub fn get_showpadlock(&self) -> bool {
self.param.get_int(Param::GuaranteeE2ee).unwrap_or_default() != 0
} | pub fn get_int(&self, key: Param) -> Option<i32> {
self.get(key).and_then(|s| s.parse().ok())
}
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
pub(crate) to_id: Cont... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__46.txt |
projects/deltachat-core/c/dc_location.c | int dc_set_location(dc_context_t* context,
double latitude, double longitude, double accuracy)
{
sqlite3_stmt* stmt_chats = NULL;
sqlite3_stmt* stmt_insert = NULL;
int continue_streaming = 0;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC
|| (latitude==0.0 && longitude==0.0))... | projects/deltachat-core/rust/location.rs | pub async fn set(context: &Context, latitude: f64, longitude: f64, accuracy: f64) -> Result<bool> {
if latitude == 0.0 && longitude == 0.0 {
return Ok(true);
}
let mut continue_streaming = false;
let now = time();
let chats = context
.sql
.query_map(
"SELECT id F... | pub(crate) fn time() -> i64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64
}
pub async fn query_map<T, F, G, H>(
&self,
sql: &str,
params: impl rusqlite::Params + Send,
f: F,
mut g: G,
) -> Resul... | use std::time::Duration;
use anyhow::{ensure, Context as _, Result};
use async_channel::Receiver;
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
use tokio::time::timeout;
use crate::chat::{self, ChatId};
use crate::constants::DC_CHAT_ID_TRASH;
use crate::contact::ContactId;
use crate::context::Context;
use c... | projects__deltachat-core__rust__location__.rs__function__9.txt |
projects/deltachat-core/c/dc_msg.c | void dc_msg_guess_msgtype_from_suffix(const char* pathNfilename, int* ret_msgtype, char** ret_mime)
{
char* suffix = NULL;
int dummy_msgtype = 0;
char* dummy_buf = NULL;
if (pathNfilename==NULL) {
goto cleanup;
}
if (ret_msgtype==NULL) { ret_msgtype = &dummy_msgtype; }
if (ret_mime==NULL) { ret_mime = &... | projects/deltachat-core/rust/message.rs | pub(crate) fn guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {
let extension: &str = &path.extension()?.to_str()?.to_lowercase();
let info = match extension {
// before using viewtype other than Viewtype::File,
// make sure, all target UIs support that type in the context of ... | pub enum Viewtype {
/// Unknown message type.
#[default]
Unknown = 0,
/// Text message.
/// The text of the message is set using dc_msg_set_text() and retrieved with dc_msg_get_text().
Text = 10,
/// Image message.
/// If the image is a GIF and has the appropriate extension, the viewty... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__87.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_is_forwarded(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
return dc_param_get_int(msg->param, DC_PARAM_FORWARDED, 0)? 1 : 0;
} | projects/deltachat-core/rust/message.rs | pub fn is_forwarded(&self) -> bool {
0 != self.param.get_int(Param::Forwarded).unwrap_or_default()
} | pub fn get_int(&self, key: Param) -> Option<i32> {
self.get(key).and_then(|s| s.parse().ok())
}
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
pub(crate) to_id: Cont... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__55.txt |
projects/deltachat-core/c/dc_sqlite3.c | static void maybe_add_file(dc_hash_t* files_in_use, const char* file)
{
#define PREFIX "$BLOBDIR/"
#define PREFIX_LEN 9
if (strncmp(file, PREFIX, PREFIX_LEN)!=0) {
return;
}
const char* raw_name = &file[PREFIX_LEN];
dc_hash_insert_str(files_in_use, raw_name, (void*)1);
} | projects/deltachat-core/rust/sql.rs | fn maybe_add_file(files_in_use: &mut HashSet<String>, file: &str) {
if let Some(file) = file.strip_prefix("$BLOBDIR/") {
files_in_use.insert(file.to_string());
}
} | use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use anyhow::{bail, Context as _, Result};
use rusqlite::{config::DbConfig, types::ValueRef, Connection, OpenFlags, Row};
use tokio::sync::{Mutex, MutexGuard, RwLock};
use crate::blob::BlobObject;
use crate::chat::{self, add_device_msg, update_dev... | projects__deltachat-core__rust__sql__.rs__function__42.txt | |
projects/deltachat-core/c/dc_tools.c | time_t dc_smeared_time(dc_context_t* context)
{
/* function returns a corrected time(NULL) */
time_t now = time(NULL);
SMEAR_LOCK
if (context->last_smeared_timestamp >= now) {
now = context->last_smeared_timestamp+1;
}
SMEAR_UNLOCK
return now;
} | projects/deltachat-core/rust/tools.rs | pub(crate) fn smeared_time(context: &Context) -> i64 {
let now = time();
let ts = context.smeared_timestamp.current();
std::cmp::max(ts, now)
} | pub(crate) fn time() -> i64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64
}
pub fn current(&self) -> i64 {
self.smeared_timestamp.load(Ordering::Relaxed)
}
pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
... | use std::borrow::Cow;
use std::io::{Cursor, Write};
use std::mem;
use std::path::{Path, PathBuf};
use std::str::from_utf8;
use std::time::Duration;
use std::time::SystemTime as Time;
use std::time::SystemTime;
use anyhow::{bail, Context as _, Result};
use base64::Engine as _;
use chrono::{Local, NaiveDateTime, NaiveTim... | projects__deltachat-core__rust__tools__.rs__function__6.txt |
projects/deltachat-core/c/dc_oauth2.c | char* dc_get_oauth2_access_token(dc_context_t* context, const char* addr,
const char* code, int flags)
{
oauth2_t* oauth2 = NULL;
char* access_token = NULL;
char* refresh_token = NULL;
char* refresh_token_for = NULL;
char* redirect_uri = NULL;
int ... | projects/deltachat-core/rust/oauth2.rs | pub(crate) async fn get_oauth2_access_token(
context: &Context,
addr: &str,
code: &str,
regenerate: bool,
) -> Result<Option<String>> {
let socks5_enabled = context.get_config_bool(Config::Socks5Enabled).await?;
if let Some(oauth2) = Oauth2::from_address(context, addr, socks5_enabled).await {
... | pub async fn get_config_bool(&self, key: Config) -> Result<bool> {
Ok(self.get_config_bool_opt(key).await?.unwrap_or_default())
}
pub(crate) fn time() -> i64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64
}
pub async fn get_ra... | use std::collections::HashMap;
use anyhow::Result;
use percent_encoding::{utf8_percent_encode, NON_ALPHANUMERIC};
use serde::Deserialize;
use crate::config::Config;
use crate::context::Context;
use crate::provider;
use crate::provider::Oauth2Authorizer;
use crate::socks::Socks5Config;
use crate::tools::time;
use super:... | projects__deltachat-core__rust__oauth2__.rs__function__2.txt |
projects/deltachat-core/c/dc_chat.c | int dc_chat_get_type(const dc_chat_t* chat)
{
if (chat==NULL || chat->magic!=DC_CHAT_MAGIC) {
return DC_CHAT_TYPE_UNDEFINED;
}
return chat->type;
} | projects/deltachat-core/rust/chat.rs | pub fn get_type(&self) -> Chattype {
self.typ
} | pub struct Chat {
/// Database ID.
pub id: ChatId,
/// Chat type, e.g. 1:1 chat, group chat, mailing list.
pub typ: Chattype,
/// Chat name.
pub name: String,
/// Whether the chat is archived or pinned.
pub visibility: ChatVisibility,
/// Group ID. For [`Chattype::Mailinglist`] -... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__70.txt |
projects/deltachat-core/c/dc_imex.c | char* dc_decrypt_setup_file(dc_context_t* context, const char* passphrase, const char* filecontent)
{
char* binary = NULL;
size_t binary_bytes = 0;
size_t indx = 0;
void* plain = NULL;
size_t plain_bytes = 0;
char* payload = NULL;
/* decrypt symmetrically */
if (!dc... | projects/deltachat-core/rust/imex.rs | async fn decrypt_setup_file<T: std::io::Read + std::io::Seek>(
passphrase: &str,
file: T,
) -> Result<String> {
let plain_bytes = pgp::symm_decrypt(passphrase, file).await?;
let plain_text = std::string::String::from_utf8(plain_bytes)?;
Ok(plain_text)
} | pub async fn symm_decrypt<T: std::io::Read + std::io::Seek>(
passphrase: &str,
ctext: T,
) -> Result<Vec<u8>> {
let (enc_msg, _) = Message::from_armor_single(ctext)?;
let passphrase = passphrase.to_string();
tokio::task::spawn_blocking(move || {
let decryptor = enc_msg.decrypt_with_password... | use std::any::Any;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use deltachat_contact_tools::EmailAddress;
use futures::StreamExt;
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
use ... | projects__deltachat-core__rust__imex__.rs__function__9.txt |
projects/deltachat-core/c/dc_imex.c | char* dc_normalize_setup_code(dc_context_t* context, const char* in)
{
if (in==NULL) {
return NULL;
}
dc_strbuilder_t out;
dc_strbuilder_init(&out, 0);
int outlen = 0;
const char* p1 = in;
while (*p1) {
if (*p1 >= '0' && *p1 <= '9') {
dc_strbuilder_catf(&out, "%c", *p1);
outlen = strlen(out.buf);
... | projects/deltachat-core/rust/imex.rs | fn normalize_setup_code(s: &str) -> String {
let mut out = String::new();
for c in s.chars() {
if c.is_ascii_digit() {
out.push(c);
if let 4 | 9 | 14 | 19 | 24 | 29 | 34 | 39 = out.len() {
out += "-"
}
}
}
out
} | use std::any::Any;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use deltachat_contact_tools::EmailAddress;
use futures::StreamExt;
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
use ... | projects__deltachat-core__rust__imex__.rs__function__10.txt | |
projects/deltachat-core/c/dc_aheader.c | int dc_aheader_set_from_string(dc_aheader_t* aheader, const char* header_str__)
{
/* according to RFC 5322 (Internet Message Format), the given string may contain `\r\n` before any whitespace.
we can ignore this issue as
(a) no key or value is expected to contain spaces,
(b) for the key, non-base64-characters are i... | projects/deltachat-core/rust/aheader.rs | fn from_str(s: &str) -> Result<Self> {
let mut attributes: BTreeMap<String, String> = s
.split(';')
.filter_map(|a| {
let attribute: Vec<&str> = a.trim().splitn(2, '=').collect();
match &attribute[..] {
[key, value] => Some((key.trim().... | pub struct Aheader {
pub addr: String,
pub public_key: SignedPublicKey,
pub prefer_encrypt: EncryptPreference,
}
fn from_base64(data: &str) -> Result<Self> {
// strip newlines and other whitespace
let cleaned: String = data.split_whitespace().collect();
let bytes = base64::engine::g... | use std::collections::BTreeMap;
use std::fmt;
use std::str::FromStr;
use anyhow::{bail, Context as _, Error, Result};
use crate::key::{DcKey, SignedPublicKey};
use super::*; | projects__deltachat-core__rust__aheader__.rs__function__5.txt |
projects/deltachat-core/c/dc_param.c | dc_param_t* dc_param_new()
{
dc_param_t* param = NULL;
if ((param=calloc(1, sizeof(dc_param_t)))==NULL) {
exit(28); /* cannot allocate little memory, unrecoverable error */
}
param->packed = calloc(1, 1);
return param;
} | projects/deltachat-core/rust/param.rs | pub fn new() -> Self {
Default::default()
} | pub struct Params {
inner: BTreeMap<Param, String>,
} | use std::collections::BTreeMap;
use std::fmt;
use std::path::PathBuf;
use std::str;
use anyhow::{bail, Error, Result};
use num_traits::FromPrimitive;
use serde::{Deserialize, Serialize};
use crate::blob::BlobObject;
use crate::context::Context;
use crate::mimeparser::SystemMessage;
use std::path::Path;
use std::str::Fr... | projects__deltachat-core__rust__param__.rs__function__3.txt |
projects/deltachat-core/c/dc_contact.c | int dc_contact_is_blocked(const dc_contact_t* contact)
{
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
return 0;
}
return contact->blocked;
} | projects/deltachat-core/rust/contact.rs | pub fn is_blocked(&self) -> bool {
self.blocked
} | pub struct Contact {
/// The contact ID.
pub id: ContactId,
/// Contact name. It is recommended to use `Contact::get_name`,
/// `Contact::get_display_name` or `Contact::get_name_n_addr` to access this field.
/// May be empty, initially set to `authname`.
name: String,
/// Name authorized b... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__14.txt |
projects/deltachat-core/c/dc_context.c | dc_array_t* dc_get_fresh_msgs(dc_context_t* context)
{
int show_deaddrop = 0;
dc_array_t* ret = dc_array_new(context, 128);
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || ret==NULL) {
goto cleanup;
}
stmt = dc_sqlite3_prepare(context->sql,
"SELECT m.id"
" F... | projects/deltachat-core/rust/context.rs | pub async fn get_fresh_msgs(&self) -> Result<Vec<MsgId>> {
let list = self
.sql
.query_map(
concat!(
"SELECT m.id",
" FROM msgs m",
" LEFT JOIN contacts ct",
" ON m.from_id=ct.id",
... | pub(crate) fn time() -> i64 {
SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs() as i64
}
pub async fn query_map<T, F, G, H>(
&self,
sql: &str,
params: impl rusqlite::Params + Send,
f: F,
mut g: G,
) -> Resul... | use std::collections::{BTreeMap, HashMap};
use std::ffi::OsString;
use std::ops::Deref;
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
us... | projects__deltachat-core__rust__context__.rs__function__44.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_is_setupmessage(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC || msg->type!=DC_MSG_FILE) {
return 0;
}
return dc_param_get_int(msg->param, DC_PARAM_CMD, 0)==DC_CMD_AUTOCRYPT_SETUP_MESSAGE? 1 : 0;
} | projects/deltachat-core/rust/message.rs | pub fn is_setupmessage(&self) -> bool {
if self.viewtype != Viewtype::File {
return false;
}
self.param.get_cmd() == SystemMessage::AutocryptSetupMessage
} | pub fn get_cmd(&self) -> SystemMessage {
self.get_int(Param::Cmd)
.and_then(SystemMessage::from_i32)
.unwrap_or_default()
}
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first con... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__60.txt |
projects/deltachat-core/c/dc_contact.c | dc_array_t* dc_get_contacts(dc_context_t* context, uint32_t listflags, const char* query)
{
char* self_addr = NULL;
char* self_name = NULL;
char* self_name2 = NULL;
int add_self = 0;
dc_array_t* ret = dc_array_new(context, 100);
char* s3strLikeCmd = NULL;
sqlite3_stmt*... | projects/deltachat-core/rust/contact.rs | pub async fn get_all(
context: &Context,
listflags: u32,
query: Option<&str>,
) -> Result<Vec<ContactId>> {
let self_addrs = context.get_all_self_addrs().await?;
let mut add_self = false;
let mut ret = Vec::new();
let flag_verified_only = (listflags & DC_GCL_V... | pub async fn get_config_bool(&self, key: Config) -> Result<bool> {
Ok(self.get_config_bool_opt(key).await?.unwrap_or_default())
}
macro_rules! params_slice {
($($param:expr),+) => {
[$(&$param as &dyn $crate::sql::ToSql),+]
};
}
pub(crate) fn params_iter(
iter: &[impl crate::sql::ToSql... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__28.txt |
projects/deltachat-core/c/dc_chat.c | dc_array_t* dc_get_chat_contacts(dc_context_t* context, uint32_t chat_id)
{
/* Normal chats do not include SELF. Group chats do (as it may happen that one is deleted from a
groupchat but the chats stays visible, moreover, this makes displaying lists easier) */
dc_array_t* ret = dc_array_new(context, 100);
sqlite... | projects/deltachat-core/rust/chat.rs | pub async fn get_chat_contacts(context: &Context, chat_id: ChatId) -> Result<Vec<ContactId>> {
// Normal chats do not include SELF. Group chats do (as it may happen that one is deleted from a
// groupchat but the chats stays visible, moreover, this makes displaying lists easier)
let list = context
... | pub struct Context {
pub(crate) inner: Arc<InnerContext>,
}
pub struct InnerContext {
/// Blob directory path
pub(crate) blobdir: PathBuf,
pub(crate) sql: Sql,
pub(crate) smeared_timestamp: SmearedTimestamp,
/// The global "ongoing" process state.
///
/// This is a global mutex-like sta... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__118.txt |
projects/deltachat-core/c/dc_imex.c | char* dc_create_setup_code(dc_context_t* context)
{
#define CODE_ELEMS 9
uint16_t random_val = 0;
int i = 0;
dc_strbuilder_t ret;
dc_strbuilder_init(&ret, 0);
for (i = 0; i < CODE_ELEMS; i++)
{
do
{
if (!RAND_bytes((unsigned char*)&random_val, sizeof(uint16_t))) {
dc_log_wa... | projects/deltachat-core/rust/imex.rs | pub fn create_setup_code(_context: &Context) -> String {
let mut random_val: u16;
let mut rng = thread_rng();
let mut ret = String::new();
for i in 0..9 {
loop {
random_val = rng.gen();
if random_val as usize <= 60000 {
break;
}
}
... | pub struct Context {
pub(crate) inner: Arc<InnerContext>,
} | use std::any::Any;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use deltachat_contact_tools::EmailAddress;
use futures::StreamExt;
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
use ... | projects__deltachat-core__rust__imex__.rs__function__5.txt |
projects/deltachat-core/c/dc_contact.c | char* dc_contact_get_name(const dc_contact_t* contact)
{
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
return dc_strdup(NULL);
}
return dc_strdup(contact->name);
} | projects/deltachat-core/rust/contact.rs | pub fn get_name(&self) -> &str {
&self.name
} | pub struct Contact {
/// The contact ID.
pub id: ContactId,
/// Contact name. It is recommended to use `Contact::get_name`,
/// `Contact::get_display_name` or `Contact::get_name_n_addr` to access this field.
/// May be empty, initially set to `authname`.
name: String,
/// Name authorized b... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__39.txt |
projects/deltachat-core/c/dc_chat.c | * See also dc_send_msg().
*
* @memberof dc_context_t
* @param context The context object as returned from dc_context_new().
* @param chat_id Chat ID to send the text message to.
* @param text_to_send Text to send to the chat defined by the chat ID.
* Passing an empty text here causes an empty text to be sent,... | projects/deltachat-core/rust/chat.rs | pub async fn send_text_msg(
context: &Context,
chat_id: ChatId,
text_to_send: String,
) -> Result<MsgId> {
ensure!(
!chat_id.is_special(),
"bad chat_id, can not be a special chat: {}",
chat_id
);
let mut msg = Message::new(Viewtype::Text);
msg.text = text_to_send;
... | pub async fn send_msg(context: &Context, chat_id: ChatId, msg: &mut Message) -> Result<MsgId> {
if chat_id.is_unset() {
let forwards = msg.param.get(Param::PrepForwards);
if let Some(forwards) = forwards {
for forward in forwards.split(' ') {
if let Ok(msg_id) = forward.p... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__109.txt |
projects/deltachat-core/c/dc_contact.c | char* dc_contact_get_addr(const dc_contact_t* contact)
{
if (contact==NULL || contact->magic!=DC_CONTACT_MAGIC) {
return dc_strdup(NULL);
}
return dc_strdup(contact->addr);
} | projects/deltachat-core/rust/contact.rs | pub fn get_addr(&self) -> &str {
&self.addr
} | pub struct Contact {
/// The contact ID.
pub id: ContactId,
/// Contact name. It is recommended to use `Contact::get_name`,
/// `Contact::get_display_name` or `Contact::get_name_n_addr` to access this field.
/// May be empty, initially set to `authname`.
name: String,
/// Name authorized b... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__37.txt |
projects/deltachat-core/c/dc_contact.c | * unless it was edited manually by dc_create_contact() before.
* @return The number of modified or added contacts.
*/
int dc_add_address_book(dc_context_t* context, const char* adr_book)
{
carray* lines = NULL;
size_t i = 0;
size_t iCnt = 0;
int sth_modified = 0;
int modify_cnt = 0;
if (context=... | projects/deltachat-core/rust/contact.rs | pub async fn add_address_book(context: &Context, addr_book: &str) -> Result<usize> {
let mut modify_cnt = 0;
for (name, addr) in split_address_book(addr_book) {
let (name, addr) = sanitize_name_and_addr(name, addr);
match ContactAddress::new(&addr) {
Ok(addr) => ... | fn split_address_book(book: &str) -> Vec<(&str, &str)> {
book.lines()
.collect::<Vec<&str>>()
.chunks(2)
.filter_map(|chunk| {
let name = chunk.first()?;
let addr = chunk.get(1)?;
Some((*name, *addr))
})
.collect()
}
pub(crate) async fn ad... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__27.txt |
projects/deltachat-core/c/dc_sqlite3.c | int dc_sqlite3_execute(dc_sqlite3_t* sql, const char* querystr)
{
int success = 0;
sqlite3_stmt* stmt = NULL;
int sqlState = 0;
stmt = dc_sqlite3_prepare(sql, querystr);
if (stmt==NULL) {
goto cleanup;
}
sqlState = sqlite3_step(stmt);
if (sqlState != SQLITE_DONE && sqlState != SQLITE_ROW... | projects/deltachat-core/rust/sql.rs | pub async fn execute(
&self,
query: &str,
params: impl rusqlite::Params + Send,
) -> Result<usize> {
self.call_write(move |conn| {
let res = conn.execute(query, params)?;
Ok(res)
})
.await
} | pub async fn call_write<'a, F, R>(&'a self, function: F) -> Result<R>
where
F: 'a + FnOnce(&mut Connection) -> Result<R> + Send,
R: Send + 'static,
{
let _lock = self.write_lock().await;
self.call(function).await
}
pub struct Params {
inner: BTreeMap<Param, String>,
}
p... | use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use anyhow::{bail, Context as _, Result};
use rusqlite::{config::DbConfig, types::ValueRef, Connection, OpenFlags, Row};
use tokio::sync::{Mutex, MutexGuard, RwLock};
use crate::blob::BlobObject;
use crate::chat::{self, add_device_msg, update_dev... | projects__deltachat-core__rust__sql__.rs__function__16.txt |
projects/deltachat-core/c/dc_contact.c | * normalize() is _not_ called for the name. If the contact is blocked, it is unblocked.
*
* To add a number of contacts, see dc_add_address_book() which is much faster for adding
* a bunch of addresses.
*
* May result in a #DC_EVENT_CONTACTS_CHANGED event.
*
* @memberof dc_context_t
* @param context The context... | projects/deltachat-core/rust/contact.rs | pub async fn create(context: &Context, name: &str, addr: &str) -> Result<ContactId> {
Self::create_ex(context, Sync, name, addr).await
} | pub(crate) async fn create_ex(
context: &Context,
sync: sync::Sync,
name: &str,
addr: &str,
) -> Result<ContactId> {
let name = improve_single_line_input(name);
let (name, addr) = sanitize_name_and_addr(&name, addr);
let addr = ContactAddress::new(&addr)?;
... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__20.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_get_state(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return DC_STATE_UNDEFINED;
}
return msg->state;
} | projects/deltachat-core/rust/message.rs | pub fn get_state(&self) -> MessageState {
self.state
} | pub struct MsgId(u32);
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
pub(crate) to_id: ContactId,
/// ID of the chat message belongs to.
pub(crate) chat_id: ChatId,
... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__36.txt |
projects/deltachat-core/c/dc_chatlist.c | * 0 and dc_chatlist_get_cnt()-1.
*/
uint32_t dc_chatlist_get_chat_id(const dc_chatlist_t* chatlist, size_t index)
{
if (chatlist==NULL || chatlist->magic!=DC_CHATLIST_MAGIC || chatlist->chatNlastmsg_ids==NULL || index>=chatlist->cnt) {
return 0;
}
return dc_array_get_id(chatlist->chatNlastmsg_ids, index*DC_C... | projects/deltachat-core/rust/chatlist.rs | pub fn get_chat_id(&self, index: usize) -> Result<ChatId> {
let (chat_id, _msg_id) = self
.ids
.get(index)
.context("chatlist index is out of range")?;
Ok(*chat_id)
} | pub struct Chatlist {
/// Stores pairs of `chat_id, message_id`
ids: Vec<(ChatId, Option<MsgId>)>,
} | use anyhow::{ensure, Context as _, Result};
use once_cell::sync::Lazy;
use crate::chat::{update_special_chat_names, Chat, ChatId, ChatVisibility};
use crate::constants::{
Blocked, Chattype, DC_CHAT_ID_ALLDONE_HINT, DC_CHAT_ID_ARCHIVED_LINK, DC_GCL_ADD_ALLDONE_HINT,
DC_GCL_ARCHIVED_ONLY, DC_GCL_FOR_FORWARDING, D... | projects__deltachat-core__rust__chatlist__.rs__function__5.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_has_location(const dc_msg_t* msg)
{
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
return 0;
}
return (msg->location_id!=0);
} | projects/deltachat-core/rust/message.rs | pub fn has_location(&self) -> bool {
self.location_id != 0
} | pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first contact in the `To:` header.
pub(crate) to_id: ContactId,
/// ID of the chat message belongs to.
pub(crate) chat_id: ChatId,
/// Type of the messa... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__27.txt |
projects/deltachat-core/c/dc_sqlite3.c | static int is_file_in_use(dc_hash_t* files_in_use, const char* namespc, const char* name)
{
char* name_to_check = dc_strdup(name);
if (namespc) {
int name_len = strlen(name);
int namespc_len = strlen(namespc);
if (name_len<=namespc_len
|| strcmp(&name[name_len-namespc_len], namespc)!=0) {
return 0;
}
... | projects/deltachat-core/rust/sql.rs | fn is_file_in_use(files_in_use: &HashSet<String>, namespc_opt: Option<&str>, name: &str) -> bool {
let name_to_check = if let Some(namespc) = namespc_opt {
let name_len = name.len();
let namespc_len = namespc.len();
if name_len <= namespc_len || !name.ends_with(namespc) {
return ... | use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use anyhow::{bail, Context as _, Result};
use rusqlite::{config::DbConfig, types::ValueRef, Connection, OpenFlags, Row};
use tokio::sync::{Mutex, MutexGuard, RwLock};
use crate::blob::BlobObject;
use crate::chat::{self, add_device_msg, update_dev... | projects__deltachat-core__rust__sql__.rs__function__41.txt | |
projects/deltachat-core/c/dc_chat.c | * After the creation with dc_create_group_chat() the chat is usually unpromoted
* until the first call to dc_send_text_msg() or another sending function.
*
* With unpromoted chats, members can be added
* and settings can be modified without the need of special status messages being sent.
*
* While the core takes ... | projects/deltachat-core/rust/chat.rs | pub fn is_unpromoted(&self) -> bool {
self.param.get_bool(Param::Unpromoted).unwrap_or_default()
} | pub fn get_bool(&self, key: Param) -> Option<bool> {
self.get_int(key).map(|v| v != 0)
}
pub struct Chat {
/// Database ID.
pub id: ChatId,
/// Chat type, e.g. 1:1 chat, group chat, mailing list.
pub typ: Chattype,
/// Chat name.
pub name: String,
/// Whether the chat is arch... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__78.txt |
projects/deltachat-core/c/dc_imex.c | char* dc_imex_has_backup(dc_context_t* context, const char* dir_name)
{
char* ret = NULL;
DIR* dir_handle = NULL;
struct dirent* dir_entry = NULL;
int prefix_len = strlen(DC_BAK_PREFIX);
int suffix_len = strlen(DC_BAK_SUFFIX);
char* curr_pathNfilename = NULL;
dc_... | projects/deltachat-core/rust/imex.rs | pub async fn has_backup(_context: &Context, dir_name: &Path) -> Result<String> {
let mut dir_iter = tokio::fs::read_dir(dir_name).await?;
let mut newest_backup_name = "".to_string();
let mut newest_backup_path: Option<PathBuf> = None;
while let Ok(Some(dirent)) = dir_iter.next_entry().await {
l... | pub fn is_empty(&self) -> bool {
self.inner.is_empty()
}
pub struct Context {
pub(crate) inner: Arc<InnerContext>,
} | use std::any::Any;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use deltachat_contact_tools::EmailAddress;
use futures::StreamExt;
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
use ... | projects__deltachat-core__rust__imex__.rs__function__2.txt |
projects/deltachat-core/c/dc_param.c | int dc_param_exists(dc_param_t* param, int key)
{
char *p2 = NULL;
if (param==NULL || key==0) {
return 0;
}
return find_param(param->packed, key, &p2)? 1 : 0;
} | projects/deltachat-core/rust/param.rs | pub fn exists(&self, key: Param) -> bool {
self.inner.contains_key(&key)
} | pub struct Params {
inner: BTreeMap<Param, String>,
} | use std::collections::BTreeMap;
use std::fmt;
use std::path::PathBuf;
use std::str;
use anyhow::{bail, Error, Result};
use num_traits::FromPrimitive;
use serde::{Deserialize, Serialize};
use crate::blob::BlobObject;
use crate::context::Context;
use crate::mimeparser::SystemMessage;
use std::path::Path;
use std::str::Fr... | projects__deltachat-core__rust__param__.rs__function__5.txt |
projects/deltachat-core/c/dc_imex.c | int dc_continue_key_transfer(dc_context_t* context, uint32_t msg_id, const char* setup_code)
{
int success = 0;
dc_msg_t* msg = NULL;
char* filename = NULL;
char* filecontent = NULL;
size_t filebytes = 0;
char* armored_key = NULL;
char* norm_sc = NULL;
if (context==NULL || context->mag... | projects/deltachat-core/rust/imex.rs | pub async fn continue_key_transfer(
context: &Context,
msg_id: MsgId,
setup_code: &str,
) -> Result<()> {
ensure!(!msg_id.is_special(), "wrong id");
let msg = Message::load_from_db(context, msg_id).await?;
ensure!(
msg.is_setupmessage(),
"Message is no Autocrypt Setup Message."
... | pub fn is_special(self) -> bool {
self.0 <= DC_MSG_ID_LAST_SPECIAL
}
pub async fn load_from_db(context: &Context, id: MsgId) -> Result<Message> {
let message = Self::load_from_db_optional(context, id)
.await?
.with_context(|| format!("Message {id} does not exist"))?;
... | use std::any::Any;
use std::ffi::OsStr;
use std::path::{Path, PathBuf};
use ::pgp::types::KeyTrait;
use anyhow::{bail, ensure, format_err, Context as _, Result};
use deltachat_contact_tools::EmailAddress;
use futures::StreamExt;
use futures_lite::FutureExt;
use rand::{thread_rng, Rng};
use tokio::fs::{self, File};
use ... | projects__deltachat-core__rust__imex__.rs__function__7.txt |
projects/deltachat-core/c/dc_contact.c | * Known and unblocked contacts will be returned by dc_get_contacts().
*
* To validate an e-mail address independently of the contact database
* use dc_may_be_valid_addr().
*
* @memberof dc_context_t
* @param context The context object as created by dc_context_new().
* @param addr The e-mail-address to check.
* ... | projects/deltachat-core/rust/contact.rs | pub async fn lookup_id_by_addr(
context: &Context,
addr: &str,
min_origin: Origin,
) -> Result<Option<ContactId>> {
Self::lookup_id_by_addr_ex(context, addr, min_origin, Some(Blocked::Not)).await
} | pub(crate) async fn lookup_id_by_addr_ex(
context: &Context,
addr: &str,
min_origin: Origin,
blocked: Option<Blocked>,
) -> Result<Option<ContactId>> {
if addr.is_empty() {
bail!("lookup_id_by_addr: empty address");
}
let addr_normalized = addr_no... | use std::cmp::{min, Reverse};
use std::collections::BinaryHeap;
use std::fmt;
use std::path::{Path, PathBuf};
use std::time::UNIX_EPOCH;
use anyhow::{bail, ensure, Context as _, Result};
use async_channel::{self as channel, Receiver, Sender};
use base64::Engine as _;
use deltachat_contact_tools::may_be_valid_addr;
use ... | projects__deltachat-core__rust__contact__.rs__function__24.txt |
projects/deltachat-core/c/dc_msg.c | int dc_msg_get_info_type(const dc_msg_t* msg)
{
return dc_param_get_int(msg->param, DC_PARAM_CMD, 0);
} | projects/deltachat-core/rust/message.rs | pub fn get_info_type(&self) -> SystemMessage {
self.param.get_cmd()
} | pub fn get_cmd(&self) -> SystemMessage {
self.get_int(Param::Cmd)
.and_then(SystemMessage::from_i32)
.unwrap_or_default()
}
pub struct Message {
/// Message ID.
pub(crate) id: MsgId,
/// `From:` contact ID.
pub(crate) from_id: ContactId,
/// ID of the first con... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__57.txt |
projects/deltachat-core/c/dc_msg.c | void dc_update_msg_state(dc_context_t* context, uint32_t msg_id, int state)
{
sqlite3_stmt* stmt = dc_sqlite3_prepare(context->sql,
"UPDATE msgs SET state=? WHERE id=? AND (?=? OR state<?)");
sqlite3_bind_int(stmt, 1, state);
sqlite3_bind_int(stmt, 2, msg_id);
sqlite3_bind_int(stmt, 3, state);
sqlite... | projects/deltachat-core/rust/message.rs | pub(crate) async fn update_msg_state(
context: &Context,
msg_id: MsgId,
state: MessageState,
) -> Result<()> {
ensure!(state != MessageState::OutFailed, "use set_msg_failed()!");
let error_subst = match state >= MessageState::OutPending {
true => ", error=''",
false => "",
};
... | pub async fn execute(
&self,
query: &str,
params: impl rusqlite::Params + Send,
) -> Result<usize> {
self.call_write(move |conn| {
let res = conn.execute(query, params)?;
Ok(res)
})
.await
}
pub struct MsgId(u32);
pub struct Context {
... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__91.txt |
projects/deltachat-core/c/dc_chat.c | size_t dc_get_chat_cnt(dc_context_t* context)
{
size_t ret = 0;
sqlite3_stmt* stmt = NULL;
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || context->sql->cobj==NULL) {
goto cleanup; /* no database, no chats - this is no error (needed eg. for information) */
}
stmt = dc_sqlite3_prepare(context->s... | projects/deltachat-core/rust/chat.rs | pub(crate) async fn get_chat_cnt(context: &Context) -> Result<usize> {
if context.sql.is_open().await {
// no database, no chats - this is no error (needed eg. for information)
let count = context
.sql
.count("SELECT COUNT(*) FROM chats WHERE id>9 AND blocked=0;", ())
... | pub async fn count(&self, query: &str, params: impl rusqlite::Params + Send) -> Result<usize> {
let count: isize = self.query_row(query, params, |row| row.get(0)).await?;
Ok(usize::try_from(count)?)
}
pub async fn is_open(&self) -> bool {
self.sql.is_open().await
}
pub struct Context {... | use std::cmp;
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::time::Duration;
use anyhow::{anyhow, bail, ensure, Context as _, Result};
use deltachat_contact_tools::{strip_rtlo_characters, ContactAddress};
use deltachat_derive::{FromSql, ToSql};
us... | projects__deltachat-core__rust__chat__.rs__function__141.txt |
projects/deltachat-core/c/dc_msg.c | dc_lot_t* dc_msg_get_summary(const dc_msg_t* msg, const dc_chat_t* chat)
{
dc_lot_t* ret = dc_lot_new();
dc_contact_t* contact = NULL;
dc_chat_t* chat_to_delete = NULL;
if (msg==NULL || msg->magic!=DC_MSG_MAGIC) {
goto cleanup;
}
if (chat==NULL) {
if ((chat_to_delete=dc_get_chat(msg->context, msg-... | projects/deltachat-core/rust/message.rs | pub async fn get_summary(&self, context: &Context, chat: Option<&Chat>) -> Result<Summary> {
let chat_loaded: Chat;
let chat = if let Some(chat) = chat {
chat
} else {
let chat = Chat::load_from_db(context, self.chat_id).await?;
chat_loaded = chat;
... | pub async fn load_from_db(context: &Context, chat_id: ChatId) -> Result<Self> {
let mut chat = context
.sql
.query_row(
"SELECT c.type, c.name, c.grpid, c.param, c.archived,
c.blocked, c.locations_send_until, c.muted_until, c.protected
FRO... | use std::collections::BTreeSet;
use std::path::{Path, PathBuf};
use anyhow::{ensure, format_err, Context as _, Result};
use deltachat_contact_tools::{parse_vcard, VcardContact};
use deltachat_derive::{FromSql, ToSql};
use serde::{Deserialize, Serialize};
use tokio::{fs, io};
use crate::blob::BlobObject;
use crate::chat... | projects__deltachat-core__rust__message__.rs__function__50.txt |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.