• Patch: Elm ME+ 2.5 PLalpha51 -> Elm ME+ 2.5 PLalpha52 [6/7] (3/5)

    From Kari Hurtta@21:1/5 to All on Mon Jun 8 19:52:22 2020
    [continued from previous message]

    + int encoding_supported,char * name,
    + struct string *s,
    + int width));
    + static void add_string_header(F,edit_charset,encoding_supported,name,s,width) + FILE * F;
    + charset_t edit_charset;
    + int encoding_supported;
    + char * name;
    + struct string * s;
    + int width;
    + {
    + int l = strlen(name) + 1;
    +
    + fprintf(F,"%s: ",name);
    + print_edit_string (mode_plain,F,edit_charset,encoding_supported,s,
    + &l,width);
    + putc('\n',F);
    +
    + }
    +
    + static void print_edit_id P_((FILE * F,charset_t edit_charset,
    + int encoding_supported,
    + const struct message_id * id,
    + int *L, int width));
    + static void print_edit_id(F,edit_charset,encoding_supported,
    + id,L,width)
    + FILE * F;
    + charset_t edit_charset;
    + int encoding_supported;
    + const struct message_id * id;
    + int *L;
    + int width;
    + {
    + int l = *L;
    +
    + const char * left = message_id_left(id);
    + const char * domain = message_id_domain(id);
    + const struct string * id_comment = message_id_comment(id);
    + int sl;
    +
    + putc('<',F);
    + l++;
    +
    + if (left) {
    + fputs(left,F);
    + l += strlen(left);
    + }
    +
    + if (domain) {
    + putc('@',F);
    + fputs(domain,F);
    + l += strlen(domain) + 1;
    + }
    +
    + putc('>',F);
    + l++;
    +
    + if (id_comment && (sl = string_len(id_comment)) > 0) {
    + if (l + sl >= width-5 && l > 1) {
    + putc('\n',F);
    + l = 0;
    + }
    + putc(' ',F);
    + l++;
    +
    + print_edit_string (mode_comment,F,edit_charset,encoding_supported,
    + id_comment,
    + &l,width);
    + }
    +
    + *L = l;
    + }
    +
    + static void add_id_header P_((FILE * F,charset_t edit_charset,
    + int encoding_supported,char * name,
    + struct message_id *id,
    + int width));
    + static void add_id_header(F,edit_charset,encoding_supported,name,id,width)
    + FILE * F;
    + charset_t edit_charset;
    + int encoding_supported;
    + char * name;
    + struct message_id * id;
    + int width;
    + {
    + int l = strlen(name) + 1;
    +
    + fprintf(F,"%s: ",name);
    +
    + if (id) {
    + print_edit_id(F,edit_charset,encoding_supported,id,&l,width);
    + }
    +
    + putc('\n',F);
    + }
    +
    + static void print_edit_str P_((FILE *F,const char *str,int *L, int width));
    + static void print_edit_str(F,str,L,width)
    + FILE *F;
    + const char *str;
    + int *L;
    + int width;
    + {
    + int l = *L;
    + const char *s;
    +
    + for (s = str; *s; s++) {
    + if (whitespace(*s)) {
    + if ((width > 40) ? (l > width -20) : (l > 60)) {
    + putc('\n',F);
    + l = 0;
    + }
    + putc(*s,F);
    + } else {
    + putc(*s,F);
    + }
    + l++;
    + }
    +
    + *L = l;
    + }
    +
    + static void add_expires_header P_((FILE * F,
    + char * name,
    + struct expanded_expires *expires_value,
    + int width));
    + static void add_expires_header(F,name,expires_value,width)
    + FILE * F;
    + char * name;
    + struct expanded_expires * expires_value;
    + int width;
    + {
    + int l = strlen(name) + 1;
    +
    + fprintf(F,"%s: ",name);
    +
    + if (expires_value) {
    + char timebuf[SLEN] = "";
    +
    + enum print_time print_time = get_expanded_expires_print_time(expires_value);
    +
    + if (days_ahead_hdrval(expires_value,timebuf,sizeof timebuf,
    + print_time)) {
    +
    + print_edit_str(F,timebuf,&l,width);
    + }
    + }
    + putc('\n',F);
    + }
    +
    + static void add_date_header P_((FILE * F,
    + char * name,
    + struct expanded_date *date_value,
    + int width));
    + static void add_date_header(F,name,date_value,width)
    + FILE * F;
    + char * name;
    + struct expanded_date * date_value;
    + int width;
    + {
    + int l = strlen(name) + 1;
    +
    + fprintf(F,"%s: ",name);
    +
    + if (date_value) {
    + char timebuf[SLEN] = "";
    +
    + if (date_hdrval(date_value,timebuf,sizeof timebuf,
    + print_date_and_time /* print_time */)) {
    +
    + print_edit_str(F,timebuf,&l,width);
    + }
    + }
    + putc('\n',F);
    + }
    +
    +
    + static void add_refs_header P_((FILE * F,charset_t edit_charset,
    + int encoding_supported,char * name,
    + struct references *refs,
    + int width));
    + static void add_refs_header(F,edit_charset,encoding_supported,name,refs,width)
    + FILE * F;
    + charset_t edit_charset;
    + int encoding_supported;
    + char * name;
    + struct references * refs;
    + int width;
    + {
    + int l = strlen(name) + 1;
    +
    +
    + fprintf(F,"%s: ",name);
    +
    + if (refs) {
    + int idx;
    + int add_sep = 0;
    + int count = references_item_count(refs);
    +
    + for (idx = 0; idx < count; idx++) {
    +
    + /* message_id also includes comment */
    + const struct message_id * id = references_get_message_id(refs,idx); + const struct string * phrase = references_get_phrase(refs,idx);
    + const struct string * tail_comment = references_get_comment(refs,idx);
    +
    + int sl;
    +
    + if (id) {
    + if (add_sep) {
    + if ((width > 40) ? (l > width -20) : (l > 60)) {
    + putc('\n',F);
    + l = 0;
    + }
    + putc(' ',F);
    + l++;
    + }
    +
    + print_edit_id(F,edit_charset,encoding_supported,id,&l,width);
    + add_sep = 1;
    + }
    +
    + if (phrase && (sl = string_len(phrase)) > 0) {
    + if (add_sep) {
    + if (l + sl >= width-5 && l > 1) {
    + putc('\n',F);
    + l = 0;
    + }
    + putc(' ',F);
    + l++;
    + }
    +
    + print_edit_string (mode_phrase,F,edit_charset,
    + encoding_supported,phrase,
    + &l,width);
    + add_sep = 1;
    + }
    +
    + if (tail_comment && (sl = string_len(tail_comment)) > 0) {
    + if (add_sep) {
    + if (l + sl >= width-5 && l > 1) {
    + putc('\n',F);
    + l = 0;
    + }
    + putc(' ',F);
    + l++;
    + }
    +
    + print_edit_string (mode_comment,F,edit_charset,encoding_supported,
    + tail_comment,
    + &l,width);
    + add_sep = 1;
    + }
    + }
    + }
    +
    + putc('\n',F);
    + }
    +
    + void edit_headers_on_editor(headers,editor, encoding_supported,
    + page)
    + struct mailing_headers *headers;
    + const char *editor;
    + int encoding_supported;
    + struct menu_context *page;
    + {
    + charset_t edit_charset = system_charset;
    + FILE * F = NULL;
    + const char * tmp = give_dt_estr_as_str(&temp_dir_e,"tmpdir",NULL,NULL);
    +
    + char * filename = elm_message(FRM("%s%sHDR%d"),
    + tmp ? tmp : "/tmp/",
    + temp_file, getpid());
    + char * buffer = NULL;
    + char buffer1[32*1024];
    + int stat;
    + int c;
    + int err;
    + int LINES, COLUMNS;
    +
    + menu_get_sizes(page, &LINES, &COLUMNS);
    +
    + if (in_string(editor, "%s"))
    + buffer = elm_message(FRM(editor),
    + filename);
    + else
    + buffer = elm_message(FRM("%s %s"),
    + editor, filename);
    +
    +
    + F = safeopen_rdwr(filename);
    + if (!F)
    + goto fail1;
    +
    + PutLineX(LINES-1, 0, CATGETS(elm_msg_cat, ElmSet, ElmInvokeEditor,
    + "Invoking editor..."));
    + FlushBuffer();
    +
    +
    + /* FIX: Following prints with display_charset and
    + not with edit_charset (system_charset)
    + */
    +
    + {
    + const char *MIME_name_e =
    + get_charset_MIME_name(edit_charset);
    +
    + elm_fprintf(F,
    + CATGETS(elm_msg_cat, ElmSet, ElmHdrEditComment,
    + "# Headers are automatically converted from %s charset and not need encoded\n"),
    + MIME_name_e ? MIME_name_e : "<no MIME name>");
    + }
    +
    + if (encoding_supported) {
    + elm_fprintf(F,
    + CATGETS(elm_msg_cat, ElmSet, ElmHdrEditCommentEnc,
    + "# MIME encoding of headers is supported\n"));
    +
    + } else {
    + elm_fprintf(F,
    + CATGETS(elm_msg_cat, ElmSet, ElmHdrEditCommentNo,
    + "# MIME encoding of headers is NOT supported\n")); +
    + }
    +
    + add_addr_header(F,edit_charset,encoding_supported,
    + "From", & headers->from,0,COLUMNS);
    + add_addr_header(F,edit_charset,encoding_supported,
    + "To", & headers->to,1,COLUMNS);
    + add_addr_header(F,edit_charset,encoding_supported,
    + "Cc", & headers->cc,1,COLUMNS);
    + add_addr_header(F,edit_charset,encoding_supported,
    + "Bcc", & headers->bcc,1,COLUMNS);
    + add_addr_header(F,edit_charset,encoding_supported,
    + "Reply-To", & headers->reply_to,1,COLUMNS);
    + add_string_header(F,edit_charset,encoding_supported,
    + "Subject", headers->subject,COLUMNS);
    + add_id_header(F,edit_charset,encoding_supported,
    + "Message-ID",headers->message_id,COLUMNS);
    + if (headers->date) {
    + switch (get_expanded_date_source(headers->date)) {
    + case date_automatic:
    + elm_fprintf(F,
    + CATGETS(elm_msg_cat, ElmSet, ElmHdrEditDUpdate,
    + "# Date is updated automatically, if Date: is not modified.\n"));
    + break;
    + case date_explicit:
    + elm_fprintf(F,
    + CATGETS(elm_msg_cat, ElmSet, ElmHdrEditDClear,
    + "# Date is generated automatically, if Date: is cleared.\n"));
    + break;
    + }
    + } else {
    + elm_fprintf(F,
    + CATGETS(elm_msg_cat, ElmSet, ElmHdrEditDEmpty,
    + "# Date is generated automatically, if Date: is left empty.\n"));
    + }
    + add_date_header(F,"Date",headers->date,COLUMNS);
    + add_expires_header(F,"Expires",headers->expires,COLUMNS);
    + add_refs_header(F,edit_charset,encoding_supported,
    + "In-reply-to",headers->in_reply_to,COLUMNS);
    + add_refs_header(F,edit_charset,encoding_supported,
    + "References",headers->references,COLUMNS);
    +
    + fclose(F);
    +
    + (void) elm_chown(filename, userid, groupid);
    +
    + Raw(OFF);
    + /* FIX: SY_DUMPSTATE should perhaps be supported? */
    + if ((stat = system_call(buffer, SY_ENAB_SIGHUP,
    + NULL)) == -1) {
    + int err UNUSED_VAROK = errno;
    +
    + Raw(ON);
    + DPRINT(Debug,1,(&Debug,
    + "System call failed with stat %d (edit_headers_on_editor)\n",
    + stat));
    + DPRINT(Debug,1,(&Debug,
    + "** %s **\n", strerror(err)));
    + ClearLine(LINES-2);
    + lib_error(CATGETS(elm_msg_cat, ElmSet, ElmCantInvokeEditor,
    + "Can't invoke editor '%s' for composition."),
    + editor);
    + sleep_message();
    +
    + goto fail2;
    + }
    + Raw(ON);
    +
    + err = can_open(filename,"r");
    + if (err) {
    + lib_error(FRM("%s: %s"),filename,err);
    +
    + goto fail1;
    + }
    +
    + F = fopen(filename,"r");
    + if (!F) {
    + /* In than point opening should have succeed */
    + int err = errno;
    + lib_error(FRM("%s: %s"),filename,err);
    +
    + goto fail1;
    + }
    +
    + /* Skip comment block */
    +
    + while ('#' == (c = getc(F))) {
    +
    + while ('\n' != (c = getc(F))) {
    + if (EOF == c)
    + break;
    + }
    + }
    +
    + if (EOF != c)
    + ungetc(c,F);
    +
    +
    + /* Read headers */
    + while (0 < read_header_line(F,buffer1,sizeof buffer1,0)) {
    +
    + header_ptr header_name;
    + char *k;
    +
    + if ('#' == buffer1[0])
    + continue;
    +
    + k = strchr(buffer1,':');
    + if (!k)
    + break;
    + *k = '\0';
    + k++;
    +
    + while (whitespace(*k))
    + k++;
    +
    + header_name = find_header(buffer1,1);
    +
    + if (!add_to_mailing_header(headers,header_name,k,
    + encoding_supported,
    + edit_charset,1 /* REPLACE */ )) {
    +
    + lib_error(CATGETS(elm_msg_cat, ElmSet, ElmHdrNotSupported,
    + "Editing of %s header is not supported."),
    + buffer1);
    + }
    + }
    +
    + if (!feof(F))
    + lib_error(CATGETS(elm_msg_cat, ElmSet, ElmHdrGarbage,
    + "Garbage on header file"));
    +
    + fclose(F);
    +
    + fail2:
    + unlink(filename);
    +
    + fail1:
    +
    + free(filename); filename = NULL;
    + free(buffer); buffer = NULL;
    +
    + }
    +
    +
    + /*
    + * Local Variables:
    + * mode:c
    + * c-basic-offset:4
    + * buffer-file-coding-system: iso-8859-1
    + * End:
    + */
    Index: elmME+.2.5.alpha52-cvs/src/elm.c
    *** elmME+.2.5.alpha51/src/elm.c Sat Feb 8 14:34:18 2020
    --- elmME+.2.5.alpha52-cvs/src/elm.c Sun May 17 09:02:36 2020 ***************
    *** 1,7 ****
    ! static char rcsid[] = "@(#)$Id: elm.c,v 2.49 2020/01/29 16:20:24 hurtta Exp $";

    /*****************************************************************************
    ! * The Elm (ME+) Mail System - $Revision: 2.49 $ $State: Exp $
    *
    * Modified by: Kari Hurtta <hurtta+elm@siilo.FMI.FI>
    * (was hurtta+elm@posti.FMI.FI, hurtta+elm@ozone.FMI.FI)
    --- 1,7 ----
    ! static char rcsid[] = "@(#)$Id: elm.c,v 2.50 2020/05/17 06:02:36 hurtta Exp $";

    /*****************************************************************************
    ! * The Elm (ME+) Mail System - $Revision: 2.50 $ $State: Exp $
    *
    * Modified by: Kari Hurtta <hurtta+elm@siilo.FMI.FI>
    * (was hurtta+elm@posti.FMI.FI, hurtta+elm@ozone.FMI.FI)
    ***************
    *** 1775,1782 ****
    #endif
    free_addr_util();
    free_mail_file_list();
    free_rc_options();
    !
    return ex