Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

rename Message to MessageStream, expose it, and document it

  • Loading branch information...
commit 6efb5a023e0203d8c778482bc66c1ff8debace67 1 parent 762fefc
@aredridel authored
Showing with 40 additions and 18 deletions.
  1. +31 −11 doc/api.markdown
  2. +9 −7 lib/smtp.js
View
42 doc/api.markdown
@@ -113,20 +113,10 @@ The `'recipient'` object has the following properties:
### Event: 'DATA'
-`function(message) {}`
+`function(MessageStream) {}`
Emitted when the client begins sending message data.
-The `'message'` object has the following properties:
-
-* `'sender'`, the SMTP sender object
-* `'receivers'`, an array of SMTP receiver objects
-* `'connection'`, the `'smtp.Connection'` object
-* `'accepted'`, whether or not confirmation that the message has been
- received will be sent. Defaults to `false`. Can be set to `true` if you're
- sure you've really accepted responsibility for the message.
-
-It implements the `Readable Stream` interface.
### Event: 'RSET'
@@ -143,3 +133,33 @@ Emitted when the client quits, before the socket is closed
### Event: 'EXPN' (work in progress)
Emitted when the client issues an expand aliases command
+
+## smtp.MessageStream()
+
+An `EventEmitter` implementing the `Readable Stream` interface carrying the
+message data.
+
+### Properties
+
+* `'sender'`, the SMTP sender object
+* `'receivers'`, an array of SMTP receiver objects
+* `'connection'`, the `'smtp.Connection'` object
+* `'accepted'`, whether or not confirmation that the message has been
+ received will be sent. Defaults to `false`. Call `accept()` to accept the
+ message or `reject()` to reject it.
+
+### smtp.MessageStream.accept()
+
+Accepts the message, so the SMTP daemon will return a 2xx response.
+
+### smtp.MessageStream.reject()
+
+Rejects the message, so the SMTP daemon will return a 4xx/5xx response.
+
+### Event: accept
+
+Emitted when the message is accepted.
+
+### Event: reject
+
+Emitted when the message is rejected.
View
16 lib/smtp.js
@@ -15,19 +15,21 @@ var left = function (str, n) {
return String(str).substring(0,n);
}
-function Message() {
+function MessageStream() {
events.EventEmitter.call(this)
}
-sys.inherits(Message, events.EventEmitter)
+sys.inherits(MessageStream, events.EventEmitter)
-Message.prototype.pause = function() { this.emit('pause') }
-Message.prototype.resume = function() { this.emit('resume') }
+exports.MessageStream = MessageStream
-Message.prototype.accept = function() {
+MessageStream.prototype.pause = function() { this.emit('pause') }
+MessageStream.prototype.resume = function() { this.emit('resume') }
+
+MessageStream.prototype.accept = function() {
this.accepted = true
this.emit('accept')
}
-Message.prototype.reject = function() {
+MessageStream.prototype.reject = function() {
this.accepted = false
this.emit('reject')
}
@@ -144,7 +146,7 @@ function connectionListener(socket) {
} else if(line.match(/^DATA\b/i)) {
socket.state = 'data';
Out.out('354 Enter mail, end with "." on a line by itself');
- var message = new Message()
+ var message = new MessageStream()
socket.currentMessage = message
message.recipients = socket.recipients
message.sender = socket.sender
Please sign in to comment.
Something went wrong with that request. Please try again.