Skip to content

Commit f633d1d

Browse files
committed
imap: synchronize a fully fetched message w/ local db
The messages list is first retrieved from Proton via the /messages call. A JSON representation of each of these messages is saved in a local db. However, the retrieved JSON description doesn't include the MIMEType field which is left empty. This CL fixes this by always sync'ing the local db with the full message description as soon as it's retrieved from Proton. Fixes #112.
1 parent eaed359 commit f633d1d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

imap/message.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ func (mbox *mailbox) fetchBodySection(msg *protonmail.Message, section *imap.Bod
262262
return nil, err
263263
}
264264

265+
err = mbox.db.Sync([]*protonmail.Message{msg})
266+
if err != nil {
267+
return nil, fmt.Errorf("could not sync message w/ db: %w", err)
268+
}
269+
265270
pw, err := w.CreatePart(inlineHeader(msg))
266271
if err != nil {
267272
return nil, err
@@ -308,6 +313,11 @@ func (mbox *mailbox) fetchBodySection(msg *protonmail.Message, section *imap.Bod
308313
return nil, err
309314
}
310315

316+
err = mbox.db.Sync([]*protonmail.Message{msg})
317+
if err != nil {
318+
return nil, fmt.Errorf("could not sync message w/ db: %w", err)
319+
}
320+
311321
h = inlineHeader(msg)
312322
getBody = func() (io.Reader, error) {
313323
return mbox.inlineBody(msg)
@@ -323,6 +333,11 @@ func (mbox *mailbox) fetchBodySection(msg *protonmail.Message, section *imap.Bod
323333
return nil, err
324334
}
325335

336+
err = mbox.db.Sync([]*protonmail.Message{msg})
337+
if err != nil {
338+
return nil, fmt.Errorf("could not sync message w/ db: %w", err)
339+
}
340+
326341
att := msg.Attachments[i]
327342
h = attachmentHeader(att)
328343
getBody = func() (io.Reader, error) {

0 commit comments

Comments
 (0)