| 1 |
use super::{ |
| 2 |
Attachment, AttachmentId, DateTime, Email, EmailAccount, EmailAccountId, EmailAuthType, |
| 3 |
EmailId, EmailThread, FolderSyncState, HashSet, NewAttachment, NewEmail, NewEmailWithTracking, |
| 4 |
ProjectId, Result, TaskId, UserId, Utc, async_trait, |
| 5 |
}; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#[async_trait] |
| 12 |
pub trait EmailRepository: Send + Sync { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
async fn list_all(&self, user_id: UserId, include_archived: bool) -> Result<Vec<Email>>; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
async fn list_metadata(&self, user_id: UserId, include_archived: bool) -> Result<Vec<Email>>; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
async fn list_threaded( |
| 29 |
&self, |
| 30 |
user_id: UserId, |
| 31 |
include_archived: bool, |
| 32 |
offset: Option<i64>, |
| 33 |
limit: Option<i64>, |
| 34 |
folder: Option<&str>, |
| 35 |
label: Option<&str>, |
| 36 |
) -> Result<(Vec<EmailThread>, i64)>; |
| 37 |
|
| 38 |
|
| 39 |
async fn list_by_project(&self, user_id: UserId, project_id: ProjectId) -> Result<Vec<Email>>; |
| 40 |
|
| 41 |
|
| 42 |
async fn list_by_addresses(&self, user_id: UserId, addresses: &[&str]) -> Result<Vec<Email>>; |
| 43 |
|
| 44 |
|
| 45 |
async fn list_unlinked(&self, user_id: UserId) -> Result<Vec<Email>>; |
| 46 |
|
| 47 |
|
| 48 |
async fn get_by_id(&self, id: EmailId, user_id: UserId) -> Result<Option<Email>>; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
async fn set_full_body(&self, id: EmailId, user_id: UserId, body: &str) -> Result<()>; |
| 53 |
|
| 54 |
|
| 55 |
async fn create(&self, user_id: UserId, email: NewEmail) -> Result<Email>; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
async fn restore(&self, user_id: UserId, email: &Email) -> Result<()>; |
| 64 |
|
| 65 |
|
| 66 |
async fn create_with_tracking( |
| 67 |
&self, |
| 68 |
user_id: UserId, |
| 69 |
email: NewEmailWithTracking, |
| 70 |
) -> Result<Email>; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
async fn create_with_tracking_batch( |
| 75 |
&self, |
| 76 |
user_id: UserId, |
| 77 |
emails: Vec<NewEmailWithTracking>, |
| 78 |
) -> Result<usize>; |
| 79 |
|
| 80 |
|
| 81 |
async fn delete(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 82 |
|
| 83 |
|
| 84 |
async fn mark_read(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 85 |
|
| 86 |
|
| 87 |
async fn mark_unread(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 88 |
|
| 89 |
|
| 90 |
async fn archive(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 91 |
|
| 92 |
|
| 93 |
async fn unarchive(&self, id: EmailId, user_id: UserId) -> Result<bool>; |
| 94 |
|
| 95 |
|
| 96 |
async fn update_source_folder( |
| 97 |
&self, |
| 98 |
id: EmailId, |
| 99 |
user_id: UserId, |
| 100 |
new_folder: &str, |
| 101 |
) -> Result<bool>; |
| 102 |
|
| 103 |
|
| 104 |
async fn mark_all_read(&self, user_id: UserId) -> Result<u64>; |
| 105 |
|
| 106 |
|
| 107 |
async fn link_to_project( |
| 108 |
&self, |
| 109 |
id: EmailId, |
| 110 |
user_id: UserId, |
| 111 |
project_id: Option<ProjectId>, |
| 112 |
) -> Result<bool>; |
| 113 |
|
| 114 |
|
| 115 |
async fn count_unread(&self, user_id: UserId) -> Result<i64>; |
| 116 |
|
| 117 |
|
| 118 |
async fn exists_by_message_id(&self, user_id: UserId, message_id: &str) -> Result<bool>; |
| 119 |
|
| 120 |
|
| 121 |
async fn exists_by_message_ids( |
| 122 |
&self, |
| 123 |
user_id: UserId, |
| 124 |
message_ids: &[&str], |
| 125 |
) -> Result<HashSet<String>>; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
async fn exists_as_senders( |
| 130 |
&self, |
| 131 |
user_id: UserId, |
| 132 |
addresses: &[&str], |
| 133 |
) -> Result<HashSet<String>>; |
| 134 |
|
| 135 |
|
| 136 |
async fn snooze( |
| 137 |
&self, |
| 138 |
id: EmailId, |
| 139 |
user_id: UserId, |
| 140 |
until: DateTime<Utc>, |
| 141 |
) -> Result<Option<Email>>; |
| 142 |
|
| 143 |
|
| 144 |
async fn unsnooze(&self, id: EmailId, user_id: UserId) -> Result<Option<Email>>; |
| 145 |
|
| 146 |
|
| 147 |
async fn list_snoozed(&self, user_id: UserId) -> Result<Vec<Email>>; |
| 148 |
|
| 149 |
|
| 150 |
async fn mark_waiting( |
| 151 |
&self, |
| 152 |
id: EmailId, |
| 153 |
user_id: UserId, |
| 154 |
expected_response: Option<DateTime<Utc>>, |
| 155 |
) -> Result<Option<Email>>; |
| 156 |
|
| 157 |
|
| 158 |
async fn clear_waiting(&self, id: EmailId, user_id: UserId) -> Result<Option<Email>>; |
| 159 |
|
| 160 |
|
| 161 |
async fn list_waiting(&self, user_id: UserId) -> Result<Vec<Email>>; |
| 162 |
|
| 163 |
|
| 164 |
async fn list_by_thread(&self, user_id: UserId, thread_id: &str) -> Result<Vec<Email>>; |
| 165 |
|
| 166 |
|
| 167 |
async fn get_by_message_id(&self, user_id: UserId, message_id: &str) -> Result<Option<Email>>; |
| 168 |
|
| 169 |
|
| 170 |
async fn update_labels( |
| 171 |
&self, |
| 172 |
id: EmailId, |
| 173 |
user_id: UserId, |
| 174 |
labels: &[String], |
| 175 |
) -> Result<Option<Email>>; |
| 176 |
|
| 177 |
|
| 178 |
async fn list_folders(&self, user_id: UserId) -> Result<Vec<String>>; |
| 179 |
|
| 180 |
|
| 181 |
async fn list_labels(&self, user_id: UserId) -> Result<Vec<String>>; |
| 182 |
|
| 183 |
|
| 184 |
async fn list_drafts(&self, user_id: UserId) -> Result<Vec<Email>>; |
| 185 |
|
| 186 |
|
| 187 |
#[allow(clippy::too_many_arguments)] |
| 188 |
async fn save_draft( |
| 189 |
&self, |
| 190 |
id: EmailId, |
| 191 |
user_id: UserId, |
| 192 |
from: &str, |
| 193 |
to: &str, |
| 194 |
cc: Option<&str>, |
| 195 |
bcc: Option<&str>, |
| 196 |
subject: &str, |
| 197 |
body: &str, |
| 198 |
account_id: Option<EmailAccountId>, |
| 199 |
in_reply_to: Option<&str>, |
| 200 |
references: Option<&str>, |
| 201 |
thread_id: Option<&str>, |
| 202 |
) -> Result<Email>; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
#[allow(clippy::too_many_arguments)] |
| 207 |
#[async_trait] |
| 208 |
pub trait EmailAccountRepository: Send + Sync { |
| 209 |
|
| 210 |
async fn list_by_user(&self, user_id: UserId) -> Result<Vec<EmailAccount>>; |
| 211 |
|
| 212 |
|
| 213 |
async fn get_by_id(&self, id: EmailAccountId, user_id: UserId) -> Result<Option<EmailAccount>>; |
| 214 |
|
| 215 |
|
| 216 |
async fn create( |
| 217 |
&self, |
| 218 |
user_id: UserId, |
| 219 |
account_name: &str, |
| 220 |
email_address: &str, |
| 221 |
imap_server: &str, |
| 222 |
imap_port: i32, |
| 223 |
smtp_server: &str, |
| 224 |
smtp_port: i32, |
| 225 |
username: &str, |
| 226 |
password: &str, |
| 227 |
use_tls: bool, |
| 228 |
archive_folder_name: Option<&str>, |
| 229 |
) -> Result<EmailAccount>; |
| 230 |
|
| 231 |
|
| 232 |
async fn create_oauth( |
| 233 |
&self, |
| 234 |
user_id: UserId, |
| 235 |
account_name: &str, |
| 236 |
email_address: &str, |
| 237 |
access_token: &str, |
| 238 |
refresh_token: &str, |
| 239 |
expires_at: DateTime<Utc>, |
| 240 |
jmap_session_url: &str, |
| 241 |
jmap_account_id: &str, |
| 242 |
) -> Result<EmailAccount>; |
| 243 |
|
| 244 |
|
| 245 |
async fn create_oauth_imap( |
| 246 |
&self, |
| 247 |
user_id: UserId, |
| 248 |
account_name: &str, |
| 249 |
email_address: &str, |
| 250 |
auth_type: EmailAuthType, |
| 251 |
access_token: &str, |
| 252 |
refresh_token: &str, |
| 253 |
expires_at: DateTime<Utc>, |
| 254 |
imap_server: &str, |
| 255 |
imap_port: i32, |
| 256 |
smtp_server: &str, |
| 257 |
smtp_port: i32, |
| 258 |
) -> Result<EmailAccount>; |
| 259 |
|
| 260 |
|
| 261 |
async fn update( |
| 262 |
&self, |
| 263 |
id: EmailAccountId, |
| 264 |
user_id: UserId, |
| 265 |
account_name: &str, |
| 266 |
email_address: &str, |
| 267 |
imap_server: &str, |
| 268 |
imap_port: i32, |
| 269 |
smtp_server: &str, |
| 270 |
smtp_port: i32, |
| 271 |
username: &str, |
| 272 |
password: Option<&str>, |
| 273 |
use_tls: bool, |
| 274 |
archive_folder_name: Option<&str>, |
| 275 |
) -> Result<Option<EmailAccount>>; |
| 276 |
|
| 277 |
|
| 278 |
async fn update_oauth_tokens( |
| 279 |
&self, |
| 280 |
id: EmailAccountId, |
| 281 |
user_id: UserId, |
| 282 |
access_token: &str, |
| 283 |
refresh_token: Option<&str>, |
| 284 |
expires_at: DateTime<Utc>, |
| 285 |
) -> Result<Option<EmailAccount>>; |
| 286 |
|
| 287 |
|
| 288 |
async fn update_jmap_session( |
| 289 |
&self, |
| 290 |
id: EmailAccountId, |
| 291 |
user_id: UserId, |
| 292 |
session_url: &str, |
| 293 |
account_id: &str, |
| 294 |
) -> Result<Option<EmailAccount>>; |
| 295 |
|
| 296 |
|
| 297 |
async fn delete(&self, id: EmailAccountId, user_id: UserId) -> Result<bool>; |
| 298 |
|
| 299 |
|
| 300 |
async fn update_last_sync(&self, id: EmailAccountId, user_id: UserId) -> Result<bool>; |
| 301 |
|
| 302 |
|
| 303 |
async fn update_sync_interval( |
| 304 |
&self, |
| 305 |
id: EmailAccountId, |
| 306 |
user_id: UserId, |
| 307 |
interval_minutes: Option<i32>, |
| 308 |
) -> Result<Option<EmailAccount>>; |
| 309 |
|
| 310 |
|
| 311 |
async fn update_signature( |
| 312 |
&self, |
| 313 |
id: EmailAccountId, |
| 314 |
user_id: UserId, |
| 315 |
signature: Option<&str>, |
| 316 |
) -> Result<Option<EmailAccount>>; |
| 317 |
|
| 318 |
|
| 319 |
async fn update_notify_new_emails( |
| 320 |
&self, |
| 321 |
id: EmailAccountId, |
| 322 |
user_id: UserId, |
| 323 |
enabled: bool, |
| 324 |
) -> Result<Option<EmailAccount>>; |
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
async fn list_accounts_needing_sync(&self, user_id: UserId) -> Result<Vec<EmailAccount>>; |
| 329 |
|
| 330 |
|
| 331 |
async fn get_folder_sync_state( |
| 332 |
&self, |
| 333 |
account_id: EmailAccountId, |
| 334 |
folder: &str, |
| 335 |
) -> Result<Option<FolderSyncState>>; |
| 336 |
|
| 337 |
|
| 338 |
async fn upsert_folder_sync_state( |
| 339 |
&self, |
| 340 |
account_id: EmailAccountId, |
| 341 |
folder: &str, |
| 342 |
uid_validity: u32, |
| 343 |
last_seen_uid: u32, |
| 344 |
) -> Result<()>; |
| 345 |
|
| 346 |
|
| 347 |
async fn delete_folder_sync_state( |
| 348 |
&self, |
| 349 |
account_id: EmailAccountId, |
| 350 |
folder: &str, |
| 351 |
) -> Result<()>; |
| 352 |
} |
| 353 |
|
| 354 |
|
| 355 |
#[async_trait] |
| 356 |
pub trait AttachmentRepository: Send + Sync { |
| 357 |
|
| 358 |
async fn create(&self, user_id: UserId, attachment: NewAttachment) -> Result<Attachment>; |
| 359 |
|
| 360 |
|
| 361 |
async fn list_for_task(&self, task_id: TaskId, user_id: UserId) -> Result<Vec<Attachment>>; |
| 362 |
|
| 363 |
|
| 364 |
async fn list_for_project( |
| 365 |
&self, |
| 366 |
project_id: ProjectId, |
| 367 |
user_id: UserId, |
| 368 |
) -> Result<Vec<Attachment>>; |
| 369 |
|
| 370 |
|
| 371 |
async fn get_by_id(&self, id: AttachmentId, user_id: UserId) -> Result<Option<Attachment>>; |
| 372 |
|
| 373 |
|
| 374 |
async fn delete(&self, id: AttachmentId, user_id: UserId) -> Result<bool>; |
| 375 |
|
| 376 |
|
| 377 |
async fn list_by_blob_hash(&self, blob_hash: &str, user_id: UserId) -> Result<Vec<Attachment>>; |
| 378 |
|
| 379 |
|
| 380 |
async fn list_all_blob_hashes(&self, user_id: UserId) -> Result<Vec<String>>; |
| 381 |
|
| 382 |
|
| 383 |
async fn list_all(&self, user_id: UserId) -> Result<Vec<Attachment>>; |
| 384 |
} |
| 385 |
|