static void show_preview(const char *filename) { char *header, *value; struct rfc2045 *rfcp; FILE *fp; int fd; fp=0; fd=maildir_safeopen(filename, O_RDONLY, 0); if (fd >= 0) if ((fp=fdopen(fd, "r")) == 0) close(fd); if (!fp) return; while ((header=maildir_readheader(fp, &value, 1)) != 0) { /* Don't show X-, From, and Content- headers in preview */ if (strncmp(header, "x-", 2) == 0) continue; if (strcmp(header, "mime-version") == 0) continue; if (strncmp(header, "content-", 8) == 0) continue; printf("%c", toupper(*header)); output_attrencoded_oknl(header+1); printf(": "); value=rfc2047_decode_enhanced(value, sqwebmail_content_charset); if (value) { output_attrencoded_oknl(value); free(value); } printf("\n"); } printf("\n"); rfcp=rfc2045_fromfp(fp); if (!rfcp) return; filter_start(FILTER_FOR_PREVIEW, &preview_show_func_s); { struct rfc2045 *q= rfc2045_searchcontenttype(rfcp, "text/plain"); if (q) rfc2045_decodemimesection(fileno(fp), q, &filter_stub, NULL); } rfc2045_free(rfcp); filter_end(); }
static int search_spell(const char *filename, unsigned parnum, unsigned pos) { struct rfc2045 *rfcp, *textp; struct buf newtext, current_line; off_t start_pos, end_pos, start_body; int made_replacements, has_misspelling; char *new_line; unsigned paragraph; const char *ignoreword=""; const char *replacefrom=""; const char *replaceto=""; int checked=0; off_t dummy; FILE *fp=0; int x; x=maildir_safeopen(filename, O_RDONLY, 0); if (x >= 0) if ((fp=fdopen(x, "r")) == 0) close(x); if (!fp) return (0); rfcp=rfc2045_fromfp(fp); if (!rfcp) enomem(); textp=findtext(rfcp); if (!textp) { rfc2045_free(rfcp); fclose(fp); return (0); } buf_init(&newtext); buf_init(¤t_line); rfc2045_mimepos(textp, &start_pos, &end_pos, &start_body, &dummy, &dummy); if (fseek(fp, start_body, SEEK_SET) == -1) enomem(); made_replacements=0; has_misspelling=0; paragraph=0; for ( ; start_body < end_pos; start_body++) { int c=getc(fp); if (c < 0) enomem(); if (c != '\n') { buf_append(¤t_line, c); continue; } buf_append(¤t_line, '\0'); if (parnum) { --parnum; buf_cat(&newtext, current_line.ptr); buf_cat(&newtext, "\n"); current_line.cnt=0; ++paragraph; continue; } if (!checked) { int l; checked=1; if ((l=strlen(cgi("word"))) > 0) { /* Ok, what should we do? */ const char *newword=cgi("REPLACE"); if (!*newword || strcmp(newword, "#other") == 0) newword=cgi("OTHER"); /* ** Perhaps they entered the word without ** checking this checkmark. */ else if (*newword == '#') newword=""; if (*newword && pos + l <= strlen(current_line.ptr)) { struct buf tempbuf; buf_init(&tempbuf); buf_cpyn(&tempbuf, current_line.ptr, pos); buf_cat(&tempbuf, newword); buf_cat(&tempbuf, current_line.ptr+pos+l); pos += strlen(newword); if (*cgi("REPLACEALL")) { replacefrom=cgi("word"); replaceto=newword; } buf_append(&tempbuf, '\0'); buf_cpy(¤t_line, tempbuf.ptr); buf_append(¤t_line, '\0'); buf_free(&tempbuf); made_replacements=1; } else { pos += l; if (strcmp(cgi("REPLACE"), "#ignoreall") == 0) ignoreword=cgi("word"); } if (strcmp(cgi("REPLACE"), "#insert") == 0) { spelladd(cgi("word")); } } } if (*current_line.ptr == '>') { buf_cat(&newtext, current_line.ptr); buf_cat(&newtext, "\n"); pos=0; current_line.cnt=0; ++paragraph; continue; } if (!has_misspelling) { new_line=spell_check(current_line.ptr, paragraph, pos, ignoreword, replacefrom, replaceto, &has_misspelling); if (new_line) { buf_cat(&newtext, new_line); free(new_line); made_replacements=1; } else buf_cat(&newtext, current_line.ptr); } else buf_cat(&newtext, current_line.ptr); buf_cat(&newtext, "\n"); pos=0; current_line.cnt=0; ++paragraph; } if (current_line.cnt) buf_cat(&newtext, "\n"); rfc2045_free(rfcp); fclose(fp); if (made_replacements) { char *p=newmsg_createdraft_do(filename, newtext.ptr, NEWMSG_SQISPELL); if (p) free(p); if (*cgi("error")) { has_misspelling=0; /* Abort spell checking */ } } buf_free(&newtext); buf_free(¤t_line); if (*ignoreword) { static char *p=0; if (p) free(p); p=malloc(strlen(cgi("globignore")) + 2 + strlen(ignoreword)); if (!p) enomem(); strcpy(p, cgi("globignore")); if (*p) strcat(p, ":"); strcat(p, ignoreword); cgi_put("globignore", p); } if (*replacefrom) { static char *p=0; if (p) free(p); p=malloc(strlen(cgi("globreplace"))+3 +strlen(replacefrom)+strlen(replaceto)); if (!p) enomem(); strcpy(p, cgi("globreplace")); if (*p) strcat(p, ":"); strcat(strcat(strcat(p, replacefrom), ":"), replaceto); cgi_put("globreplace", p); free(p); } if (has_misspelling) return (1); return (0); }
static int dosendmsg(const char *origdraft) { pid_t pid; const char *returnaddr; int pipefd1[2]; char *filename; const char *line; char *draftmessage; int isgpgerr; unsigned long filesize; struct stat stat_buf; int dsn; if (tokencheck()) /* Duplicate submission - message was already sent */ { sendmsg_done(); return (1); } if (strcmp(cgi("form"), "doattach") == 0) { /* When called from the attachment window, we do NOT create ** a new draft message */ draftmessage=strdup(origdraft); } else draftmessage=newmsg_createdraft(origdraft); if (!draftmessage) enomem(); filename=newmsg_createsentmsg(draftmessage, &isgpgerr, 1); if (!filename) { char *draftbase=maildir_basename(draftmessage); if (isgpgerr) { cgi_put("draftmessage", draftbase); output_form("gpgerr.html"); } else { http_redirect_argss("&form=newmsg&pos=%s" "&draft=%s&error=quota", cgi("pos"), draftbase); } free(draftmessage); free(draftbase); return (1); } if (pipe(pipefd1) != 0) { cgi_put("foldermsg", "ERROR: pipe() failed."); maildir_msgpurgefile(SENT, filename); free(filename); free(draftmessage); return (0); } returnaddr=login_returnaddr(); dsn= *cgi("dsn") != 0; pid=fork(); if (pid < 0) { cgi_put("foldermsg", "ERROR: fork() failed."); close(pipefd1[0]); close(pipefd1[1]); maildir_msgpurgefile(SENT, filename); free(filename); free(draftmessage); return (0); } if (pid == 0) { static const char noexec[]="ERROR: Unable to execute sendit.sh.\n"; static const char nofile[]="ERROR: Temp file not available - probably exceeded quota.\n"; char *tmpfile=maildir_find(SENT, filename); int fd; if (!tmpfile) { fwrite((char*)nofile, 1, sizeof(nofile)-1, stderr); _exit(1); } close(0); fd=maildir_safeopen(tmpfile, O_RDONLY, 0); close(1); close(2); dup(pipefd1[1]); dup(pipefd1[1]); close(pipefd1[0]); close(pipefd1[1]); if (dsn) putenv("DSN=-Nsuccess,delay,fail"); else putenv("DSN="); if (fd == 0) execl(SENDITSH, "sendit.sh", returnaddr, sqwebmail_mailboxid, NULL); fwrite(noexec, 1, sizeof(noexec)-1, stderr); _exit(1); } close(pipefd1[1]); line=geterrbuf(pipefd1[0]); close(pipefd1[0]); if (waitfor(pid)) { if (!*line) line="Unable to send message.\n"; } else line=""; if (*line == 0) /* Succesfully sent message */ { if (*draftmessage) { char *base=maildir_basename(draftmessage); char *draftfile=maildir_find(DRAFTS, base); free(base); /* Remove draft file */ if (draftfile) { char *replytofolder=0, *replytomsg=0; char *header, *value; FILE *fp; int x; fp=0; x=maildir_safeopen(draftfile, O_RDONLY, 0); if ( maildir_parsequota(draftfile, &filesize)) { if (x < 0 || fstat(x, &stat_buf)) stat_buf.st_size=0; filesize=stat_buf.st_size; } if (x >= 0) if ((fp=fdopen(x, "r")) == 0) close(x); /* First, look for a message that we should ** mark as replied */ while (fp && (header=maildir_readheader(fp, &value, 0)) != 0) { if (strcmp(header,"x-reply-to-folder") == 0 && !replytofolder) { replytofolder=strdup(value); if (!replytofolder) enomem(); } if (strcmp(header,"x-reply-to-msg") == 0 && !replytomsg) { replytomsg=strdup(value); if (!replytomsg) enomem(); } if (replytofolder && replytomsg) break; } if (fp) fclose(fp); if (replytofolder && replytomsg) maildir_markreplied(replytofolder, replytomsg); if (replytofolder) free(replytofolder); if (replytomsg) free(replytomsg); maildir_quota_deleted(".", -(long)filesize, -1); unlink(draftfile); free(draftfile); } } tokensave(); if (*cgi("fcc") == 0) { unsigned long filesize=0; char *tmpfile=maildir_find(SENT, filename); if (tmpfile) { maildir_parsequota(tmpfile, &filesize); unlink(tmpfile); maildir_quota_deleted(".", -(long)filesize,-1); free(tmpfile); } } free(filename); free(draftmessage); sendmsg_done(); return (1); } if (stat(filename, &stat_buf) == 0) maildir_quota_deleted(".", -(long)stat_buf.st_size, -1); maildir_msgpurgefile(SENT, filename); free(filename); { char *draftbase=maildir_basename(draftmessage); http_redirect_argsss("&form=newmsg&pos=%s&draft=%s&foldermsg=%s", cgi("pos"), draftbase, line); free(draftmessage); free(draftbase); } return (1); }
void newmsg_init(const char *folder, const char *pos) { const char *tolab=getarg("TOLAB"); const char *cclab=getarg("CCLAB"); const char *bcclab=getarg("BCCLAB"); const char *subjectlab=getarg("SUBJECTLAB"); const char *messagelab=getarg("MESSAGELAB"); const char *sendlab=getarg("SENDLAB"); const char *previewlab=getarg("PREVIEWLAB"); const char *forwardsep=getarg("FORWARDLAB"); const char *savedraft=getarg("SAVEDRAFT"); const char *uploadlab=getarg("UPLOAD"); const char *attachedlab=getarg("ATTACHMENTS"); const char *replysalutation=getarg("SALUTATION"); const char *checkspellingdone=getarg("SPELLCHECKDONE"); const char *checkspelling=getarg("CHECKSPELLING"); const char *quotaerr=getarg("QUOTAERR"); const char *fromlab=getarg("FROMLAB"); const char *replytolab=getarg("REPLYTOLAB"); const char *addressbooklab=getarg("ADDRESSBOOK"); char *draftmessage; char *draftmessagefilename; const char *p; FILE *fp; int attachcnt=0; char *cursubj, *curto, *curcc, *curbcc, *curfrom, *curreplyto; /* Picking up an existing draft? */ p=cgi("draft"); if (*p) { CHECKFILENAME(p); } if (*p) { draftmessage=strdup(p); if (!draftmessage) enomem(); p=""; } else { draftmessage=newmsg_newdraft(folder, pos, forwardsep, replysalutation); if (!draftmessage) { if (*ispreviewmsg()) { p=cgi("draftmessage"); if (*p) { CHECKFILENAME(p); } draftmessage=newmsg_createdraft(p); } } } draftmessagefilename= draftmessage ? maildir_find(DRAFTS, draftmessage):0; if (*(p=cgi("previewmsg"))) { #ifdef ISPELL if (strcmp(p, "SPELLCHK") == 0) printf("%s<BR><BR>\n", checkspellingdone); #endif printf("<TABLE WIDTH=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=1 CLASS=\"box-small-outer\"><TR><TD>\n"); printf("<TABLE WIDTH=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=4 CLASS=\"preview\"><TR><TD>\n"); if (draftmessagefilename) { const char *p=strrchr(draftmessagefilename, '/'); if (p) ++p; else p=draftmessagefilename; newmsg_preview(p); } printf("</TD></TR></TABLE>\n"); printf("</TD></TR></TABLE>\n"); printf("<TABLE WIDTH=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=6><TR><TD><HR WIDTH=\"80%%\"></TD></TR></TABLE>\n"); } printf("<INPUT TYPE=HIDDEN NAME=form VALUE=\"donewmsg\">\n"); newmsg_hiddenheader("pos", pos); newmsg_hiddenheader("focusto", *cgi("newmsg") ? "headers":"text"); /* Generate unique message token, to detect duplicate SUBMITs */ tokennew(); /* Display any error message */ if (*cgi("foldermsg")) { printf("<P><FONT CLASS=\"error\" COLOR=\"#FF0000\">"); output_attrencoded_nltobr(cgi("foldermsg")); printf("</FONT><BR>"); } if (strcmp(cgi("error"), "quota") == 0) printf("%s", quotaerr); /* Read message from the draft file */ cursubj=0; curto=0; curfrom=0; curreplyto=0; curcc=0; curbcc=0; fp=0; if (draftmessagefilename) { int x=maildir_safeopen(draftmessagefilename, O_RDONLY, 0); if (x >= 0) if ((fp=fdopen(x, "r")) == 0) close(x); } if (fp != 0) { char *header, *value; while ((header=maildir_readheader(fp, &value, 0)) != 0) { char **rfchp=0; if (strcmp(header, "subject") == 0) { if (!cursubj && !(cursubj=strdup(value))) enomem(); continue; } if (strcmp(header, "from") == 0) rfchp= &curfrom; if (strcmp(header, "reply-to") == 0) rfchp= &curreplyto; if (strcmp(header, "to") == 0) rfchp= &curto; if (strcmp(header, "cc") == 0) rfchp= &curcc; if (strcmp(header, "bcc") == 0) rfchp= &curbcc; if (rfchp) { char *newh=malloc ( (*rfchp ? strlen(*rfchp)+2:1) +strlen(value)); if (!newh) enomem(); strcpy(newh, value); if (*rfchp) strcat(strcat(newh, ","), *rfchp); if (*rfchp) free( *rfchp ); *rfchp=newh; } } } //printf("<TABLE WIDTH=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=1 CLASS=\"box-small-outer\"><TR><TD>\n"); printf("<TABLE WIDTH=\"100%%\" BORDER=0 CELLSPACING=0 CELLPADDING=4 CLASS=\"new-message-box\"><TR><TD>\n"); printf("<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=1 WIDTH=\"100%%\">\n"); /* by lfan if (access(NOCHANGINGFROM, 0)) newmsg_header(fromlab, "headerfrom", curfrom ? curfrom: *cgi("from") ? cgi("from"): pref_from && *pref_from ? pref_from: login_fromhdr()); printf("<TR VALIGN=MIDDLE><TH ALIGN=RIGHT>" "<P CLASS=\"new-message-header\">" "<FONT CLASS=\"new-message-header-addressbook\">" "%s</FONT></TD><TD WIDTH=6> </TH>", addressbooklab); */ printf("<TR VALIGN=MIDDLE><TD ALIGN=RIGHT CLASS=\"new-message-header\">" "%s</TD><TD WIDTH=6> </TD>", addressbooklab); printf("<TD VALIGN=MIDDLE>"); printf("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>"); //printf("<TR VALIGN=MIDDLE><TD><SELECT NAME=\"nick\" SIZE=4 MULTIPLE>\n"); printf("<TR VALIGN=MIDDLE><TD><SELECT NAME=\"nick\">\n"); ab_listselect(); printf("</select></TD><TD WIDTH=\"100%%\">"); printf(" <input type=submit class=mybtn name=\"addressbook_to\" value=\"%s\">", tolab); printf(" <input type=submit class=mybtn name=\"addressbook_cc\" value=\"%s\">", cclab); printf(" <input type=submit class=mybtn name=\"addressbook_bcc\" value=\"%s\">", bcclab); printf("</TD></TR></TABLE>"); printf("</TD></TR>\n"); newmsg_header(tolab, "headerto", curto ? curto:cgi("to")); newmsg_header(cclab, "headercc", curcc ? curcc:cgi("cc")); newmsg_header(bcclab, "headerbcc", curbcc ? curbcc:cgi("bcc")); // by lfan //newmsg_header(replytolab, "headerreply-to", curreplyto ? curreplyto:cgi("replyto")); newmsg_header(subjectlab, "headersubject", cursubj ? cursubj:cgi("subject")); if (curto) free(curto); if (curfrom) free(curfrom); if (curreplyto) free(curreplyto); if (curcc) free(curcc); if (curbcc) free(curbcc); if (cursubj) free(cursubj); printf("<TR><TD COLSPAN=3><HR WIDTH=\"100%%\"></TD></TR>"); /* by lfan printf("<TR><TH VALIGN=TOP ALIGN=RIGHT>" "<P CLASS=\"new-message-header\">" "<FONT CLASS=\"new-message-header-message\">" "%s</FONT></P></TD><TD WIDTH=6> </TD>", messagelab); */ printf("<TR><TD WIDTH=60 VALIGN=TOP ALIGN=RIGHT CLASS=\"ctype\">" "%s</TD><TD WIDTH=6> </TD>", messagelab); printf("<TD><TEXTAREA NAME=message COLS=%d ROWS=15 WRAP=soft>", MYLINESIZE); if (fp) { newmsg_showfp(fp, &attachcnt); } else { printf("%s", cgi("body")); if ((fp=fopen(SIGNATURE, "r")) != NULL) { char buf[256]; int n; printf("\n\n"); while ((n=fread(buf, 1, sizeof(buf)-1, fp)) > 0) { buf[n]=0; output_attrencoded_oknl(buf); } fclose(fp); fp=NULL; } } printf("</TEXTAREA><BR>\n"); if (draftmessage && *draftmessage) { printf("<INPUT TYPE=HIDDEN NAME=draftmessage VALUE=\""); output_attrencoded(draftmessage); printf("\">"); } if (draftmessage) free(draftmessage); printf("</TD></TR>\n"); //by lfan printf("<TR><TD> </TD><TD> </TD><TD>"); printf("<INPUT TYPE=CHECKBOX " "NAME=fcc%s><FONT class=ctype>%s</FONT> \n", pref_noarchive ? "":" CHECKED", getarg("PRESERVELAB")); if (access(NODSN, R_OK)) printf("<TR><TD COLSPAN=2 ALIGN=RIGHT><INPUT TYPE=CHECKBOX " "NAME=dsn></TD><TD>%s</TD></TR>\n", getarg("DSN")); #if HAVE_SQWEBMAIL_UNICODE if (has_gpg(GPGDIR) == 0) { char *all_addr; printf("<TR><TD COLSPAN=2 ALIGN=RIGHT><INPUT TYPE=CHECKBOX " "NAME=sign></TD><TD>%s<SELECT NAME=signkey>", getarg("SIGNLAB")); gpgselectkey(); printf("</SELECT></TD></TR>\n"); all_addr=newmsg_alladdrs(fp); printf("<TR VALIGN=MIDDLE><TD COLSPAN=2 ALIGN=RIGHT>" "<INPUT TYPE=CHECKBOX NAME=encrypt></TD>" "<TD><TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 VALIGN=MIDDLE><TR><TD>%s</TD><TD><SELECT SIZE=4 MULTIPLE NAME=encryptkey>", getarg("ENCRYPTLAB")); gpgencryptkeys(all_addr); printf("</SELECT></TD></TR>\n"); printf("</TABLE></TD></TR>\n"); if (ishttps()) printf("<TR><TD COLSPAN=2 ALIGN> </TD><TD>%s<input type=password name=passphrase></TD></TR>\n", getarg("PASSPHRASE")); if (all_addr) free(all_addr); } #endif if (fp) fclose(fp); if (draftmessagefilename) free(draftmessagefilename); //printf("<TR><TD COLSPAN=2> </TD><TD>"); //printf("<INPUT CLASS=mybtn TYPE=SUBMIT NAME=previewmsg VALUE=\"%s\">", // previewlab); printf("<INPUT CLASS=mybtn TYPE=SUBMIT NAME=sendmsg onclick=\"return check();\" VALUE=\"%s\"> ", sendlab); printf("<INPUT CLASS=mybtn TYPE=SUBMIT NAME=previewmsg VALUE=\"%s\"> ", previewlab); printf("<INPUT CLASS=mybtn TYPE=SUBMIT NAME=savedraft VALUE=\"%s\"> ", savedraft); printf("<INPUT CLASS=\"mybtn\" TYPE=SUBMIT NAME=doattachments VALUE=\""); printf(uploadlab); printf("\"> "); printf(attachedlab, attachcnt); #ifdef ISPELL printf("<INPUT TYPE=SUBMIT NAME=startspellchk VALUE=\"%s\">", checkspelling); #endif printf("</TD></TR>\n"); printf("</TD></TABLE>\n"); printf("</TD></TR></TABLE>\n"); //printf("</TD></TR></TABLE>\n"); }
void newmsg_init(const char *folder, const char *pos) { const char *tolab=getarg("TOLAB"); const char *cclab=getarg("CCLAB"); const char *bcclab=getarg("BCCLAB"); const char *subjectlab=getarg("SUBJECTLAB"); const char *messagelab=getarg("MESSAGELAB"); const char *sendlab=getarg("SENDLAB"); const char *previewlab=getarg("PREVIEWLAB"); const char *forwardsep=getarg("FORWARDLAB"); const char *savedraft=getarg("SAVEDRAFT"); const char *attachmentslab=getarg("ATTACHMENTS"); const char *uploadlab=getarg("UPLOAD"); const char *replysalutation=getarg("SALUTATION"); const char *checkspellingdone=getarg("SPELLCHECKDONE"); const char *checkspelling=getarg("CHECKSPELLING"); const char *quotaerr=getarg("QUOTAERR"); const char *fromlab=getarg("FROMLAB"); const char *replytolab=getarg("REPLYTOLAB"); const char *addressbooklab=getarg("ADDRESSBOOK"); const char *select1=getarg("SELECT1"); const char *select2=getarg("SELECT2"); const char *text1=getarg("TEXT1"); const char *text2=getarg("TEXT2"); char *draftmessage; char *draftmessagefilename; const char *p; FILE *fp; int attachcnt=0; char *cursubj, *curto, *curcc, *curbcc, *curfrom, *curreplyto; int wbnochangingfrom; /* Picking up an existing draft? */ p=cgi("draft"); if (*p) { CHECKFILENAME(p); } if (*p) { draftmessage=strdup(p); if (!draftmessage) enomem(); p=""; } else { draftmessage=newmsg_newdraft(folder, pos, forwardsep, replysalutation); if (!draftmessage) { if (*ispreviewmsg()) { p=cgi("draftmessage"); if (*p) { CHECKFILENAME(p); } draftmessage=newmsg_createdraft(p); } } } draftmessagefilename= draftmessage ? maildir_find(INBOX "." DRAFTS, draftmessage):0; if (*(p=cgi("previewmsg"))) { #ifdef ISPELL if (strcmp(p, "SPELLCHK") == 0) printf("%s<br /><br />\n", checkspellingdone); #endif printf("<table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\" class=\"box-small-outer\"><tr><td>\n"); printf("<table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\" class=\"preview\"><tr><td>\n"); if (draftmessagefilename) { const char *p=strrchr(draftmessagefilename, '/'); if (p) ++p; else p=draftmessagefilename; newmsg_preview(p); } printf("</td></tr></table>\n"); printf("</td></tr></table>\n"); printf("<table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"6\"><tr><td><hr width=\"80%%\" /></td></tr></table>\n"); } printf("<input type=\"hidden\" name=\"form\" value=\"donewmsg\" />\n"); newmsg_hiddenheader("pos", pos); newmsg_hiddenheader("focusto", *cgi("newmsg") ? "headers":"text"); /* Generate unique message token, to detect duplicate SUBMITs */ tokennew(); /* Display any error message */ if (*cgi("foldermsg")) { printf("<p><span class=\"error\" style=\"color: #ff0000\">"); output_attrencoded_nltobr(cgi("foldermsg")); printf("</span></p>"); } if (strcmp(cgi("error"), "quota") == 0) printf("%s", quotaerr); /* Read message from the draft file */ cursubj=0; curto=0; curfrom=0; curreplyto=0; curcc=0; curbcc=0; fp=0; if (draftmessagefilename) { int x=maildir_safeopen(draftmessagefilename, O_RDONLY, 0); if (x >= 0) if ((fp=fdopen(x, "r")) == 0) close(x); } if (fp != 0) { char *header, *value; while ((header=maildir_readheader(fp, &value, 0)) != 0) { char **rfchp=0; if (strcmp(header, "subject") == 0) { if (!cursubj && !(cursubj=strdup(value))) enomem(); continue; } while (*value && isspace(*value)) ++value; if (strcmp(header, "from") == 0) rfchp= &curfrom; if (strcmp(header, "reply-to") == 0) rfchp= &curreplyto; if (strcmp(header, "to") == 0) rfchp= &curto; if (strcmp(header, "cc") == 0) rfchp= &curcc; if (strcmp(header, "bcc") == 0) rfchp= &curbcc; if (rfchp) { char *newh=malloc ( (*rfchp ? strlen(*rfchp)+2:1) +strlen(value)); if (!newh) enomem(); strcpy(newh, value); if (*rfchp) strcat(strcat(newh, ","), *rfchp); if (*rfchp) free( *rfchp ); *rfchp=newh; } } } printf("<table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\" class=\"box-small-outer\"><tr><td>\n"); printf("<table width=\"100%%\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\" class=\"new-message-box\"><tr><td>\n"); printf("<table border=\"0\" width=\"100%%\">\n"); wbnochangingfrom=auth_getoptionenvint("wbnochangingfrom"); if (wbnochangingfrom < 2) newmsg_header_rfc822(fromlab, "headerfrom", curfrom, *cgi("from") ? cgi("from"): pref_from && *pref_from ? pref_from: login_fromhdr(), wbnochangingfrom ? 1:0); printf("<tr valign=\"middle\"><th align=\"right\">" "<p class=\"new-message-header\">" "<span class=\"new-message-header-addressbook\">" "%s</span></p></th><td width=\"6\"> </td>", addressbooklab); printf("<td valign=\"middle\">"); printf("<table border=\"0\" cellpadding=\"0\" cellspacing=\"4\">"); printf("<tr valign=\"middle\"><td>%s\n", select1); ab_listselect(); printf("%s</td><td width=\"100%%\">", select2); printf("<input type=\"submit\" name=\"addressbook_to\" value=\"%s\" />", tolab); printf("<input type=\"submit\" name=\"addressbook_cc\" value=\"%s\" />", cclab); printf("<input type=\"submit\" name=\"addressbook_bcc\" value=\"%s\" />", bcclab); printf("</td></tr></table>"); printf("</td></tr>\n"); #if 0 { FILE *fp; fp=fopen("/tmp/pid", "w"); fprintf(fp, "%d", getpid()); fclose(fp); sleep(10); } #endif newmsg_header_rfc822(tolab, "headerto", curto, cgi("to"), 0); newmsg_header_rfc822(cclab, "headercc", curcc, cgi("cc"), 0); newmsg_header_rfc822(bcclab, "headerbcc", curbcc, cgi("bcc"), 0); newmsg_header_rfc822(replytolab, "headerreply-to", curreplyto, cgi("replyto"), 0); newmsg_header(subjectlab, "headersubject", cursubj, cgi("subject")); if (curto) free(curto); if (curfrom) free(curfrom); if (curreplyto) free(curreplyto); if (curcc) free(curcc); if (curbcc) free(curbcc); if (cursubj) free(cursubj); printf("<tr><td colspan=\"3\"><hr width=\"100%%\" /></td></tr>"); printf("<tr>" "<th valign=\"top\" align=\"right\">" "<p class=\"new-message-header\">" "<span class=\"new-message-header-message\">" "%s</span></p></th><td width=\"6\"> </td>" "<td><select name=\"textformat\">" "<option value=\"plain\" %s>%s</option>" "<option value=\"wiki\" %s>%s</option></select>" "<small>(<a href='%s/wikifmt.html' target='_blank'>%s</a>)</small>" "</td></tr>" "<tr><th valign=\"top\" align=\"right\">" "<p class=\"new-message-header\">" "<span class=\"new-message-header-message\">" "%s</span></p></th><td width=\"6\"> </td>", getarg("FMTNAME"), pref_wikifmt ? "":"selected='selected'", getarg("FMTTEXTPLAIN"), pref_wikifmt ? "selected='selected'":"", getarg("FMTTEXTWIKI"), get_imageurl(), getarg("FMTHELP"), messagelab); printf("<td>%s\n", text1); if (fp) { newmsg_showfp(fp, &attachcnt); } else { printf("%s", cgi("body")); } printf("%s\n", text2); if (draftmessage && *draftmessage) { printf("<input type=\"hidden\" name=\"draftmessage\" value=\""); output_attrencoded(draftmessage); printf("\" />"); } if (draftmessage) free(draftmessage); printf("</td></tr>\n"); printf("<tr><th valign=\"top\" align=\"right\">" "<p class=\"new-message-header\">" "<span class=\"new-message-header-message\">" "%s</span></p></th><td> </td>" "<td>%d <input type=\"submit\" name=\"doattachments\" value=\"%s\" /></td></tr>", attachmentslab, attachcnt, uploadlab); printf("<tr><td colspan=\"2\" align=\"right\"><input type=\"checkbox\" " "name=\"fcc\" id=\"fcc\"%s /></td><td><label for=\"fcc\">%s</label></td></tr>\n", pref_noarchive ? "":" checked=\"checked\"", getarg("PRESERVELAB")); if (auth_getoptionenvint("wbnodsn") == 0) printf("<tr><td colspan=\"2\" align=\"right\"><input type=\"checkbox\" " "name=\"dsn\" id=\"dsn\" /></td><td><label for=\"dsn\">%s</label></td></tr>\n", getarg("DSN")); if (libmail_gpg_has_gpg(GPGDIR) == 0) { char *all_addr; printf("<tr><td colspan=\"2\" align=\"right\"><input type=\"checkbox\" " "name=\"sign\" id=\"sign\" /></td><td><label for=\"sign\">%s</label><select name=\"signkey\">", getarg("SIGNLAB")); gpgselectkey(); printf("</select></td></tr>\n"); all_addr=newmsg_alladdrs(fp); printf("<tr valign=\"middle\"><td colspan=\"2\" align=\"right\">" "<input type=\"checkbox\" name=\"encrypt\" id=\"encrypt\" /></td>" "<td><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr valign=\"middle\"><td><label for=\"encrypt\">%s</label></td><td><select size=\"4\" multiple=\"multiple\" name=\"encryptkey\">", getarg("ENCRYPTLAB")); gpgencryptkeys(all_addr); printf("</select></td></tr>\n"); printf("</table></td></tr>\n"); if (ishttps()) printf("<tr><td colspan=\"2\" align=\"left\"> </td><td>%s<input type=\"password\" name=\"passphrase\" /></td></tr>\n", getarg("PASSPHRASE")); if (all_addr) free(all_addr); } if (fp) fclose(fp); if (draftmessagefilename) free(draftmessagefilename); printf("<tr><td colspan=\"2\"> </td><td>"); printf("<input type=\"submit\" name=\"previewmsg\" value=\"%s\" />", previewlab); printf("<input type=\"submit\" name=\"sendmsg\" value=\"%s\" />", sendlab); printf("<input type=\"submit\" name=\"savedraft\" value=\"%s\" />", savedraft); #ifdef ISPELL printf("<input type=\"submit\" name=\"startspellchk\" value=\"%s\" />", checkspelling); #endif printf("</td></tr>\n"); printf("</table>\n"); printf("</td></tr></table>\n"); printf("</td></tr></table>\n"); }
static void do_maildir_shared_sync(const char *dir, const char *shared) { struct dbobj obj; char *dbname; char *cur; char *shared_update_name; struct stat stat1, stat2; int fd; maildir_purgetmp(dir); /* clean up after myself */ maildir_getnew(dir, 0, NULL, NULL); maildir_purgetmp(shared); maildir_getnew(shared, 0, NULL, NULL); /* Figure out if we REALLY need to sync something */ shared_update_name=malloc(strlen(dir)+sizeof("/shared-timestamp")); if (!shared_update_name) return; strcat(strcpy(shared_update_name, dir), "/shared-timestamp"); cur=malloc(strlen(shared)+sizeof("/new")); if (!cur) { free(shared_update_name); return; } if (stat(shared_update_name, &stat1) == 0) { if ( stat( strcat(strcpy(cur, shared), "/new"), &stat2) == 0 && stat2.st_mtime < stat1.st_mtime && stat( strcat(strcpy(cur, shared), "/cur"), &stat2) == 0 && stat2.st_mtime < stat1.st_mtime) { free(shared_update_name); free(cur); return; } } if ((fd=maildir_safeopen(shared_update_name, O_RDWR|O_CREAT, 0600))>= 0) { if (write(fd, "", 1) < 0) perror("write"); close(fd); } free(cur); free(shared_update_name); if (create_db(&obj, dir, &dbname)) return; if (build_db(shared, &obj)) { dbobj_close(&obj); unlink(dbname); free(dbname); return; } if ((cur=malloc(strlen(dir)+sizeof("/cur"))) == 0) { perror("malloc"); dbobj_close(&obj); unlink(dbname); free(dbname); return; } strcat(strcpy(cur, dir), "/cur"); if (update_cur(cur, shared, &obj) == 0) { strcat(strcpy(cur, dir), "/new"); if (update_cur(cur, shared, &obj) == 0) { *strrchr(cur, '/')=0; /* Chop off the /new */ newmsgs(cur, shared, &obj); } } free(cur); dbobj_close(&obj); unlink(dbname); free(dbname); }