-void do_unsubscribe(char *room, char *email, char *webpage) {
- struct ctdlroom qrbuf;
- FILE *ncfp;
- char filename[256];
- char token[256];
- char buf[512];
- char confirmation_request[2048];
- char urlroom[ROOMNAMELEN];
- char scancmd[256];
- char scanemail[256];
- int found_sub = 0;
-
- if (getroom(&qrbuf, room) != 0) {
- cprintf("%d There is no list called '%s'\n",
- ERROR + ROOM_NOT_FOUND, room);
- return;
- }
-
- if ((qrbuf.QRflags2 & QR2_SELFLIST) == 0) {
- cprintf("%d '%s' "
- "does not accept subscribe/unsubscribe requests.\n",
- ERROR + HIGHER_ACCESS_REQUIRED, qrbuf.QRname);
- return;
- }
-
- listsub_generate_token(token);
-
- assoc_file_name(filename, sizeof filename, &qrbuf, ctdl_netcfg_dir);
-
- /*
- * Make sure there's actually a subscription there to remove
- */
- begin_critical_section(S_NETCONFIGS);
- ncfp = fopen(filename, "r");
- if (ncfp != NULL) {
- while (fgets(buf, sizeof buf, ncfp) != NULL) {
- buf[strlen(buf)-1] = 0;
- extract_token(scancmd, buf, 0, '|', sizeof scancmd);
- extract_token(scanemail, buf, 1, '|', sizeof scanemail);
- if ((!strcasecmp(scancmd, "listrecp"))
- || (!strcasecmp(scancmd, "digestrecp"))) {
- if (!strcasecmp(scanemail, email)) {
- ++found_sub;
- }
- }
- }
- fclose(ncfp);
- }
- end_critical_section(S_NETCONFIGS);
-
- if (found_sub == 0) {
- cprintf("%d '%s' is not subscribed to '%s'.\n",
- ERROR + NO_SUCH_USER,
- email, qrbuf.QRname);
- return;
- }
-
- /*
- * Ok, now enter the unsubscribe-pending entry.
- */
- begin_critical_section(S_NETCONFIGS);
- ncfp = fopen(filename, "a");
- if (ncfp != NULL) {
- fprintf(ncfp, "unsubpending|%s|%s|%ld|%s\n",
- email,
- token,
- time(NULL),
- webpage
- );
- fclose(ncfp);
- }
- end_critical_section(S_NETCONFIGS);
-
- /* Generate and send the confirmation request */