Skip to content

Commit bd83a4a

Browse files
committed
Add message.unsubscribe().
1 parent 4b0c4b6 commit bd83a4a

2 files changed

Lines changed: 39 additions & 46 deletions

File tree

changes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- added: `NEWOPERATION(name, fn(error, callback(response), value))` - registers a new operation (same as schemas)
2222
- added: `OPERATION('name', function(err, response))` - executes an operation (same as schemas)
2323
- added: `.flac` file extensions
24+
- added: a new method for `MailMessage` object `message.unsubscribe('your URL or email address')`
2425

2526
- updated: new error message `The field "@" is invalid.`
2627
- updated: `NOSQL().insert(doc, [unique])`

mail.js

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,15 @@ function Message(subject, body) {
101101
this.$callback;
102102
// Supports (but it's hidden):
103103
// this.headers;
104+
// this.$unsubscribe;
104105
}
105106

107+
Message.prototype.unsubscribe = function(url) {
108+
var tmp = url.substring(0, 6);
109+
this.$unsubscribe = tmp === 'http:/' || tmp === 'https:' ? '<' + url + '>' : '<mailto:' + url + '>';
110+
return this;
111+
};
112+
106113
Message.prototype.callback = function(fn) {
107114
this.$callback = fn;
108115
return this;
@@ -120,10 +127,9 @@ Message.prototype.from = function(address, name) {
120127
address = address.substring(index + 1, address.length - 1);
121128
}
122129

123-
var self = this;
124-
self.addressFrom.name = name || '';
125-
self.addressFrom.address = address;
126-
return self;
130+
this.addressFrom.name = name || '';
131+
this.addressFrom.address = address;
132+
return this;
127133
};
128134

129135
Message.prototype.to = function(address, name, clear) {
@@ -139,17 +145,15 @@ Message.prototype.to = function(address, name, clear) {
139145
address = address.substring(index + 1, address.length - 1);
140146
}
141147

142-
var self = this;
143-
144148
if (clear)
145-
self.addressTo = [];
149+
this.addressTo = [];
146150

147151
if (name)
148-
self.addressTo.push({ email: address, name: name });
152+
this.addressTo.push({ email: address, name: name });
149153
else
150-
self.addressTo.push(address);
154+
this.addressTo.push(address);
151155

152-
return self;
156+
return this;
153157
};
154158

155159
Message.prototype.cc = function(address, name, clear) {
@@ -165,60 +169,48 @@ Message.prototype.cc = function(address, name, clear) {
165169
address = address.substring(index + 1, address.length - 1);
166170
}
167171

168-
var self = this;
169-
170-
if (clear || !self.addressCC)
171-
self.addressCC = [];
172+
if (clear || !this.addressCC)
173+
this.addressCC = [];
172174

173175
if (name)
174-
self.addressCC.push({ email: address, name: name });
176+
this.addressCC.push({ email: address, name: name });
175177
else
176-
self.addressCC.push(address);
178+
this.addressCC.push(address);
177179

178-
return self;
180+
return this;
179181
};
180182

181183
Message.prototype.bcc = function(address, clear) {
182-
183-
var self = this;
184-
185-
if (clear || !self.addressBCC)
186-
self.addressBCC = [];
187-
188-
self.addressBCC.push(address);
189-
return self;
184+
if (clear || !this.addressBCC)
185+
this.addressBCC = [];
186+
this.addressBCC.push(address);
187+
return this;
190188
};
191189

192190
Message.prototype.reply = function(address, clear) {
193-
194-
var self = this;
195-
196-
if (clear || !self.addressReply)
197-
self.addressReply = [];
198-
199-
self.addressReply.push(address);
200-
return self;
191+
if (clear || !this.addressReply)
192+
this.addressReply = [];
193+
this.addressReply.push(address);
194+
return this;
201195
};
202196

203197
Message.prototype.attachment = function(filename, name) {
204-
var self = this;
205198
if (!name)
206199
name = framework_utils.getName(filename);
207200
var extension = framework_utils.getExtension(name);
208-
if (!self.files)
209-
self.files = [];
210-
self.files.push({ name: name, filename: filename, contentType: framework_utils.getContentType(extension), extension: extension });
211-
return self;
201+
if (!this.files)
202+
this.files = [];
203+
this.files.push({ name: name, filename: filename, contentType: framework_utils.getContentType(extension), extension: extension });
204+
return this;
212205
};
213206

214207
/**
215208
* Clears a timeout for sending emails (if the email is sent through the F.onMail)
216209
* @return {Message}
217210
*/
218211
Message.prototype.manually = function() {
219-
var self = this;
220-
self.$sending && clearTimeout(self.$sending);
221-
return self;
212+
this.$sending && clearTimeout(this.$sending);
213+
return this;
222214
};
223215

224216
/**
@@ -233,14 +225,13 @@ Message.prototype.manually = function() {
233225
* @returns {Message}
234226
*/
235227
Message.prototype.attachmentInline = function(filename, name, contentId) {
236-
var self = this;
237228
if (!name)
238229
name = framework_utils.getName(filename);
239-
if (!self.files)
240-
self.files = [];
230+
if (!this.files)
231+
this.files = [];
241232
var extension = framework_utils.getExtension(name);
242-
self.files.push({ name: name, filename: filename, contentType: framework_utils.getContentType(extension), disposition: 'inline', contentId: contentId, extension: extension });
243-
return self;
233+
this.files.push({ name: name, filename: filename, contentType: framework_utils.getContentType(extension), disposition: 'inline', contentId: contentId, extension: extension });
234+
return this;
244235
};
245236

246237
/**
@@ -566,6 +557,7 @@ Mailer.prototype._writemessage = function(obj, buffer) {
566557

567558
message.push('Date: ' + obj.date.toUTCString());
568559
message.push('Subject: ' + unicode_encode(msg.subject));
560+
msg.$unsubscribe && message.push('List-Unsubscribe: ' + msg.$unsubscribe);
569561

570562
if (msg.addressReply) {
571563
length = msg.addressReply.length;

0 commit comments

Comments
 (0)