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