mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
Let the python tast recognize when the mvbox is Inbox/DeltaChat instead of DeltaChat
This commit is contained in:
@@ -5,6 +5,7 @@ from . import Account
|
||||
INBOX = "Inbox"
|
||||
SENT = "Sent"
|
||||
MVBOX = "DeltaChat"
|
||||
MVBOX_FALLBBACK = "INBOX/DeltaChat"
|
||||
DC_CONSTANT_MSG_MOVESTATE_PENDING = 1
|
||||
DC_CONSTANT_MSG_MOVESTATE_STAY = 2
|
||||
DC_CONSTANT_MSG_MOVESTATE_MOVING = 3
|
||||
@@ -80,7 +81,7 @@ class ImapConn():
|
||||
try:
|
||||
self.connection.close()
|
||||
except Exception:
|
||||
print("Could not close direct_imap conn")
|
||||
pass
|
||||
try:
|
||||
self.connection.logout()
|
||||
except Exception:
|
||||
@@ -90,8 +91,21 @@ class ImapConn():
|
||||
def make_direct_imap(account, folder):
|
||||
conn_info = (account.get_config("configured_mail_server"),
|
||||
account.get_config("addr"), account.get_config("mail_pw"))
|
||||
imap = ImapConn(folder, conn_info=conn_info)
|
||||
return imap
|
||||
# try:
|
||||
# return ImapConn(folder, conn_info=conn_info)
|
||||
# except ConnectionError as e:
|
||||
# if folder == MVBOX:
|
||||
# account.log("Selecting " + MVBOX_FALLBBACK + " not " + MVBOX + " because connecting to the latter failed")
|
||||
# return ImapConn(MVBOX_FALLBBACK, conn_info=conn_info)
|
||||
# else:
|
||||
# raise e
|
||||
if folder == MVBOX:
|
||||
new_folder = account.get_config("configured_mvbox_folder")
|
||||
else:
|
||||
new_folder = folder
|
||||
if new_folder != folder:
|
||||
account.log("Making connection with " + new_folder + " not " + folder)
|
||||
return ImapConn(new_folder, conn_info=conn_info)
|
||||
|
||||
|
||||
def print_imap_structure(database, dir="."):
|
||||
@@ -104,13 +118,13 @@ def print_imap_structure_ac(ac, dir="."):
|
||||
print("----------------- CONFIG: -----------------")
|
||||
print(ac.get_info())
|
||||
|
||||
for imapfolder in [INBOX, MVBOX, SENT]:
|
||||
for imapfolder in [INBOX, MVBOX, SENT, MVBOX_FALLBBACK]:
|
||||
try:
|
||||
print("-----------------", imapfolder, "-----------------")
|
||||
imap = make_direct_imap(ac, imapfolder)
|
||||
c = imap.connection
|
||||
typ, data = c.search(None, 'ALL')
|
||||
c._get_tagged_response
|
||||
print("-----------------", imapfolder, "-----------------")
|
||||
for num in data[0].split():
|
||||
typ, data = c.fetch(num, '(RFC822)')
|
||||
body = data[0][1]
|
||||
@@ -123,5 +137,5 @@ def print_imap_structure_ac(ac, dir="."):
|
||||
file = path.joinpath(str(info).replace("b'", "").replace("'", "").replace("\\", ""))
|
||||
file.write_bytes(body)
|
||||
print("Message", info, "saved as", file)
|
||||
except ConnectionError:
|
||||
print("Seems like there is no", imapfolder, "folder")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -679,7 +679,8 @@ class TestOnlineAccount:
|
||||
time.sleep(1) # We might need to wait because Imaplib is slower than DC-Core
|
||||
assert imap2.get_unread_cnt() == 0
|
||||
|
||||
def test_mark_bcc_read_on_server(self, acfactory, lp):
|
||||
@pytest.mark.parametrize('i', range(30))
|
||||
def test_mark_bcc_read_on_server(self, acfactory, lp, i):
|
||||
ac1 = acfactory.get_online_configuring_account(mvbox=True, move=True)
|
||||
ac2 = acfactory.get_online_configuring_account()
|
||||
|
||||
@@ -689,7 +690,7 @@ class TestOnlineAccount:
|
||||
ac2.start_io()
|
||||
|
||||
imap1 = make_direct_imap(ac1, direct_imap.MVBOX)
|
||||
# imap1.mark_all_read()
|
||||
imap1.mark_all_read()
|
||||
assert imap1.get_unread_cnt() == 0
|
||||
|
||||
chat = self.get_chat(ac1, ac2)
|
||||
|
||||
@@ -104,6 +104,9 @@ pub enum Config {
|
||||
ConfiguredServerFlags,
|
||||
ConfiguredSendSecurity,
|
||||
ConfiguredE2EEEnabled,
|
||||
ConfiguredInboxFolder,
|
||||
ConfiguredMvboxFolder,
|
||||
ConfiguredSentboxFolder,
|
||||
Configured,
|
||||
|
||||
#[strum(serialize = "sys.version")]
|
||||
@@ -137,6 +140,7 @@ impl Context {
|
||||
// Default values
|
||||
match key {
|
||||
Config::Selfstatus => Some(self.stock_str(StockMessage::StatusLine).await.into_owned()),
|
||||
Config::ConfiguredInboxFolder => Some("INBOX".to_owned()),
|
||||
_ => key.get_str("default").map(|s| s.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,13 +300,11 @@ impl Context {
|
||||
.unwrap_or_default();
|
||||
|
||||
let configured_sentbox_folder = self
|
||||
.sql
|
||||
.get_raw_config(self, "configured_sentbox_folder")
|
||||
.get_config(Config::ConfiguredSentboxFolder)
|
||||
.await
|
||||
.unwrap_or_else(|| "<unset>".to_string());
|
||||
let configured_mvbox_folder = self
|
||||
.sql
|
||||
.get_raw_config(self, "configured_mvbox_folder")
|
||||
.get_config(Config::ConfiguredMvboxFolder)
|
||||
.await
|
||||
.unwrap_or_else(|| "<unset>".to_string());
|
||||
|
||||
@@ -442,33 +440,19 @@ impl Context {
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn is_inbox(&self, folder_name: impl AsRef<str>) -> bool {
|
||||
folder_name.as_ref() == "INBOX"
|
||||
pub async fn is_inbox(&self, folder_name: impl AsRef<str>) -> bool {
|
||||
self.get_config(Config::ConfiguredInboxFolder).await
|
||||
== Some(folder_name.as_ref().to_string())
|
||||
}
|
||||
|
||||
pub async fn is_sentbox(&self, folder_name: impl AsRef<str>) -> bool {
|
||||
let sentbox_name = self
|
||||
.sql
|
||||
.get_raw_config(self, "configured_sentbox_folder")
|
||||
.await;
|
||||
if let Some(name) = sentbox_name {
|
||||
name == folder_name.as_ref()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.get_config(Config::ConfiguredSentboxFolder).await
|
||||
== Some(folder_name.as_ref().to_string())
|
||||
}
|
||||
|
||||
pub async fn is_mvbox(&self, folder_name: impl AsRef<str>) -> bool {
|
||||
let mvbox_name = self
|
||||
.sql
|
||||
.get_raw_config(self, "configured_mvbox_folder")
|
||||
.await;
|
||||
|
||||
if let Some(name) = mvbox_name {
|
||||
name == folder_name.as_ref()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
self.get_config(Config::ConfiguredMvboxFolder).await
|
||||
== Some(folder_name.as_ref().to_string())
|
||||
}
|
||||
|
||||
pub async fn do_heuristics_moves(&self, folder: &str, msg_id: MsgId) {
|
||||
|
||||
@@ -1223,19 +1223,16 @@ impl Imap {
|
||||
}
|
||||
}
|
||||
context
|
||||
.sql
|
||||
.set_raw_config(context, "configured_inbox_folder", Some("INBOX"))
|
||||
.set_config(Config::ConfiguredInboxFolder, Some("INBOX"))
|
||||
.await?;
|
||||
if let Some(ref mvbox_folder) = mvbox_folder {
|
||||
context
|
||||
.sql
|
||||
.set_raw_config(context, "configured_mvbox_folder", Some(mvbox_folder))
|
||||
.set_config(Config::ConfiguredMvboxFolder, Some(mvbox_folder))
|
||||
.await?;
|
||||
}
|
||||
if let Some(ref sentbox_folder) = sentbox_folder {
|
||||
context
|
||||
.sql
|
||||
.set_raw_config(context, "configured_sentbox_folder", Some(sentbox_folder))
|
||||
.set_config(Config::ConfiguredSentboxFolder, Some(sentbox_folder))
|
||||
.await?;
|
||||
}
|
||||
context
|
||||
@@ -1381,8 +1378,6 @@ async fn precheck_imf(
|
||||
server_folder,
|
||||
server_uid
|
||||
);
|
||||
update_server_uid(context, rfc724_mid, server_folder, server_uid).await;
|
||||
context.interrupt_inbox(false).await;
|
||||
} else if old_server_uid != server_uid {
|
||||
warn!(
|
||||
context,
|
||||
@@ -1392,12 +1387,10 @@ async fn precheck_imf(
|
||||
old_server_uid,
|
||||
server_uid
|
||||
);
|
||||
update_server_uid(context, rfc724_mid, server_folder, server_uid).await;
|
||||
context.interrupt_inbox(false).await;
|
||||
}
|
||||
|
||||
if old_server_folder != server_folder || old_server_uid != server_uid {
|
||||
update_server_uid(context, &rfc724_mid, server_folder, server_uid).await;
|
||||
update_server_uid(context, rfc724_mid, server_folder, server_uid).await;
|
||||
}
|
||||
Ok(true)
|
||||
} else {
|
||||
|
||||
11
src/job.rs
11
src/job.rs
@@ -504,10 +504,7 @@ impl Job {
|
||||
warn!(context, "could not configure folders: {:?}", err);
|
||||
return Status::RetryLater;
|
||||
}
|
||||
let dest_folder = context
|
||||
.sql
|
||||
.get_raw_config(context, "configured_mvbox_folder")
|
||||
.await;
|
||||
let dest_folder = context.get_config(Config::ConfiguredMvboxFolder).await;
|
||||
|
||||
if let Some(dest_folder) = dest_folder {
|
||||
let server_folder = msg.server_folder.as_ref().unwrap();
|
||||
@@ -612,11 +609,7 @@ impl Job {
|
||||
|
||||
async fn empty_server(&mut self, context: &Context, imap: &mut Imap) -> Status {
|
||||
if self.foreign_id & DC_EMPTY_MVBOX > 0 {
|
||||
if let Some(mvbox_folder) = context
|
||||
.sql
|
||||
.get_raw_config(context, "configured_mvbox_folder")
|
||||
.await
|
||||
{
|
||||
if let Some(mvbox_folder) = &context.get_config(Config::ConfiguredMvboxFolder).await {
|
||||
imap.empty_folder(context, &mvbox_folder).await;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use async_std::task;
|
||||
use crate::context::Context;
|
||||
use crate::imap::Imap;
|
||||
use crate::job::{self, Thread};
|
||||
use crate::smtp::Smtp;
|
||||
use crate::{config::Config, smtp::Smtp};
|
||||
|
||||
pub(crate) struct StopToken;
|
||||
|
||||
@@ -104,7 +104,7 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne
|
||||
None => {
|
||||
jobs_loaded = 0;
|
||||
probe_network =
|
||||
fetch_idle(&ctx, &mut connection, "configured_inbox_folder").await;
|
||||
fetch_idle(&ctx, &mut connection, Config::ConfiguredInboxFolder).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ async fn inbox_loop(ctx: Context, started: Sender<()>, inbox_handlers: ImapConne
|
||||
}
|
||||
|
||||
async fn fetch(ctx: &Context, connection: &mut Imap) {
|
||||
match get_watch_folder(&ctx, "configured_inbox_folder").await {
|
||||
match ctx.get_config(Config::ConfiguredInboxFolder).await {
|
||||
Some(watch_folder) => {
|
||||
// fetch
|
||||
if let Err(err) = connection.fetch(&ctx, &watch_folder).await {
|
||||
@@ -136,8 +136,8 @@ async fn fetch(ctx: &Context, connection: &mut Imap) {
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_idle(ctx: &Context, connection: &mut Imap, folder: &str) -> bool {
|
||||
match get_watch_folder(&ctx, folder).await {
|
||||
async fn fetch_idle(ctx: &Context, connection: &mut Imap, folder: Config) -> bool {
|
||||
match ctx.get_config(folder).await {
|
||||
Some(watch_folder) => {
|
||||
// fetch
|
||||
if let Err(err) = connection.fetch(&ctx, &watch_folder).await {
|
||||
@@ -170,7 +170,7 @@ async fn simple_imap_loop(
|
||||
ctx: Context,
|
||||
started: Sender<()>,
|
||||
inbox_handlers: ImapConnectionHandlers,
|
||||
folder: impl AsRef<str>,
|
||||
folder: Config,
|
||||
) {
|
||||
use futures::future::FutureExt;
|
||||
|
||||
@@ -193,7 +193,7 @@ async fn simple_imap_loop(
|
||||
started.send(()).await;
|
||||
|
||||
loop {
|
||||
fetch_idle(&ctx, &mut connection, folder.as_ref()).await;
|
||||
fetch_idle(&ctx, &mut connection, folder).await;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -286,7 +286,7 @@ impl Scheduler {
|
||||
ctx1,
|
||||
mvbox_start_send,
|
||||
mvbox_handlers,
|
||||
"configured_mvbox_folder",
|
||||
Config::ConfiguredMvboxFolder,
|
||||
)
|
||||
.await
|
||||
}));
|
||||
@@ -300,7 +300,7 @@ impl Scheduler {
|
||||
ctx1,
|
||||
sentbox_start_send,
|
||||
sentbox_handlers,
|
||||
"configured_sentbox_folder",
|
||||
Config::ConfiguredSentboxFolder,
|
||||
)
|
||||
.await
|
||||
}));
|
||||
@@ -541,21 +541,3 @@ struct ImapConnectionHandlers {
|
||||
stop_receiver: Receiver<()>,
|
||||
shutdown_sender: Sender<()>,
|
||||
}
|
||||
|
||||
async fn get_watch_folder(context: &Context, config_name: impl AsRef<str>) -> Option<String> {
|
||||
match context
|
||||
.sql
|
||||
.get_raw_config(context, config_name.as_ref())
|
||||
.await
|
||||
{
|
||||
Some(name) => Some(name),
|
||||
None => {
|
||||
if config_name.as_ref() == "configured_inbox_folder" {
|
||||
// initialized with old version, so has not set configured_inbox_folder
|
||||
Some("INBOX".to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user