extract attachment info from bodystructure
parent
3d218e0aa5
commit
3f23809c79
28
Syncer.js
28
Syncer.js
|
@ -222,7 +222,8 @@ Syncer.prototype.syncBox = function*(srv, accountId, boxName, boxKind, doFull)
|
|||
missing.push((maxUid ? maxUid+1 : 1)+':*');
|
||||
yield* this.imap.runFetch(srv, missing, {
|
||||
size: true,
|
||||
bodies: 'HEADER'
|
||||
bodies: 'HEADER',
|
||||
struct: true,
|
||||
}, (messages, state) => this.saveMessages(messages, boxRow.id, state));
|
||||
|
||||
yield this.pg.update('folders', {
|
||||
|
@ -383,6 +384,25 @@ Syncer.prototype.parseMsg = function*(msg)
|
|||
return obj;
|
||||
}
|
||||
|
||||
Syncer.prototype.extractAttachments = function(struct, attachments)
|
||||
{
|
||||
attachments = attachments || [];
|
||||
for (var i = 0; i < struct.length; i++)
|
||||
{
|
||||
if (struct[i] instanceof Array)
|
||||
this.extractAttachments(struct[i], attachments);
|
||||
else if (struct[i].disposition && struct[i].disposition.type == 'attachment')
|
||||
{
|
||||
attachments.push([
|
||||
struct[i].disposition.params && struct[i].disposition.params.filename || struct[i].description || '',
|
||||
struct[i].type+'/'+struct[i].subtype,
|
||||
struct[i].size
|
||||
]);
|
||||
}
|
||||
}
|
||||
return attachments;
|
||||
}
|
||||
|
||||
Syncer.prototype.addMessage = function*(boxId, msgrow, attrs)
|
||||
{
|
||||
var self = this;
|
||||
|
@ -403,11 +423,6 @@ Syncer.prototype.addMessage = function*(boxId, msgrow, attrs)
|
|||
if (!header.date)
|
||||
header.date = new Date(attrs.date);
|
||||
|
||||
if (!header.from)
|
||||
{
|
||||
console.log(msgrow.headers);
|
||||
console.log(header);
|
||||
}
|
||||
delete msgrow.headers;
|
||||
msgrow.folder_id = boxId;
|
||||
msgrow.subject = header.subject || '';
|
||||
|
@ -417,6 +432,7 @@ Syncer.prototype.addMessage = function*(boxId, msgrow, attrs)
|
|||
cc: (header.cc||[]).map((a) => [ a.name, a.address ]),
|
||||
bcc: (header.bcc||[]).map((a) => [ a.name, a.address ]),
|
||||
replyto: (header.replyTo||[]).map((a) => [ a.name, a.address ]),
|
||||
attachments: this.extractAttachments(attrs.struct),
|
||||
});
|
||||
msgrow.messageid = header.messageId || '';
|
||||
msgrow.inreplyto = header.inReplyTo && header.inReplyTo[0] || '';
|
||||
|
|
Loading…
Reference in New Issue