int resend_requeue(const char *listdir, const char *mlmmjsend)
{
-#if 0
DIR *queuedir;
struct dirent *dp;
-#endif
+ char *dirname = concatstr(2, listdir, "/requeue/");
+ char *archivefilename, *subfilename, *subnewname;
+ struct stat st;
+ pid_t pid;
+ time_t t;
- /* TODO: Go through all mails sitting in requeue/ and send the mail in the
- * archive marked by the directory name in requeue/ to the people in
- * the file subscribers sitting in the same dir.
- * IMPORTANT: do not forget to *not* archive and *not* delete when
- * sent.
- */
+ if(chdir(dirname) < 0) {
+ log_error(LOG_ARGS, "Could not chdir(%s)", dirname);
+ free(dirname);
+ return 1;
+ }
+
+ if((queuedir = opendir(dirname)) == NULL) {
+ log_error(LOG_ARGS, "Could not opendir(%s)", dirname);
+ free(dirname);
+ return 1;
+ }
+
+ while((dp = readdir(queuedir)) != NULL) {
+ if((strcmp(dp->d_name, "..") == 0) ||
+ (strcmp(dp->d_name, ".") == 0))
+ continue;
+
+ if(stat(dp->d_name, &st) < 0) {
+ log_error(LOG_ARGS, "Could not stat(%s)",dp->d_name);
+ continue;
+ }
+
+ if(!S_ISDIR(st.st_mode))
+ continue;
+
+ /* Remove old empty directories */
+ t = time(NULL);
+ if(t - st.st_mtime > (time_t)3600)
+ if(rmdir(dp->d_name) == 0)
+ continue;
+
+ archivefilename = concatstr(3, listdir, "/archive/",
+ dp->d_name);
+ if(stat(archivefilename, &st) < 0) {
+ /* Might be it's just not moved to the archive
+ * yet because it's still getting sent, so just
+ * continue
+ */
+ free(archivefilename);
+ continue;
+ }
+ subfilename = concatstr(3, dirname, dp->d_name, "/subscribers");
+ if(stat(subfilename, &st) < 0) {
+ log_error(LOG_ARGS, "Could not stat(%s)", subfilename);
+ free(archivefilename);
+ free(subfilename);
+ continue;
+ }
+
+ subnewname = concatstr(2, subfilename, ".resending");
+
+ if(rename(subfilename, subnewname) < 0) {
+ log_error(LOG_ARGS, "Could not rename(%s, %s)",
+ subfilename, subnewname);
+ free(archivefilename);
+ free(subfilename);
+ free(subnewname);
+ continue;
+ }
+ free(subfilename);
+
+ pid = fork();
+
+ if(pid == 0)
+ execlp(mlmmjsend, mlmmjsend,
+ "-l", "3",
+ "-L", listdir,
+ "-m", archivefilename,
+ "-s", subnewname,
+ "-a",
+ "-D", 0);
+
+
+ }
return 0;
}
if((c = strchr(myfrom, '@')) == NULL) {
free(myfrom);
- return 0; /* Success when mailformed 'from' */
+ return 0; /* Success when malformed 'from' */
}
*c = '\0';
num = strrchr(myfrom, '-');
{
printf("Usage: %s [-L /path/to/list || -l listctrl] -m /path/to/mail "
"[-a] [-D] [-F]\n"
- " [-h] [-r] [-R] [-T] [-V]\n"
+ " [-h] [-r] [-R] [-s] [-T] [-V]\n"
" -a: Don't archive the mail\n"
" -D: Don't delete the mail after it's sent\n"
" -F: What to use as MAIL FROM:\n"
" -h: This help\n"
- " -l: List control variable:\n"
- " '1' means 'send a single mail'\n"
+ " -l: List control variable:\n", prg);
+ printf(" '1' means 'send a single mail'\n"
" '2' means 'mail to moderators'\n"
" -L: Full path to list directory\n"
" -m: Full path to mail file\n"
" -r: Relayhost (defaults to localhost)\n"
" -R: What to use as Reply-To: header\n"
+ " -s: Subscribers file name\n"
" -T: What to use as RCPT TO:\n"
- " -V: Print version\n", prg);
+ " -V: Print version\n");
exit(EXIT_SUCCESS);
}
mlmmjbounce = concatstr(2, bindir, "/mlmmj-bounce");
free(bindir);
- while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:")) != -1){
+ while ((opt = getopt(argc, argv, "aVDhm:l:L:R:F:T:r:s:")) != -1){
switch(opt) {
case 'a':
archive = 0;
case 'R':
replyto = optarg;
break;
+ case 's':
+ subfilename = optarg;
+ break;
case 'T':
to_addr = optarg;
break;
exit(EXIT_FAILURE);
}
- if(listctrl[0] == '1' || listctrl[0] == '2')
+ if(listctrl[0] == '1' || listctrl[0] == '2' || listctrl[0] == '3')
archive = 0;
if(listdir)
exit(EXIT_SUCCESS);
}
break;
+ case '3': /* resending earlier failed mails */
+ if((subfile = fopen(subfilename, "r")) == NULL) {
+ log_error(LOG_ARGS, "Could not open '%s':",
+ subfilename);
+ exit(EXIT_FAILURE);
+ }
+
default: /* normal list mail -- now handled when forking */
break;
}
NULL, NULL, listdir, NULL);
endsmtp(&sockfd);
break;
+ case '3': /* resending earlier failed mails */
+ initsmtp(&sockfd, relayhost);
+ send_mail_many(sockfd, NULL, NULL, mailfile, subfile,
+ listaddr, mailfilename, listdir, mlmmjbounce);
+ endsmtp(&sockfd);
+ unlink(subfilename);
+ break;
default: /* normal list mail */
subddirname = concatstr(2, listdir, "/subscribers.d/");
if((subddir = opendir(subddirname)) == NULL) {
free(newsockfd);
fclose(subfile);
exit(EXIT_SUCCESS);
- } else {
- syslog(LOG_INFO, "%d/%d connections open",
- conncount, MAX_CONNECTIONS);
+ } else
fclose(subfile);
- }
}
closedir(subddir);
break;