feat: fix attachment stub issues in Rust implementation

- Removed attachment metadata from initial document storage
- Attachments are now stored separately using CouchDB native attachment API
- This matches the Go implementation approach and resolves CouchDB validation errors
- All messages with attachments now store successfully

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2025-08-03 13:52:55 +02:00
commit d4e10a3aae
5 changed files with 126 additions and 30 deletions

View file

@ -271,7 +271,7 @@ impl SyncCoordinator {
let mut messages_skipped = 0;
let mut last_uid = None;
for mail_doc in messages {
for (mail_doc, attachments) in messages {
// Apply message filters
if !should_process_message(&mail_doc, &source.message_filter) {
messages_skipped += 1;
@ -281,10 +281,31 @@ impl SyncCoordinator {
// Extract UID before moving the document
let uid_str = mail_doc.source_uid.clone();
// Store the message
// Store the message document first
match self.couch_client.store_mail_document(db_name, mail_doc).await {
Ok(_) => {
Ok(doc_id) => {
messages_stored += 1;
// Store attachments if any exist
if !attachments.is_empty() {
for (filename, content_type, data) in attachments {
match self.couch_client.store_attachment(
db_name,
&doc_id,
&filename,
&content_type,
&data,
).await {
Ok(_) => {
debug!(" Stored attachment: {}", filename);
}
Err(e) => {
warn!(" Failed to store attachment {}: {}", filename, e);
}
}
}
}
// Parse UID from source_uid
if let Ok(uid) = uid_str.parse::<u32>() {
last_uid = Some(last_uid.map_or(uid, |prev: u32| prev.max(uid)));