int main(int argc, char **argv) { FILE *fp; struct rfc2045 *rfc; struct msg2html_info *info; if (argc < 2) return 0; if ((fp=fopen(argv[1], "r")) == NULL) { perror(argv[1]); exit(1); } rfc=rfc2045_fromfp(fp); info=msg2html_alloc("utf-8"); info->showhtml=1; msg2html(fp, rfc, info); fclose(fp); msg2html_free(info); rfc2045_free(rfc); return (0); }
struct rfc2045 *fetch_alloc_rfc2045(unsigned long msgnum, FILE *fp) { if (cached_rfc2045p && strcmp(cached_filename, current_maildir_info.msgs[msgnum].filename) == 0) return (cached_rfc2045p); fetch_free_cached(); if ((cached_filename=strdup(current_maildir_info. msgs[msgnum].filename)) == 0) write_error_exit(0); if (fseek(fp, 0L, SEEK_SET) == -1) { write_error_exit(0); return (0); } cached_rfc2045p=rfc2045_fromfp(fp); if (!cached_rfc2045p) { free(cached_filename); cached_filename=0; write_error_exit(0); } return (cached_rfc2045p); }
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(); }
void newmsg_showfp(FILE *fp, int *attachcnt) { struct rfc2045 *p=rfc2045_fromfp(fp), *q; if (!p) enomem(); /* Here's a nice opportunity to count all attachments */ *attachcnt=0; for (q=p->firstpart; q; q=q->next) if (!q->isdummy) ++*attachcnt; if (*attachcnt) --*attachcnt; /* Not counting the 1st MIME part */ { const char *content_type; const char *content_transfer_encoding; const char *charset; rfc2045_mimeinfo(p, &content_type, &content_transfer_encoding, &charset); if (content_type && strcmp(content_type, "multipart/alternative") == 0) *attachcnt=0; } q=rfc2045_searchcontenttype(p, "text/plain"); if (q) { struct rfc2045src *src=rfc2045src_init_fd(fileno(fp)); if (src) { struct show_textarea_info info; show_textarea_init(&info, 1); rfc2045_decodetextmimesection(src, q, sqwebmail_content_charset, NULL, &show_textarea_trampoline, &info); rfc2045src_deinit(src); show_textarea(&info, "\n", 1); } } rfc2045_free(p); }
void newmsg_showfp(FILE *fp, int *attachcnt) { struct rfc2045 *p=rfc2045_fromfp(fp), *q; if (!p) enomem(); /* Here's a nice opportunity to count all attachments */ *attachcnt=0; for (q=p->firstpart; q; q=q->next) if (!q->isdummy) ++*attachcnt; if (*attachcnt) --*attachcnt; /* Not counting the 1st MIME part */ q=rfc2045_searchcontenttype(p, "text/plain"); if (q) rfc2045_decodemimesection(fileno(fp), q, &show_textarea, NULL); rfc2045_free(p); }
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); }
char *newmsg_newdraft(const char *folder, const char *pos, const char *forwardsep, const char *replysalut) { char *filename=0; char *replymode; size_t pos_n; FILE *fp; const char *mimeidptr; char *draftfilename; struct rfc2045 *rfc2045p, *rfc2045partp; int x; if (*cgi(replymode="reply") || *cgi(replymode="replyall") || *cgi(replymode="replylist") || *cgi(replymode="forward") || *cgi(replymode="forwardatt")) { pos_n=atol(pos); filename=get_msgfilename(folder, &pos_n); } if (!filename) return (0); fp=0; x=maildir_semisafeopen(filename, O_RDONLY, 0); if (x >= 0) if ((fp=fdopen(x, "r")) == 0) close(x); if (fp == 0) { free(filename); return (0); } rfc2045p=rfc2045_fromfp(fp); if (!rfc2045p) { fclose(fp); enomem(); } mimeidptr=cgi("mimeid"); rfc2045partp=0; if (*mimeidptr) { rfc2045partp=rfc2045_find(rfc2045p, mimeidptr); if (rfc2045partp) { const char *content_type, *dummy; rfc2045_mimeinfo(rfc2045partp, &content_type, &dummy, &dummy); if (!content_type || strcmp(content_type, "message/rfc822")) rfc2045partp=0; else rfc2045partp=rfc2045partp->firstpart; } } if (!rfc2045partp) rfc2045partp=rfc2045p; draftfd=maildir_createmsg(DRAFTS, 0, &draftfilename); if (draftfd < 0) { fclose(fp); rfc2045_free(rfc2045p); enomem(); } maildir_writemsgstr(draftfd, "From: "); { const char *f=pref_from; if (!f || !*f) f=login_fromhdr(); if (!f) f=""; maildir_writemsgstr(draftfd, f); maildir_writemsgstr(draftfd, "\n"); } { char *ml=getmailinglists(); struct rfc2045_mkreplyinfo ri; int rc; memset(&ri, 0, sizeof(ri)); ri.fd=fileno(fp); ri.rfc2045partp=rfc2045partp; ri.replymode=replymode; ri.replysalut=replysalut; ri.forwardsep=forwardsep; ri.myaddr_func=ismyaddr; ri.write_func=writefunc; ri.writesig_func=newmsg_writesig; ri.mailinglists=ml; ri.charset=sqwebmail_content_charset; if (strcmp(replymode, "forward") == 0 || strcmp(replymode, "forwardatt") == 0) { #if HAVE_SQWEBMAIL_UNICODE rc=rfc2045_makereply_unicode(&ri); #else rc=rfc2045_makereply(&ri); #endif } else { char *basename=maildir_basename(filename); maildir_writemsgstr(draftfd, "X-Reply-To-Folder: "); maildir_writemsgstr(draftfd, folder); maildir_writemsgstr(draftfd, "\nX-Reply-To-Msg: "); maildir_writemsgstr(draftfd, basename); free(basename); maildir_writemsgstr(draftfd, "\n"); #if HAVE_SQWEBMAIL_UNICODE rc=rfc2045_makereply_unicode(&ri); #else rc=rfc2045_makereply(&ri); #endif } free(ml); if (rc) { fclose(fp); close(draftfd); rfc2045_free(rfc2045p); enomem(); } } fclose(fp); if (maildir_closemsg(draftfd, DRAFTS, draftfilename, 1, 0)) { free(draftfilename); draftfilename=0; cgi_put("error", "quota"); } free(filename); rfc2045_free(rfc2045p); return(draftfilename); }