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"); }
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"); }
static struct token * readtokens(void) { char str[LINEMAX]; struct token *t; token_t type; bool q, num; size_t j; t = malloc(sizeof(struct token)); if (t == nil) { printf("malloc failed.\n"); exit(ENOMEM); } t->next = nil; q = false; num = true; j = 0; while (readlen(1) > 0) { if (s[0] == '\\') { if (readlen(2) < 2 || s[1] != '\n') { printf("expected new line after \\\n"); break; } else { eatlen(2); continue; } } else if (s[0] == '\'') { num = false; if (readlen(2) < 2 || s[1] != '\'') { q = !q; eatlen(1); } else { str[j++] = '\''; eatlen(2); } continue; } else if (!q && s[0] == '\n') { eatlen(1); if (j > 0) { t->next = tokennew(TOKEN_SEMI); return literal(t, str, j + 1, num); } else { t->type = TOKEN_SEMI; t->aux = nil; return t; } } else if (!q && isspace(s[0])) { eatlen(1); if (j > 0) { return literal(t, str, j + 1, num); } else { continue; } } for (type = 0; !q && type < TOKEN_TYPES; type++) { if (types[type].len == 0) continue; else if (!types[type].punc && j > 0) continue; if (readlen(types[type].len) < types[type].len) { continue; } if (strncmp(s, types[type].str, types[type].len)) { eatlen(types[type].len); if (j > 0) { t->next = tokennew(type); return literal(t, str, j + 1, num); } else { t->type = type; t->aux = nil; return t; } } } if (j >= LINEMAX) { printf("token length too long!\n"); exit(ENOMEM); } str[j++] = s[0]; if (num && (s[0] < '0' || s[0] > '9')) { num = false; } eatlen(1); } if (j > 0) { t->next = tokennew(TOKEN_SEMI); return literal(t, str, j + 1, num); } else { t->type = TOKEN_END; t->aux = nil; return t; } }