Compare commits
11 commits
9834f27b8e
...
25a7c37395
Author | SHA1 | Date | |
---|---|---|---|
|
25a7c37395 | ||
|
63403293d0 | ||
|
96410df84c | ||
|
96f60c972f | ||
|
f2194aab20 | ||
|
2bbf245d83 | ||
|
20c1ae0853 | ||
|
f515f19ef0 | ||
|
85fd43037e | ||
|
77a81edb55 | ||
|
c59def8afe |
5 changed files with 52 additions and 37 deletions
25
README.md
25
README.md
|
@ -6,25 +6,30 @@ On Github : https://github.com/JohnMcLear/ep_email_notifications
|
|||
|
||||
# Installation
|
||||
Make sure an SMTP gateway is installed IE postfix
|
||||
|
||||
Configure SPF and RDNS records to ensure proper mail flow <-- Search online
|
||||
|
||||
Copy/Edit the below to your settings.json
|
||||
|
||||
Connect to a pad, Click on the Share/Embed link and enter in your email address.
|
||||
|
||||
Open that pad in ANOTHER BROWSER then begin modifying, you should receive an email when the pad has begun editing and once the pad has gone stale (when everyone stops editing it and a time period passes).
|
||||
|
||||
NOTE: You will NOT receive an email if you(the author that registered their email) are currently on or editing that pad!
|
||||
|
||||
```
|
||||
"ep_email_notifications" : {
|
||||
panelDisplayLocation: { // Where you want to have the subscription panel
|
||||
mysettings: true, // In the "mysettings" menu
|
||||
popup: true // A popup that pop in the bottom right corner of the pad after 10 seconds
|
||||
"panelDisplayLocation": { // Where you want to have the subscription panel
|
||||
"mysettings": true,
|
||||
"popup": true
|
||||
},
|
||||
checkFrequency: 6000, // checkFrequency = How frequently(milliseconds) to check for pad updates -- Move me to the settings file
|
||||
staleTime: 30000, // staleTime = How stale(milliseconds) does a pad need to be before notifying subscribers? Move me to settings
|
||||
fromName: "Etherpad SETTINGS FILE!",
|
||||
fromEmail: "pad@etherpad.org",
|
||||
urlToPads: "http://beta.etherpad.org/p/", // urlToPads = The URL to your pads note the trailing /
|
||||
emailServer: { // See https://github.com/eleith/emailjs for settings
|
||||
host: "127.0.0.1"
|
||||
"checkFrequency": "6000", // checkFrequency = How frequently(milliseconds) to check for pad updates -- Move me to the settings file
|
||||
"staleTime": "30000", // staleTime = How stale(milliseconds) does a pad need to be before notifying subscribers? Move me to settings
|
||||
"fromName": "Etherpad SETTINGS FILE!",
|
||||
"fromEmail": "pad@etherpad.org",
|
||||
"urlToPads": "http://beta.etherpad.org/p/", // urlToPads = The URL to your pads note the trailing /
|
||||
"emailServer": { // See https://github.com/eleith/emailjs for settings
|
||||
"host": "127.0.0.1"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -28,9 +28,8 @@ exports.handleMessage = function(hook_name, context, callback){
|
|||
payload: true
|
||||
}
|
||||
});
|
||||
console.warn("Settings for ep_email_notifications plugin are missing in settings.json file");
|
||||
|
||||
callback([null]); // don't run onto passing colorId or anything else to the message handler
|
||||
console.error("Settings for ep_email_notifications plugin are missing in settings.json file");
|
||||
return callback([null]); // don't run onto passing colorId or anything else to the message handler
|
||||
|
||||
} else if (context.message.data.userInfo){
|
||||
if(context.message.data.userInfo.email){ // it contains email
|
||||
|
@ -39,6 +38,8 @@ exports.handleMessage = function(hook_name, context, callback){
|
|||
// does email (Un)Subscription already exist for this email address?
|
||||
db.get("emailSubscription:"+context.message.data.padId, function(err, userIds){
|
||||
|
||||
console.debug("emailSubscription");
|
||||
|
||||
var alreadyExists = false;
|
||||
|
||||
if(userIds){
|
||||
|
@ -101,7 +102,7 @@ exports.handleMessage = function(hook_name, context, callback){
|
|||
|
||||
}); // close db get
|
||||
|
||||
callback([null]); // don't run onto passing colorId or anything else to the message handler
|
||||
return callback([null]); // don't run onto passing colorId or anything else to the message handler
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -147,8 +148,7 @@ exports.handleMessage = function(hook_name, context, callback){
|
|||
);
|
||||
}
|
||||
});
|
||||
|
||||
callback([null]);
|
||||
return callback([null]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -173,6 +173,7 @@ exports.subscriptionEmail = function (context, email, emailFound, userInfo, padI
|
|||
padId
|
||||
);
|
||||
|
||||
console.debug("emailSubSucc");
|
||||
context.client.json.send({ type: "COLLABROOM",
|
||||
data:{
|
||||
type: "emailSubscriptionSuccess",
|
||||
|
@ -192,13 +193,13 @@ exports.subscriptionEmail = function (context, email, emailFound, userInfo, padI
|
|||
subject: "Email subscription confirmation for pad "+padId
|
||||
},
|
||||
function(err, message) {
|
||||
console.log(err || message);
|
||||
console.error(err || message);
|
||||
}
|
||||
);
|
||||
|
||||
} else if (!validatesAsEmail) {
|
||||
// Subscription -> failed coz mail malformed.. y'know in general fuck em!
|
||||
console.warn("Dropped email subscription due to malformed email address");
|
||||
console.debug("Dropped email subscription due to malformed email address");
|
||||
context.client.json.send({ type: "COLLABROOM",
|
||||
data:{
|
||||
type: "emailSubscriptionSuccess",
|
||||
|
@ -262,7 +263,7 @@ exports.unsubscriptionEmail = function (context, emailFound, userInfo, padId) {
|
|||
subject: "Email unsubscription confirmation for pad "+padId
|
||||
},
|
||||
function(err, message) {
|
||||
console.log(err || message);
|
||||
console.error(err || message);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
|
@ -298,8 +299,7 @@ exports.sendUserInfo = function (context, emailFound, email, userInfo) {
|
|||
|
||||
if (emailFound == true) {
|
||||
// We send back the options associated to this userId
|
||||
context.client.json.send({ type: "COLLABROOM",
|
||||
data:{
|
||||
var msg = {
|
||||
type: "emailNotificationGetUserInfo",
|
||||
payload: {
|
||||
email: email,
|
||||
|
@ -309,7 +309,9 @@ exports.sendUserInfo = function (context, emailFound, email, userInfo) {
|
|||
success:true
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
context.client.json.send({ type: "COLLABROOM", data: msg });
|
||||
|
||||
} else {
|
||||
// No options set for this userId
|
||||
context.client.json.send({ type: "COLLABROOM",
|
||||
|
|
3
index.js
3
index.js
|
@ -8,7 +8,8 @@ db['dbSettings'].cache = 0;
|
|||
|
||||
exports.registerRoute = function (hook_name, args, callback) {
|
||||
// Catching (un)subscribe addresses
|
||||
args.app.get('/p/*/(un){0,1}subscribe=*', function(req, res) {
|
||||
args.app.get(/\/p\/.*\/(un){0,1}subscribe=(.*)/, function(req, res) {
|
||||
console.warn("HERE");
|
||||
var fullURL = req.protocol + "://" + req.get('host') + req.url;
|
||||
var path=req.url.split("/");
|
||||
var padId=path[2];
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "ep_email_notifications",
|
||||
"description": "Subscribe to a pad and receive an email when someone edits your pad",
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.4",
|
||||
"author": {
|
||||
"name": "John Mclear",
|
||||
"email": "john@mclear.co.uk",
|
||||
|
|
17
update.js
17
update.js
|
@ -4,7 +4,8 @@
|
|||
async = require('../../src/node_modules/async'),
|
||||
check = require('validator').check,
|
||||
email = require('emailjs'),
|
||||
settings = require('../../src/node/utils/Settings');
|
||||
settings = require('../../src/node/utils/Settings'),
|
||||
util = require('util');
|
||||
|
||||
// Settings -- EDIT THESE IN settings.json not here..
|
||||
var pluginSettings = settings.ep_email_notifications;
|
||||
|
@ -22,6 +23,8 @@ var timers = {};
|
|||
// Connect to the email server -- This might not be the ideal place to connect but it stops us having lots of connections
|
||||
var server = email.server.connect(emailServer);
|
||||
|
||||
var emailFooter = "\nYou can unsubscribe from these emails in the pad's Settings window.\n";
|
||||
|
||||
exports.padUpdate = function (hook_name, _pad) {
|
||||
if (areParamsOk == false) return false;
|
||||
|
||||
|
@ -41,6 +44,11 @@ exports.padUpdate = function (hook_name, _pad) {
|
|||
}
|
||||
};
|
||||
|
||||
padUrl = function(padId, fmt) {
|
||||
fmt = fmt || "%s";
|
||||
return util.format(fmt, urlToPads + padId);
|
||||
}
|
||||
|
||||
exports.notifyBegin = function(padId){
|
||||
console.warn("Getting pad email stuff for "+padId);
|
||||
db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email
|
||||
|
@ -54,7 +62,7 @@ exports.notifyBegin = function(padId){
|
|||
if(!userIsOnPad && onStart){
|
||||
console.debug("Emailing "+recipient +" about a new begin update");
|
||||
server.send({
|
||||
text: "Your pad at "+urlToPads+padId +" is being edited, we're just emailing you let you know :)",
|
||||
text: "This pad is now being edited:\n" + padUrl(padId, " <%s>\n") + emailFooter,
|
||||
from: fromName+ "<"+fromEmail+">",
|
||||
to: recipient,
|
||||
subject: "Someone started editing "+padId
|
||||
|
@ -75,8 +83,7 @@ exports.notifyBegin = function(padId){
|
|||
}
|
||||
|
||||
exports.notifyEnd = function(padId){
|
||||
// get the modified contents...
|
||||
var changesToPad = "Functionality does not exist";
|
||||
// TODO: get the modified contents to include in the email
|
||||
|
||||
db.get("emailSubscription:" + padId, function(err, recipients){ // get everyone we need to email
|
||||
if(recipients){
|
||||
|
@ -90,7 +97,7 @@ exports.notifyEnd = function(padId){
|
|||
if(!userIsOnPad && onEnd){
|
||||
console.debug("Emailing "+recipient +" about a pad finished being updated");
|
||||
server.send({
|
||||
text: "Your pad at "+urlToPads+padId +" has finished being edited, we're just emailing you let you know :) \n\n The changes look like this: \n" + changesToPad,
|
||||
text: "This pad is done being edited:\n" + padUrl(padId, " <%s>\n") + emailFooter,
|
||||
from: fromName+ "<"+fromEmail+">",
|
||||
to: recipient,
|
||||
subject: "Someone finished editing "+padId
|
||||
|
|
Loading…
Reference in a new issue