Skip to content

Commit 582eaed

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 86db017 commit 582eaed

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
@@ -253,6 +253,11 @@ func (mbox *mailbox) fetchBodySection(msg *protonmail.Message, section *imap.Bod
253253
return nil, err
254254
}
255255

256+
err = mbox.db.Sync([]*protonmail.Message{msg})
257+
if err != nil {
258+
return nil, fmt.Errorf("could not sync message w/ db: %w", err)
259+
}
260+
256261
pw, err := w.CreatePart(inlineHeader(msg))
257262
if err != nil {
258263
return nil, err
@@ -299,6 +304,11 @@ func (mbox *mailbox) fetchBodySection(msg *protonmail.Message, section *imap.Bod
299304
return nil, err
300305
}
301306

307+
err = mbox.db.Sync([]*protonmail.Message{msg})
308+
if err != nil {
309+
return nil, fmt.Errorf("could not sync message w/ db: %w", err)
310+
}
311+
302312
h = inlineHeader(msg)
303313
getBody = func() (io.Reader, error) {
304314
return mbox.inlineBody(msg)
@@ -314,6 +324,11 @@ func (mbox *mailbox) fetchBodySection(msg *protonmail.Message, section *imap.Bod
314324
return nil, err
315325
}
316326

327+
err = mbox.db.Sync([]*protonmail.Message{msg})
328+
if err != nil {
329+
return nil, fmt.Errorf("could not sync message w/ db: %w", err)
330+
}
331+
317332
att := msg.Attachments[i]
318333
h = attachmentHeader(att)
319334
getBody = func() (io.Reader, error) {

0 commit comments

Comments
 (0)