Skip to content

Commit

Permalink
Keep modseq as optional
Browse files Browse the repository at this point in the history
Some features might not support this feature
  • Loading branch information
matzipan committed Nov 12, 2023
1 parent 3b0310b commit a7291c0
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE messages_new (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
message_id TEXT NOT NULL,
subject TEXT NOT NULL,
folder_id INTEGER NOT NULL,
time_received TIMESTAMP NOT NULL,
"from" TEXT NOT NULL,
"to" TEXT NOT NULL,
cc TEXT NOT NULL,
bcc TEXT NOT NULL,
content TEXT,
"references" TEXT NOT NULL,
in_reply_to TEXT NOT NULL,
uid INTEGER NOT NULL,
modification_sequence INTEGER NOT NULL,
seen BOOLEAN NOT NULL,
flagged BOOLEAN NOT NULL,
draft BOOLEAN NOT NULL,
deleted BOOLEAN NOT NULL
);

INSERT INTO messages_new SELECT * FROM messages;
DROP TABLE messages;
ALTER TABLE messages_new RENAME TO messages;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
CREATE TABLE messages_new (
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
message_id TEXT NOT NULL,
subject TEXT NOT NULL,
folder_id INTEGER NOT NULL,
time_received TIMESTAMP NOT NULL,
"from" TEXT NOT NULL,
"to" TEXT NOT NULL,
cc TEXT NOT NULL,
bcc TEXT NOT NULL,
content TEXT,
"references" TEXT NOT NULL,
in_reply_to TEXT NOT NULL,
uid INTEGER NOT NULL,
modification_sequence INTEGER NULL,
seen BOOLEAN NOT NULL,
flagged BOOLEAN NOT NULL,
draft BOOLEAN NOT NULL,
deleted BOOLEAN NOT NULL
);

INSERT INTO messages_new SELECT * FROM messages;
DROP TABLE messages;
ALTER TABLE messages_new RENAME TO messages;
10 changes: 8 additions & 2 deletions app/src/backends/imap/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use melib::MeliError;

use log::debug;

use std::borrow::Cow;
use std::convert::TryInto;
use std::time::Instant;

Expand Down Expand Up @@ -174,8 +175,13 @@ async fn fetch_messages_overview_in_uid_range(
// message_sequence_number: 0,
// references: None,

//@TODO conversion from i64 to u64
new_message.modification_sequence = message.modseq.unwrap().0.get().try_into().unwrap();
new_message.modification_sequence = message
.modseq
// The DB uses i64 but the backend gives us NonZeroU64 so we have to do this conversion
.map(|modseq| TryInto::<i64>::try_into(u64::from(modseq.0)))
.transpose()
// Abusing the types a little bit to coerce into a valid MeliError
.or_else(|_| Err(Cow::from("Unable to convert modification sequence type")))?;

messages_list.push(new_message);
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/models/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Message {
pub references: String,
pub in_reply_to: String,
pub uid: i64,
pub modification_sequence: i64,
pub modification_sequence: Option<i64>,
pub seen: bool,
pub flagged: bool,
pub draft: bool,
Expand Down Expand Up @@ -153,7 +153,7 @@ pub struct NewMessage {
pub references: String,
pub in_reply_to: String,
pub uid: i64,
pub modification_sequence: i64,
pub modification_sequence: Option<i64>,
pub seen: bool,
pub flagged: bool,
pub draft: bool,
Expand All @@ -179,8 +179,8 @@ impl From<melib::email::Envelope> for NewMessage {
in_reply_to: envelope
.in_reply_to()
.map_or("".to_string(), |x| String::from_utf8(x.0.clone()).unwrap()),
uid: 0, //@TODO
modification_sequence: 0, //@TODO
uid: 0, //@TODO
modification_sequence: Some(0),
seen: flags.contains(melib::email::Flag::SEEN),
flagged: flags.contains(melib::email::Flag::FLAGGED),
draft: flags.contains(melib::email::Flag::DRAFT),
Expand Down
2 changes: 1 addition & 1 deletion app/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ table! {
references -> Text,
in_reply_to -> Text,
uid -> BigInt,
modification_sequence -> BigInt,
modification_sequence -> Nullable<BigInt>,
seen -> Bool,
flagged -> Bool,
draft -> Bool,
Expand Down

0 comments on commit a7291c0

Please sign in to comment.