Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send emails to accounts before they're deleted #25

Closed
retropc opened this issue Jan 30, 2016 · 6 comments
Closed

Send emails to accounts before they're deleted #25

retropc opened this issue Jan 30, 2016 · 6 comments

Comments

@retropc
Copy link
Member

retropc commented Jan 30, 2016

(self explanatory)

@retropc
Copy link
Member Author

retropc commented Jan 30, 2016

Comments from JIRA:

NaNg:

attached.
Note that this will not send a reminder to users who have reset their account in the last > CLEANUP_ACCOUNT_NOTIFY days due to the use of lockuntil value, but i think it can be assumed that > if they used a reset or such things they will try to re-auth.

retropc:

I'm not sure overleading lockuntil is a good idea, the logic for that is already extremely obtuse/complicated.

NaNg:

Attached (reminderemail) another diff with a new value,
Note that this needs DB altering:
ALTER TABLE chanserv.users ADD COLUMN reminderemail INT;
UPDATE chanserv.users SET reminderemail = 0;
ALTER TABLE chanserv.users ALTER COLUMN reminderemail SET NOT NULL;
for your consideration.

@retropc
Copy link
Member Author

retropc commented Jan 30, 2016

Patches by NaNg:

notify.diff:

diff -r f8a208449bdf chanserv/batcher/templates.py
--- a/chanserv/batcher/templates.py Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/batcher/templates.py Sat Aug 23 13:31:35 2014 +0200
@@ -139,6 +139,13 @@

    /AUTH %(user.username)s %(user.password)s
 """, },
+      7: { "subject": "%(config.bot)s account is about to expire", "body": """
+Your %(config.bot)s account is about to expire due to inactivity for %(config.cleanup)d days.
+
+Please consider reconnecting to the network and authenticating to your account to prevent it expiring.
+
+For more information please visit the %(config.bot)s help section at %(config.siteurl)s
+""", },
     },
   },
 }
diff -r f8a208449bdf chanserv/chanserv.h
--- a/chanserv/chanserv.h   Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/chanserv.h   Sat Aug 23 13:31:35 2014 +0200
@@ -96,6 +96,7 @@
 /* Cleanup options */
 #define CLEANUP_ACCOUNT_INACTIVE  180
 #define CLEANUP_ACCOUNT_UNUSED    3
+#define CLEANUP_ACCOUNT_NOTIFY    30
 #define CLEANUP_CHANNEL_INACTIVE  40

 #define CLEANUP_AUTHHISTORY      60
@@ -262,6 +263,7 @@
 #define QMAIL_RESET                4  /* reset account */
 #define QMAIL_NEWEMAIL             5  /* new email address */
 #define QMAIL_ACTIVATEEMAIL        6  /* new style new account */
+#define QMAIL_NOTIFYACCOUNT        7  /* notify when an account is about to expire */


 /* Channel flags */
diff -r f8a208449bdf chanserv/chanserv_cleanupdb.c
--- a/chanserv/chanserv_cleanupdb.c Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/chanserv_cleanupdb.c Sat Aug 23 13:31:35 2014 +0200
@@ -52,8 +52,8 @@
   regchanuser *rcup, *nrcup;
   authname *anp;
   int i,j;
-  time_t t, to_age, unused_age, maxchan_age, authhistory_age;
-  int expired = 0, unauthed = 0, chansvaped = 0;
+  time_t t, to_age, unused_age, notify_age, maxchan_age, authhistory_age;
+  int expired = 0, unauthed = 0, notified = 0, chansvaped = 0;
   chanindex *cip, *ncip;
   regchan *rcp;
   DBResult *pgres;
@@ -63,6 +63,7 @@
   t = time(NULL);
   to_age = t - (CLEANUP_ACCOUNT_INACTIVE * 3600 * 24);  
   unused_age = t - (CLEANUP_ACCOUNT_UNUSED * 3600 * 24);
+  notify_age = t - (CLEANUP_ACCOUNT_NOTIFY * 3600 * 24);
   maxchan_age = t - (CLEANUP_CHANNEL_INACTIVE * 3600 * 24);
   authhistory_age = t - (CLEANUP_AUTHHISTORY * 3600 * 24);

@@ -109,6 +110,13 @@
         } else if(!vrup->lastauth && (vrup->created < unused_age)) {
           unauthed++;
           cs_log(NULL, "CLEANUPDB unused user %s %u", vrup->username, vrup->ID);
+        } else if((vrup->lastauth && (vrup->lastauth < notify_age)) && (!vrup->lockuntil || vrup->lockuntil < notify_age)) {
+          notified++;
+          csdb_createmail(vrup, QMAIL_NOTIFYACCOUNT);
+          vrup->lockuntil = t;
+          csdb_updateuser(vrup);
+          cs_log(NULL, "CLEANUPDB notify user %s %u", vrup->username, vrup->ID);
+          continue;
         } else {
           continue;
         }
@@ -174,7 +182,7 @@

   csdb_cleanuphistories(authhistory_age);

-  cleanuplog("Stats: %d accounts inactive for %d days, %d accounts weren't used within %d days, %d channels were inactive for %d days.", expired, CLEANUP_ACCOUNT_INACTIVE, unauthed, CLEANUP_ACCOUNT_UNUSED, chansvaped, CLEANUP_CHANNEL_INACTIVE);
+  cleanuplog("Stats: %d accounts inactive for %d days, %d accounts weren't used within %d days, %d accounts were notified for expiry in %d days, %d channels were inactive for %d days.", expired, CLEANUP_ACCOUNT_INACTIVE, unauthed, CLEANUP_ACCOUNT_UNUSED, notified, CLEANUP_ACCOUNT_NOTIFY, chansvaped, CLEANUP_CHANNEL_INACTIVE);

 out:
   cleanupdb_active=0;

reminderemail.diff:

diff -r f8a208449bdf chanserv/authlib.c
--- a/chanserv/authlib.c    Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/authlib.c    Mon Aug 25 22:39:09 2014 +0200
@@ -199,6 +199,7 @@
   rup->suspendexp=0;
   rup->suspendtime=0;
   rup->lockuntil=0;
+  rup->reminderemail=0;
   strncpy(rup->password,password,PASSLEN); rup->password[PASSLEN]='\0';
   rup->email=getsstring(email,EMAILLEN);
   rup->lastemail=NULL;
diff -r f8a208449bdf chanserv/batcher/templates.py
--- a/chanserv/batcher/templates.py Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/batcher/templates.py Mon Aug 25 22:39:09 2014 +0200
@@ -139,6 +139,13 @@

    /AUTH %(user.username)s %(user.password)s
 """, },
+      7: { "subject": "%(config.bot)s account is about to expire", "body": """
+Your %(config.bot)s account is about to expire due to inactivity for %(config.cleanup)d days.
+
+Please consider reconnecting to the network and authenticating to your account to prevent it expiring.
+
+For more information please visit the %(config.bot)s help section at %(config.siteurl)s
+""", },
     },
   },
 }
diff -r f8a208449bdf chanserv/chanserv.h
--- a/chanserv/chanserv.h   Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/chanserv.h   Mon Aug 25 22:39:09 2014 +0200
@@ -96,6 +96,7 @@
 /* Cleanup options */
 #define CLEANUP_ACCOUNT_INACTIVE  180
 #define CLEANUP_ACCOUNT_UNUSED    3
+#define CLEANUP_ACCOUNT_NOTIFY    7
 #define CLEANUP_CHANNEL_INACTIVE  40

 #define CLEANUP_AUTHHISTORY      60
@@ -262,6 +263,7 @@
 #define QMAIL_RESET                4  /* reset account */
 #define QMAIL_NEWEMAIL             5  /* new email address */
 #define QMAIL_ACTIVATEEMAIL        6  /* new style new account */
+#define QMAIL_NOTIFYACCOUNT        7  /* notify when an account is about to expire */


 /* Channel flags */
@@ -601,6 +603,7 @@
   nick               *fakeuser;      /* If we had to "take" the nick, here's the pointer */

   time_t             lastpasschange;
+  time_t             reminderemail;

   struct reguser     *nextbydomain;
   struct reguser     *nextbyname;
diff -r f8a208449bdf chanserv/chanserv_cleanupdb.c
--- a/chanserv/chanserv_cleanupdb.c Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/chanserv_cleanupdb.c Mon Aug 25 22:39:09 2014 +0200
@@ -52,8 +52,8 @@
   regchanuser *rcup, *nrcup;
   authname *anp;
   int i,j;
-  time_t t, to_age, unused_age, maxchan_age, authhistory_age;
-  int expired = 0, unauthed = 0, chansvaped = 0;
+  time_t t, to_age, unused_age, notify_age, maxchan_age, authhistory_age;
+  int expired = 0, unauthed = 0, notified = 0, chansvaped = 0;
   chanindex *cip, *ncip;
   regchan *rcp;
   DBResult *pgres;
@@ -63,6 +63,7 @@
   t = time(NULL);
   to_age = t - (CLEANUP_ACCOUNT_INACTIVE * 3600 * 24);  
   unused_age = t - (CLEANUP_ACCOUNT_UNUSED * 3600 * 24);
+  notify_age = t - (CLEANUP_ACCOUNT_NOTIFY * 3600 * 24);
   maxchan_age = t - (CLEANUP_CHANNEL_INACTIVE * 3600 * 24);
   authhistory_age = t - (CLEANUP_AUTHHISTORY * 3600 * 24);

@@ -109,6 +110,13 @@
         } else if(!vrup->lastauth && (vrup->created < unused_age)) {
           unauthed++;
           cs_log(NULL, "CLEANUPDB unused user %s %u", vrup->username, vrup->ID);
+        } else if((vrup->lastauth && (vrup->lastauth < notify_age)) && (!vrup->reminderemail || vrup->reminderemail < notify_age)) {
+          notified++;
+          csdb_createmail(vrup, QMAIL_NOTIFYACCOUNT);
+          vrup->reminderemail = t;
+          csdb_updateuser(vrup);
+          cs_log(NULL, "CLEANUPDB notify user %s %u", vrup->username, vrup->ID);
+          continue;
         } else {
           continue;
         }
@@ -174,7 +182,7 @@

   csdb_cleanuphistories(authhistory_age);

-  cleanuplog("Stats: %d accounts inactive for %d days, %d accounts weren't used within %d days, %d channels were inactive for %d days.", expired, CLEANUP_ACCOUNT_INACTIVE, unauthed, CLEANUP_ACCOUNT_UNUSED, chansvaped, CLEANUP_CHANNEL_INACTIVE);
+  cleanuplog("Stats: %d accounts inactive for %d days, %d accounts weren't used within %d days, %d accounts were notified for expiry in %d days, %d channels were inactive for %d days.", expired, CLEANUP_ACCOUNT_INACTIVE, unauthed, CLEANUP_ACCOUNT_UNUSED, notified, CLEANUP_ACCOUNT_NOTIFY, chansvaped, CLEANUP_CHANNEL_INACTIVE);

 out:
   cleanupdb_active=0;
diff -r f8a208449bdf chanserv/chanservdb_updates.c
--- a/chanserv/chanservdb_updates.c Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/chanservdb_updates.c Mon Aug 25 22:39:09 2014 +0200
@@ -244,11 +244,11 @@

   dbquery("UPDATE chanserv.users SET lastauth=%lu, lastemailchng=%lu, flags=%u,"
          "language=%u, suspendby=%u, suspendexp=%lu, suspendtime=%lu, lockuntil=%lu, password='%s', email='%s',"
-         "lastuserhost='%s', suspendreason='%s', comment='%s', info='%s', lastemail='%s', lastpasschng=%lu "
+         "lastuserhost='%s', suspendreason='%s', comment='%s', info='%s', lastemail='%s', lastpasschng=%lu, reminderemail=%lu "
                   " WHERE ID=%u",
          rup->lastauth, rup->lastemailchange, rup->flags, rup->languageid, rup->suspendby, rup->suspendexp,
          rup->suspendtime, rup->lockuntil, escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail,
-                  rup->lastpasschange,
+                  rup->lastpasschange, rup->reminderemail,
          rup->ID);
 }  

@@ -297,12 +297,12 @@

   dbquery("INSERT INTO chanserv.users (ID, username, created, lastauth, lastemailchng, "
          "flags, language, suspendby, suspendexp, suspendtime, lockuntil, password, email, lastuserhost, "
-         "suspendreason, comment, info, lastemail, lastpasschng)"
-         "VALUES (%u,'%s',%lu,%lu,%lu,%u,%u,%u,%lu,%lu,%lu,'%s','%s','%s','%s','%s','%s','%s',%lu)",
+         "suspendreason, comment, info, lastemail, lastpasschng, reminderemail)"
+         "VALUES (%u,'%s',%lu,%lu,%lu,%u,%u,%u,%lu,%lu,%lu,'%s','%s','%s','%s','%s','%s','%s',%lu,%lu)",
          rup->ID, escusername, rup->created, rup->lastauth, rup->lastemailchange, rup->flags, 
          rup->languageid, rup->suspendby, rup->suspendexp, rup->suspendtime, rup->lockuntil,
          escpassword, escemail, esclastuserhost, escreason, esccomment, escinfo, esclastemail,
-                  rup->lastpasschange);
+                  rup->lastpasschange, rup->reminderemail);
 }  


diff -r f8a208449bdf chanserv/chanservuser.c
--- a/chanserv/chanservuser.c   Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/chanservuser.c   Mon Aug 25 22:39:09 2014 +0200
@@ -623,6 +623,7 @@
       rup->lastauth=0;
       rup->lastemailchange=0;
       rup->lastpasschange=0;
+      rup->reminderemail=0;
       rup->flags=QUFLAG_NOTICE;
       rup->languageid=0;
       rup->suspendby=0;
diff -r f8a208449bdf chanserv/database/chanservdb.c
--- a/chanserv/database/chanservdb.c    Sat Jul 19 23:12:53 2014 +0200
+++ b/chanserv/database/chanservdb.c    Mon Aug 25 22:39:09 2014 +0200
@@ -92,6 +92,7 @@
                "comment       VARCHAR(250),"
                "info          VARCHAR(100),"
                "lastpasschng  INT               NOT NULL,"
+               "reminderemail INT               NOT NULL,"
                "PRIMARY KEY (ID))");

   dbcreatequery("CREATE INDEX user_username_index ON chanserv.users (username)");
@@ -305,7 +306,7 @@
     return;
   }

-  if (dbnumfields(pgres)!=19) {
+  if (dbnumfields(pgres)!=20) {
     Error("chanserv",ERR_ERROR,"User DB format error");
     return;
   }
@@ -347,6 +348,7 @@
     rup->comment=getsstring(dbgetvalue(pgres,16),250);
     rup->info=getsstring(dbgetvalue(pgres,17),100);
     rup->lastpasschange=strtoul(dbgetvalue(pgres,18),NULL,10);
+    rup->reminderemail=strtoul(dbgetvalue(pgres,19),NULL,10);
     rup->knownon=NULL;
     rup->checkshd=NULL;
     rup->stealcount=0;

@retropc
Copy link
Member Author

retropc commented Jan 30, 2016

unless we can get around gmail marking our emails as spam: wontfix (because users will mark their expiring accounts they don't care about as spam)

@pandame
Copy link
Contributor

pandame commented Feb 14, 2016

If this is wontfix, any reason this issue is still open?

@retropc
Copy link
Member Author

retropc commented Feb 14, 2016

nope

@retropc retropc closed this as completed Feb 14, 2016
@retropc
Copy link
Member Author

retropc commented Feb 14, 2016

(bear in mind I spent a good hour porting these issues from JIRA, so there's a few that might not be in a perfect state)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants