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