Permalink
Browse files

Bugfix: If an email contains only one reference, the parser does not …

…return an array. We need to turn it into an array before treating it as one.
  • Loading branch information...
1 parent ca3aa06 commit 8ca1ca413f7b7d53bee183552f5e0c1c373217cd @NicoleRauch NicoleRauch committed Feb 14, 2017
@@ -13,6 +13,7 @@ const crypto = require('crypto');
const beans = require('simple-configure').get('beans');
const fieldHelpers = beans.get('fieldHelpers');
+const misc = beans.get('misc');
const memberstore = beans.get('memberstore');
module.exports = function importMails(file, group, done) {
@@ -43,7 +44,7 @@ module.exports = function importMails(file, group, done) {
function references(parsedObject) {
if (fieldHelpers.isFilled(parsedObject.references)) {
- return parsedObject.references.map(removeLeadingAndTrailingBrackets);
+ return misc.toArray(parsedObject.references).map(removeLeadingAndTrailingBrackets);
}
if (fieldHelpers.isFilled(parsedObject.inReplyTo)) {
return parsedObject.inReplyTo.split(' ').map(removeLeadingAndTrailingBrackets);
@@ -16,6 +16,7 @@ const fileWithTextAndHtml = 'test/mailarchive/testfiles/mailWithTextAndHtml';
const fileWithTextOnlyWithoutSenderName = 'test/mailarchive/testfiles/mailWithTextOnly';
const fileWithoutDate = 'test/mailarchive/testfiles/mailWithoutDate';
const fileWithReferences = 'test/mailarchive/testfiles/mailWithReferences';
+const fileWithOneReference = 'test/mailarchive/testfiles/mailWithOneReference';
const fileWithInReplyTo = 'test/mailarchive/testfiles/mailWithInReplyTo';
const fileWithoutMessageId = 'test/mailarchive/testfiles/mailWithoutMessageID';
@@ -124,6 +125,13 @@ describe('Import of mails from files with mime messages', () => {
});
});
+ it('imports a single reference', done => {
+ mailimport(fileWithOneReference, 'group', (err, result) => {
+ expect(result.references).to.eql(['message0@nomail.com']);
+ done(err);
+ });
+ });
+
it('imports reply-to as reference if no references are available', done => {
mailimport(fileWithInReplyTo, 'group', (err, result) => {
expect(result.references).to.eql(['message0@nomail.com', 'message1@nomail.com']);
@@ -0,0 +1,12 @@
+MIME-Version: 1.0
+In-Reply-To: <message0@nomail.com>
+References: <message0@nomail.com>
+Date: Mon, 25 Mar 2013 21:14:14 +0100
+Message-ID: <message2@nomail.com>
+Subject: Mail 2
+From: =?UTF-8?Q?Hei=C3=9Fen?= <some@mail.de>
+To: Craftsman swap softwerkskammer <craftsmanswap@softwerkskammer.de>
+
+
+Plain text message 2
+

0 comments on commit 8ca1ca4

Please sign in to comment.