void generate_subconfirm(struct ml *ml, const char *subaddr, enum subtype typesub,
enum subreason reasonsub, bool sub);
void send_confirmation_mail(struct ml *ml, const char *subaddr, enum subtype typesub, enum subreason reasonsub, bool sub);
+bool do_unsubscribe(struct ml *ml, const char *addr, enum subtype typesub, enum subreason reasonsub, bool inform_not_subscribed, bool confirm_unsubscription, bool quiet, bool send_goodbye_mail);
}
log_oper(ml->fd, OPLOGFNAME, "mlmmj-unsub: %s requests"
" unsubscribe", tll_front(*fromemails));
- exec_or_die(mlmmjunsub, "-L", ml->dir, "-a",
- tll_front(*fromemails), "-r",
- (nosubconfirm ? "-c" : "-C"), NULL);
+ do_unsubscribe(ml, tll_front(*fromemails), SUB_ALL, SUB_REQUEST,
+ false, !nosubconfirm, false, nosubconfirm);
+ exit(EXIT_SUCCESS);
break;
/* listname+unsubconf-digest-COOKIE@domain.tld */
int main(int argc, char **argv)
{
int opt;
- bool normal = false, digest = false, nomail = false, subbed;
- bool unsubconfirm = false, notifysub = false;
+ bool normal = false, digest = false, nomail = false;
+ bool unsubconfirm = false;
bool changeuid = true, quiet = false;
bool inform_not_subscribed = true;
bool send_goodbye_mail = false;
char *address = NULL;
- const char *subdir;
enum subtype typesub = SUB_ALL;
enum subreason reasonsub = SUB_ADMIN;
uid_t uid;
exit(0);
}
}
- if(ml.dir == 0 || address == 0) {
+ if(ml.dir == NULL || address == NULL) {
errx(EXIT_FAILURE, "You have to specify -L and -a\n"
"%s -h for help", argv[0]);
}
"%s -h for help", argv[0]);
}
- /* Make the address lowercase */
- address = lowercase(address);
-
if(changeuid) {
uid = getuid();
if(!uid && fstat(ml.fd, &st) == 0 && uid != st.st_uid) {
}
}
}
-
- if (typesub == SUB_ALL) {
- subbed = is_subbed(ml.fd, address, false) != SUB_NONE;
- } else {
- int subdirfd = open_subscriber_directory(ml.fd, typesub, &subdir);
- if (subdirfd == -1) {
- log_error(LOG_ARGS, "Could not opendir(%s/%s)", ml.dir, subdir);
- exit(EXIT_FAILURE);
- }
- subbed = is_subbed_in(subdirfd, subdir, address);
- }
-
- if(!subbed) {
- /* Address is not subscribed */
- if(inform_not_subscribed)
- generate_subscription(&ml, address, typesub, false);
- exit(EXIT_SUCCESS);
- }
-
- if(unsubconfirm)
- generate_subconfirm(&ml, address, typesub, reasonsub, false);
-
- unsubscribe(ml.fd, address, typesub);
-
- if(send_goodbye_mail)
- send_confirmation_mail(&ml, address, typesub, reasonsub, false);
-
- notifysub = !quiet && statctrl(ml.ctrlfd, "notifysub");
-
- /* Notify list owner about subscription */
- if (notifysub)
- notify_sub(&ml, address, typesub, reasonsub, false);
-
- free(address);
-
- return EXIT_SUCCESS;
+ if (do_unsubscribe(&ml, address, typesub, reasonsub, inform_not_subscribed,
+ unsubconfirm, quiet, send_goodbye_mail))
+ return(EXIT_SUCCESS);
+ return(EXIT_FAILURE);
}
#include "send_mail.h"
#include "strgen.h"
#include "send_help.h"
+#include "statctrl.h"
char *subtype_strs[] = {
"normal",
send_help_noexit(ml, queuefilename, subaddr);
}
+
+bool
+do_unsubscribe(struct ml *ml, const char *addr, enum subtype typesub,
+ enum subreason reasonsub, bool inform_not_subscribed,
+ bool confirm_unsubscription, bool quiet, bool send_goodbye_mail)
+{
+ char *address;
+ bool subscribed = false;
+
+ address = lowercase(addr);
+
+ if (typesub == SUB_ALL) {
+ subscribed = is_subbed(ml->fd, address, false) != SUB_NONE;
+ } else {
+ const char *subdir;
+ int fd = open_subscriber_directory(ml->fd, typesub, &subdir);
+ if (fd == -1) {
+ log_error(LOG_ARGS, "Could not opendir(%s/%s)", ml->dir,
+ subdir);
+ return (false);
+ }
+ subscribed = is_subbed_in(fd, subdir, address);
+ close(fd);
+ }
+
+ if (!subscribed) {
+ if (inform_not_subscribed)
+ generate_subscription(ml, address, typesub, false);
+ return (true);
+ }
+ if (confirm_unsubscription)
+ generate_subconfirm(ml, address, typesub, reasonsub, false);
+
+ unsubscribe(ml->fd, address, typesub);
+ if (send_goodbye_mail)
+ send_confirmation_mail(ml, address, typesub, reasonsub, false);
+
+ /* Notify list owner about subscription */
+ if (!quiet && statctrl(ml->ctrlfd, "notifysub"))
+ notify_sub(ml, address, typesub, reasonsub, false);
+
+ free(address);
+ return (true);
+}