1
0
mirror of https://github.com/eleith/emailjs.git synced 2024-06-25 16:29:04 +00:00

handle very large message text or data

This commit is contained in:
eleith 2012-07-25 01:23:21 -07:00
parent 8fc92a1307
commit 5bc846c269
7 changed files with 144500 additions and 28 deletions

View File

@ -1,12 +1,4 @@
# warning
please be aware that sending a string (large file attachments work fine) over 12k bytes long will crash the node process:
https://github.com/eleith/emailjs/issues?direction=desc&sort=created&state=open
this message will remain till the issue is closed.
# emailjs (v0.3.0) [![Build Status](https://secure.travis-ci.org/eleith/emailjs.png)](http://travis-ci.org/eleith/emailjs)
# emailjs (v0.3.1) [![Build Status](https://secure.travis-ci.org/eleith/emailjs.png)](http://travis-ci.org/eleith/emailjs)
send emails, html and attachments (files, streams and strings) from node.js to any smtp server

View File

@ -1,3 +1,3 @@
exports.server = require('./smtp/client');
exports.message = require('./smtp/message');
exports.SMTP = require('./smtp/smtp');
exports.server = require('./smtp/client');
exports.message = require('./smtp/message');
exports.SMTP = require('./smtp/smtp');

View File

@ -1,7 +1,7 @@
{
"name": "emailjs",
"description": "send text/html emails and attachments (files, streams and strings) from node.js to any smtp server",
"version": "0.3.0",
"version": "0.3.1",
"author": "eleith",
"contributors":["izuzak", "Hiverness", "mscdex"],
"repository":

View File

@ -378,22 +378,17 @@ var MessageStream = function(message)
var output_base64 = function(data, callback)
{
var loops = Math.floor(data.length / MIMECHUNK);
var leftover= Math.abs(data.length - loops*MIMECHUNK);
var loops = Math.ceil(data.length / MIMECHUNK);
var loop = 0;
var loop = function(index)
while(loop < loops)
{
if(index < loops)
output(data.substring(MIMECHUNK * index, MIMECHUNK * (index + 1)) + CRLF, loop, [index + 1]);
output(data.substring(MIMECHUNK * loop, MIMECHUNK * (loop + 1)) + CRLF);
loop++;
}
else if(leftover)
output(data.substring(index*MIMECHUNK) + CRLF, callback);
else if(callback)
callback();
};
loop(0);
if(callback)
callback();
};
var output_text = function(message)
@ -495,9 +490,23 @@ var MessageStream = function(message)
if(callback)
callback.apply(null, args);
}
// we can't buffer the data, so ship it out!
else if(bytes > self.buffer.length)
{
close({message:"internal buffer got too large to handle!"});
if(self.bufferIndex)
{
self.emit('data', self.buffer.toString("utf-8", 0, self.bufferIndex));
self.bufferIndex = 0;
}
var loops = Math.ceil(data.length / self.buffer.length);
var loop = 0;
while(loop < loops)
{
self.emit('data', data.substring(self.buffer.length*loop, self.buffer.length*(loop + 1)));
loop++;
}
}
else // we need to clean out the buffer, it is getting full
{

View File

@ -20,7 +20,7 @@ var AUTH_METHODS = {PLAIN:'PLAIN', CRAM_MD5:'CRAM-MD5', LOGIN:'LOGIN'};
var TIMEOUT = 5000;
var DEBUG = 0;
var log = function()
var log = function()
{
if(DEBUG)
{

144427
test/attachments/smtp.txt Normal file

File diff suppressed because it is too large Load Diff

View File

@ -77,6 +77,50 @@ describe("messages", function()
});
});
it("very large text message", function(done)
{
// thanks to jart+loberstech for this one!
var message =
{
subject: "this is a test TEXT message from emailjs",
from: "ninjas@gmail.com",
to: "pirates@gmail.com",
text: fs.readFileSync(path.join(__dirname, "attachments/smtp.txt"))
};
send(email.message.create(message), function(mail)
{
expect(mail.text).to.equal(message.text + "\n\n");
expect(mail.headers.subject).to.equal(message.subject);
expect(mail.headers.from).to.equal(message.from);
expect(mail.headers.to).to.equal(message.to);
done();
});
});
it("very large text data", function(done)
{
var text = "<html><body><pre>" + fs.readFileSync(path.join(__dirname, "attachments/smtp.txt"), "utf-8") + "</pre></body></html>";
var message =
{
subject: "this is a test TEXT+DATA message from emailjs",
from: "lobsters@gmail.com",
to: "lizards@gmail.com",
text: "hello friend if you are seeing this, you can not view html emails. it is attached inline.",
attachment: {data:text, alternative:true}
};
send(message, function(mail)
{
expect(mail.html).to.equal(text);
expect(mail.text).to.equal(message.text + "\n");
expect(mail.headers.subject).to.equal(message.subject);
expect(mail.headers.from).to.equal(message.from);
expect(mail.headers.to).to.equal(message.to);
done();
});
});
it("html data", function(done)
{
var html = fs.readFileSync(path.join(__dirname, "attachments/smtp.html"), "utf-8");