diff --git a/imap-core/lib/imap-tools.js b/imap-core/lib/imap-tools.js index b81d1487..119ee5cb 100644 --- a/imap-core/lib/imap-tools.js +++ b/imap-core/lib/imap-tools.js @@ -664,7 +664,6 @@ module.exports.getQueryResponse = function(query, message, options) { if (!mimeTree) { mimeTree = indexer.parseMimeTree(message.raw); } - console.log(item); value = indexer.getContents(mimeTree, item, { startFrom: item.partial && item.partial.startFrom, maxLength: item.partial && item.partial.maxLength diff --git a/imap-core/test/prepare.sh b/imap-core/test/prepare.sh index d342d55e..8e199923 100755 --- a/imap-core/test/prepare.sh +++ b/imap-core/test/prepare.sh @@ -6,7 +6,7 @@ echo "Clearing DB" mongo "$DBNAME" --eval "db.getCollectionNames().forEach(function(key){db[key].deleteMany({});})" > /dev/null echo "Creating user" -USERRESPONSE=`curl --silent -XPOST http://localhost:8080/users \ +USERRESPONSE=`curl --silent -XPOST http://127.0.0.1:8080/users \ -H 'Content-type: application/json' \ -d '{ "username": "testuser", @@ -17,38 +17,38 @@ echo "UR: $USERRESPONSE" USERID=`echo "$USERRESPONSE" | jq -r '.id'` echo "Reading Mailbox ID" -MAILBOXLIST=`curl --silent "http://localhost:8080/users/$USERID/mailboxes"` +MAILBOXLIST=`curl --silent "http://127.0.0.1:8080/users/$USERID/mailboxes"` echo "ML: $MAILBOXLIST" echo "$MAILBOXLIST" | jq INBOXID=`echo "$MAILBOXLIST" | jq -r '.results[0].id'` SENTID=`echo "$MAILBOXLIST" | jq -r '.results[3].id'` -curl --silent -XPUT "http://localhost:8080/users/$USERID/mailboxes/$SENTID" \ +curl --silent -XPUT "http://127.0.0.1:8080/users/$USERID/mailboxes/$SENTID" \ -H 'Content-type: application/json' \ -d '{ "path": "[Gmail]/Sent Mail" }' -MAILBOXLIST=`curl --silent "http://localhost:8080/users/$USERID/mailboxes"` +MAILBOXLIST=`curl --silent "http://127.0.0.1:8080/users/$USERID/mailboxes"` echo "$MAILBOXLIST" | jq -curl --silent -XPOST "http://localhost:8080/users/$USERID/mailboxes/$INBOXID/messages?date=14-Sep-2013%2021%3A22%3A28%20-0300&unseen=true" \ +curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?date=14-Sep-2013%2021%3A22%3A28%20-0300&unseen=true" \ -H 'Content-type: message/rfc822' \ --data-binary "@fixtures/fix1.eml" -curl --silent -XPOST "http://localhost:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=false" \ +curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=false" \ -H 'Content-type: message/rfc822' \ --data-binary "@fixtures/fix2.eml" -curl --silent -XPOST "http://localhost:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=false" \ +curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=false" \ -H 'Content-type: message/rfc822' \ --data-binary "@fixtures/fix3.eml" -curl --silent -XPOST "http://localhost:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \ +curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \ -H 'Content-type: message/rfc822' \ --data-binary "@fixtures/fix4.eml" -curl --silent -XPOST "http://localhost:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \ +curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \ -H 'Content-type: message/rfc822' \ --data-binary "from: sender@example.com to: receiver@example.com @@ -57,7 +57,7 @@ subject: test5 hello 5 " -curl --silent -XPOST "http://localhost:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \ +curl --silent -XPOST "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages?unseen=true" \ -H 'Content-type: message/rfc822' \ --data-binary "from: sender@example.com to: receiver@example.com @@ -71,4 +71,4 @@ db.messages.updateOne({mailbox: ObjectId('$INBOXID'), uid:1}, {\$set:{modseq: 10 db.messages.updateOne({mailbox: ObjectId('$INBOXID'), uid:2}, {\$set:{modseq: 5000}}); db.messages.updateMany({}, {\$inc:{uid: 100}});" > /dev/null -# curl --silent "http://localhost:8080/users/$USERID/mailboxes/$INBOXID/messages" | jq +# curl --silent "http://127.0.0.1:8080/users/$USERID/mailboxes/$INBOXID/messages" | jq diff --git a/imap-core/test/protocol-test.js b/imap-core/test/protocol-test.js index fd66945f..ab8a1c60 100644 --- a/imap-core/test/protocol-test.js +++ b/imap-core/test/protocol-test.js @@ -18,9 +18,11 @@ describe('IMAP Protocol integration tests', function() { let port = 9993; beforeEach(function(done) { - exec(__dirname + '/prepare.sh ' + config.dbs.dbname, { cwd: __dirname }, (err /*, stdout, stderr*/) => { - // console.log(stdout.toString()); - // console.log(stderr.toString()); + exec(__dirname + '/prepare.sh ' + config.dbs.dbname, { cwd: __dirname }, (err, stdout, stderr) => { + if (process.env.DEBUG_CONSOLE) { + console.log(stdout.toString()); + console.log(stderr.toString()); + } if (err) { return done(err); } diff --git a/lib/api/messages.js b/lib/api/messages.js index e025721d..f2f8e71f 100644 --- a/lib/api/messages.js +++ b/lib/api/messages.js @@ -1821,7 +1821,17 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler) => { decode = false; } - let attachmentStream = messageHandler.attachmentStorage.createReadStream(attachmentId, attachmentData); + let attachmentStream; + try { + attachmentStream = messageHandler.attachmentStorage.createReadStream(attachmentId, attachmentData); + } catch (err) { + res.status(500); + res.json({ + error: 'Failed to read attachment', + code: 'InternalError' + }); + return next(); + } attachmentStream.once('error', err => { log.error('API', 'message=%s attachment=%s error=%s', messageData._id, attachmentId, err.message); diff --git a/lib/attachments/gridstore-storage.js b/lib/attachments/gridstore-storage.js index 269af92b..91f84401 100644 --- a/lib/attachments/gridstore-storage.js +++ b/lib/attachments/gridstore-storage.js @@ -291,6 +291,8 @@ class GridstoreStorage { } createReadStream(id, attachmentData, options) { + options = options || {}; + let encoderOptions = {}; let streamOptions = {}; diff --git a/test/filtering-test.js b/test/filtering-test.js index 4bf7b9b4..68bd493e 100644 --- a/test/filtering-test.js +++ b/test/filtering-test.js @@ -28,7 +28,7 @@ const transporter = nodemailer.createTransport({ const expect = chai.expect; chai.config.includeStack = true; -const URL = 'http://localhost:8080'; +const URL = 'http://127.0.0.1:8080'; const user2PubKey = fs.readFileSync(__dirname + '/fixtures/user2-public.key', 'utf-8'); const user3PubKey = fs.readFileSync(__dirname + '/fixtures/user3-public.key', 'utf-8');