std::string SubmitFile::QueueID() { char result[NUMBUFSIZE+1]; libmail_strh_ino_t(ctlinodenum, result); return std::string(result) + "." + basemsgid; }
static void print_uidl(unsigned i) { const char *p; if (enomem_1msg) /* Error recovery - out of disk space, see comments ** at the beginning of this file. */ { char dev_buf[NUMBUFSIZE]; char ino_buf[NUMBUFSIZE]; char mtime_buf[NUMBUFSIZE]; printed(printf("ENOMEM-%s-%s-%s\r\n", libmail_strh_time_t(enomem_stat.st_mtime, mtime_buf), libmail_strh_dev_t(enomem_stat.st_dev, dev_buf), libmail_strh_ino_t(enomem_stat.st_ino, ino_buf)) ); return; } if (msglist_a[i]->uid.n != 0) { /* VERSION 1 and VERSION 2 UIDL */ printed(printf((msglist_a[i]->uid.uidv ? "UID%lu-%lu\r\n":"UID%lu\r\n"), msglist_a[i]->uid.n, msglist_a[i]->uid.uidv)); return; } /* VERSION 0 UIDL */ p=strchr(msglist_a[i]->filename, '/')+1; while (*p && *p != MDIRSEP[0]) { if (*p < 0x21 || *p > 0x7E || *p == '\'' || *p == '"' || *p == '+') printed(printf("+%02X", (int)(unsigned char)*p)); else printchar(*p); ++p; } printed(printf("\r\n")); }
static int maildir_tmpcreate_fd_do(struct maildir_tmpcreate_info *info) { const char *maildir=info->maildir; const char *uniq=info->uniq; const char *hostname=info->hostname; char hostname_buf[256]; char time_buf[NUMBUFSIZE]; char usec_buf[NUMBUFSIZE]; char pid_buf[NUMBUFSIZE]; char len_buf[NUMBUFSIZE+3]; char dev_buf[NUMBUFSIZE]; char ino_buf[NUMBUFSIZE]; struct timeval tv; struct stat stat_buf; int fd; if (!maildir) maildir="."; if (!uniq) uniq=""; if (!hostname || !*hostname) { hostname_buf[sizeof(hostname_buf)-1]=0; if (gethostname(hostname_buf, sizeof(hostname_buf)-1) < 0) strcpy(hostname_buf, "localhost"); hostname=hostname_buf; } gettimeofday(&tv, NULL); libmail_str_time_t(tv.tv_sec, time_buf); libmail_str_time_t(tv.tv_usec, usec_buf); libmail_str_pid_t(getpid(), pid_buf); len_buf[0]=0; if (info->msgsize > 0) { strcpy(len_buf, ",S="); libmail_str_size_t(info->msgsize, len_buf+3); } if (info->tmpname) free(info->tmpname); info->tmpname=malloc(strlen(maildir)+strlen(uniq)+ strlen(hostname)+strlen(time_buf)+ strlen(usec_buf)+ strlen(pid_buf)+strlen(len_buf)+100); if (!info->tmpname) { maildir_tmpcreate_free(info); return -1; } strcpy(info->tmpname, maildir); strcat(info->tmpname, "/tmp/"); strcat(info->tmpname, time_buf); strcat(info->tmpname, ".M"); strcat(info->tmpname, usec_buf); strcat(info->tmpname, "P"); strcat(info->tmpname, pid_buf); if (*uniq) strcat(strcat(info->tmpname, "_"), uniq); strcat(info->tmpname, "."); strcat(info->tmpname, hostname); strcat(info->tmpname, len_buf); if (stat( info->tmpname, &stat_buf) == 0) { maildir_tmpcreate_free(info); errno=EAGAIN; return -1; } if (errno != ENOENT) { maildir_tmpcreate_free(info); if (errno == EAGAIN) errno=EIO; return -1; } if ((fd=maildir_safeopen_stat(info->tmpname, O_CREAT|O_RDWR|O_TRUNC, info->openmode, &stat_buf)) < 0) { maildir_tmpcreate_free(info); return -1; } libmail_strh_dev_t(stat_buf.st_dev, dev_buf); libmail_strh_ino_t(stat_buf.st_ino, ino_buf); if (info->newname) free(info->newname); info->newname=NULL; if (info->curname) free(info->curname); info->curname=NULL; info->newname=malloc(strlen(info->tmpname)+strlen(ino_buf)+ strlen(dev_buf)+3); if (info->newname) { info->curname=malloc(strlen(info->tmpname)+strlen(ino_buf)+ strlen(dev_buf)+3); if (!info->curname) { free(info->newname); info->newname=NULL; } } if (!info->newname) { maildir_tmpcreate_free(info); unlink(info->tmpname); close(fd); if (errno == EAGAIN) errno=EIO; return -1; } strcpy(info->newname, maildir); strcat(info->newname, "/new/"); strcat(info->newname, time_buf); strcat(info->newname, ".M"); strcat(info->newname, usec_buf); strcat(info->newname, "P"); strcat(info->newname, pid_buf); strcat(info->newname, "V"); strcat(info->newname, dev_buf); strcat(info->newname, "I"); strcat(info->newname, ino_buf); if (*uniq) strcat(strcat(info->newname, "_"), uniq); strcat(info->newname, "."); strcat(info->newname, hostname); strcat(info->newname, len_buf); strcpy(info->curname, info->newname); memcpy(info->curname + strlen(maildir)+1, "cur", 3); return fd; }
void SubmitFile::openctl() { std::string filename; ctlfile.close(); if (num_control_files_created == 0) // First recipient { for (;;) { const char *timeptr, *pidptr, *hostnameptr; getnewtmpfilenameargs(&timeptr, &pidptr, &hostnameptr); filename=name1stctlfile(); current_submit_file=this; int nfd=open(filename.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_EXCL | O_APPEND, PERMISSION); if (nfd >= 0) ctlfile.fd(nfd); if (nfd >= 0 || errno != EEXIST) break; current_submit_file=0; sleep(3); } ++num_control_files_created; if (ctlfile.fd() < 0) { // // One reason why we may not be able to create it // would be if the subdirectory, based on current time, // does not exist, so fork a tiny program to create it, // with the right permissions // pid_t p=fork(); pid_t w; int wait_stat; if (p == -1) { clog_msg_start_err(); clog_msg_str("fork: "); clog_msg_errno(); } if (p == 0) { filename=std::string(filename.begin(), std::find(filename.begin() , filename.end() , '/')); execl(LIBEXECDIR "/courier/submitmkdir", "submitmkdir", filename.c_str(), (char *)0); exit(0); } while ((w=wait(&wait_stat)) != p) if (w == -1 && errno == ECHILD) break; int nfd=open(filename.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_EXCL | O_APPEND, PERMISSION); if (nfd >= 0) ctlfile.fd(nfd); } } else { ++num_control_files_created; filename=namefile("C", num_control_files_created); int nfd=open(filename.c_str(), O_WRONLY | O_TRUNC | O_CREAT | O_EXCL | O_APPEND, PERMISSION); if (nfd >= 0) ctlfile.fd(nfd); } if (ctlfile.fd() < 0) clog_msg_errno(); struct stat stat_buf; char ino_buf[sizeof(ino_t)*2+1]; if (fstat(ctlfile.fd(), &stat_buf) != 0) clog_msg_errno(); rcptcount=0; if (num_control_files_created == 1) { char time_buf[sizeof(time_t)*2+1]; char pid_buf[sizeof(time_t)*2+1]; char msgidbuf[sizeof(time_buf)+sizeof(pid_buf)]; ctltimestamp=stat_buf.st_mtime; ctlpid=getpid(); strcat(strcat(strcpy(msgidbuf, libmail_strh_time_t(ctltimestamp, time_buf)), "."), libmail_strh_pid_t(getpid(), pid_buf)); basemsgid=msgidbuf; ctlinodenum=stat_buf.st_ino; } libmail_strh_ino_t( stat_buf.st_ino, ino_buf ); ctlfile << COMCTLFILE_SENDER << sender << std::endl << COMCTLFILE_FROMMTA << frommta << std::endl << COMCTLFILE_ENVID << envid << std::endl << COMCTLFILE_DSNFORMAT << dsnformat << std::endl << COMCTLFILE_MSGID << ino_buf << '.' << basemsgid << std::endl; if (submitdelay) ctlfile << COMCTLFILE_SUBMITDELAY << submitdelay << std::endl; ctlfile << std::flush; }