static const char * query_format_str (char *dest, size_t destlen, size_t col, char op, const char *src, const char *fmt, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) { ENTRY *entry = (ENTRY *)data; QUERY *query = entry->data; char tmp[SHORT_STRING]; char buf2[STRING] = ""; int optional = (flags & M_FORMAT_OPTIONAL); switch (op) { case 'a': rfc822_write_address (buf2, sizeof (buf2), query->addr, 1); snprintf (tmp, sizeof (tmp), "%%%ss", fmt); snprintf (dest, destlen, tmp, buf2); break; case 'c': snprintf (tmp, sizeof (tmp), "%%%sd", fmt); snprintf (dest, destlen, tmp, query->num + 1); break; case 'e': if (!optional) { snprintf (tmp, sizeof (tmp), "%%%ss", fmt); snprintf (dest, destlen, tmp, NONULL (query->other)); } else if (!query->other || !*query->other) optional = 0; break; case 'n': snprintf (tmp, sizeof (tmp), "%%%ss", fmt); snprintf (dest, destlen, tmp, NONULL (query->name)); break; case 't': snprintf (tmp, sizeof (tmp), "%%%sc", fmt); snprintf (dest, destlen, tmp, entry->tagged ? '*' : ' '); break; default: snprintf (tmp, sizeof (tmp), "%%%sc", fmt); snprintf (dest, destlen, tmp, op); break; } if (optional) mutt_FormatString (dest, destlen, col, ifstring, query_format_str, data, 0); else if (flags & M_FORMAT_OPTIONAL) mutt_FormatString (dest, destlen, col, elsestring, query_format_str, data, 0); return src; }
void mutt_pgp_command (char *d, size_t dlen, struct pgp_command_context *cctx, const char *fmt) { mutt_FormatString (d, dlen, NONULL (fmt), _mutt_fmt_pgp_command, (unsigned long) cctx, 0); debug_print (2, ("%s\n", d)); }
char* make_sidebar_entry(char *box, unsigned int size, unsigned int new_messages, unsigned int flagged) { static char *entry = 0; struct sidebar_entry sbe; int SBvisual; SBvisual = SidebarWidth - strlen(SidebarDelim); if (SBvisual < 1) return NULL; sbe.new_messages = new_messages; sbe.flagged = flagged; sbe.size = size; strncpy(sbe.box, box, 31); safe_realloc(&entry, SBvisual + 2); entry[SBvisual + 1] = '\0'; mutt_FormatString(entry, SBvisual + 1, 0, SidebarFormat, sidebar_format_str, (unsigned long)&sbe, (format_flag)0); return entry; }
static char *get_compression_cmd (const char *cmd, const CONTEXT * ctx) { char expanded[_POSIX_PATH_MAX]; mutt_FormatString (expanded, sizeof (expanded), cmd, compresshook_format_str, (unsigned long) ctx, 0); return str_dup (expanded); }
static void query_entry(char *s, size_t slen, MUTTMENU *m, int num) { ENTRY *entry = &((ENTRY *)m->data)[num]; entry->data->num = num; mutt_FormatString(s, slen, 0, NONULL(QueryFormat), query_format_str, (unsigned long)entry, M_FORMAT_ARROWCURSOR); }
static void snd_entry(char *buf, size_t buflen, MUTTMENU *menu, int num) { mutt_FormatString(buf, buflen, 0, NONULL(AttachFormat), mutt_attach_fmt, (unsigned long)(((ATTACHPTR **)menu->data)[num]), (format_flag)(M_FORMAT_STAT_FILE | M_FORMAT_ARROWCURSOR)); }
void menu_status_line(char *buf, size_t buflen, MUTTMENU *menu, const char *p) { mutt_FormatString(buf, buflen, 0, p, status_format_str, (unsigned long)menu, (format_flag)0); }
void _mutt_make_string (char *dest, size_t destlen, const char *s, CONTEXT *ctx, HEADER *hdr, format_flag flags) { struct hdr_format_info hfi; hfi.hdr = hdr; hfi.ctx = ctx; hfi.pager_progress = 0; mutt_FormatString (dest, destlen, 0, s, hdr_format_str, (unsigned long) &hfi, flags); }
static void pgp_entry (char *s, size_t l, MUTTMENU * menu, int num) { pgp_uid_t **KeyTable = (pgp_uid_t **) menu->data; pgp_entry_t entry; entry.uid = KeyTable[num]; entry.num = num + 1; mutt_FormatString (s, l, 0, NONULL (PgpEntryFormat), pgp_entry_fmt, (unsigned long) &entry, M_FORMAT_ARROWCURSOR); }
static void compose_status_line(char *buf, size_t buflen, size_t col, MUTTMENU *menu, const char *p) { mutt_FormatString(buf, buflen, col, p, compose_format_str, (unsigned long)menu, (format_flag)0); }
void mutt_pgp_command(char *d, size_t dlen, struct pgp_command_context *cctx, const char *fmt) { mutt_FormatString(d, dlen, 0, NONULL(fmt), _mutt_fmt_pgp_command, (unsigned long)cctx, (format_flag)0); dprint(2, "mutt_pgp_command: %s\n", d); }
void mutt_make_string_info(char *dst, size_t dstlen, const char *s, struct hdr_format_info *hfi, format_flag flags) { mutt_FormatString(dst, dstlen, 0, s, hdr_format_str, (unsigned long)hfi, flags); }
static const char *pgp_entry_fmt (char *dest, size_t destlen, size_t col, char op, const char *src, const char *prefix, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) { char fmt[16]; pgp_entry_t *entry; pgp_uid_t *uid; pgp_key_t key, pkey; int kflags = 0; int optional = (flags & M_FORMAT_OPTIONAL); entry = (pgp_entry_t *) data; uid = entry->uid; key = uid->parent; pkey = pgp_principal_key (key); if (isupper ((unsigned char) op)) key = pkey; kflags = key->flags | (pkey->flags & KEYFLAG_RESTRICTIONS) | uid->flags; switch (ascii_tolower (op)) { case '[': { const char *cp; char buf2[SHORT_STRING], *p; int do_locales; struct tm *tm; size_t len; p = dest; cp = src; if (*cp == '!') { do_locales = 0; cp++; } else do_locales = 1; len = destlen - 1; while (len > 0 && *cp != ']') { if (*cp == '%') { cp++; if (len >= 2) { *p++ = '%'; *p++ = *cp; len -= 2; } else break; /* not enough space */ cp++; } else { *p++ = *cp++; len--; } } *p = 0; if (do_locales && Locale) setlocale (LC_TIME, Locale); tm = localtime (&key->gen_time); strftime (buf2, sizeof (buf2), dest, tm); if (do_locales) setlocale (LC_TIME, "C"); snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, buf2); if (len > 0) src = cp + 1; } break; case 'n': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sd", prefix); snprintf (dest, destlen, fmt, entry->num); } break; case 'k': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, _pgp_keyid (key)); } break; case 'u': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, NONULL (uid->addr)); } break; case 'a': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, key->algorithm); } break; case 'l': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sd", prefix); snprintf (dest, destlen, fmt, key->keylen); } break; case 'f': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sc", prefix); snprintf (dest, destlen, fmt, pgp_flags (kflags)); } else if (!(kflags & (KEYFLAG_RESTRICTIONS))) optional = 0; break; case 'c': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, pgp_key_abilities (kflags)); } else if (!(kflags & (KEYFLAG_ABILITIES))) optional = 0; break; case 't': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sc", prefix); snprintf (dest, destlen, fmt, trust_flags[uid->trust & 0x03]); } else if (!(uid->trust & 0x03)) /* undefined trust */ optional = 0; break; default: *dest = '\0'; } if (optional) mutt_FormatString (dest, destlen, col, ifstring, mutt_attach_fmt, data, 0); else if (flags & M_FORMAT_OPTIONAL) mutt_FormatString (dest, destlen, col, elsestring, mutt_attach_fmt, data, 0); return (src); }
static void mix_entry (char *b, size_t blen, MUTTMENU *menu, int num) { REMAILER **type2_list = (REMAILER **) menu->data; mutt_FormatString (b, blen, 0, MuttIndexWindow->cols, NONULL (MixEntryFormat), mix_entry_fmt, (unsigned long) type2_list[num], MUTT_FORMAT_ARROWCURSOR); }
/* %a = address of author * %A = reply-to address (if present; otherwise: address of author * %b = filename of the originating folder * %B = the list to which the letter was sent * %c = size of message in bytes * %C = current message number * %d = date and time of message using $date_format and sender's timezone * %D = date and time of message using $date_format and local timezone * %e = current message number in thread * %E = number of messages in current thread * %f = entire from line * %F = like %n, unless from self * %i = message-id * %l = number of lines in the message * %L = like %F, except `lists' are displayed first * %m = number of messages in the mailbox * %n = name of author * %N = score * %O = like %L, except using address instead of name * %P = progress indicator for builtin pager * %s = subject * %S = short message status (e.g., N/O/D/!/r/-) * %t = `to:' field (recipients) * %T = $to_chars * %u = user (login) name of author * %v = first name of author, unless from self * %X = number of MIME attachments * %y = `x-label:' field (if present) * %Y = `x-label:' field (if present, tree unfolded, and != parent's x-label) * %Z = status flags */ static const char * hdr_format_str(char *dest, size_t destlen, size_t col, char op, const char *src, const char *prefix, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) { struct hdr_format_info *hfi = (struct hdr_format_info *)data; HEADER *hdr, *htmp; CONTEXT *ctx; char fmt[SHORT_STRING], buf2[LONG_STRING], ch, *p; int do_locales, i; int optional = (flags & M_FORMAT_OPTIONAL); int threads = ((Sort & SORT_MASK) == SORT_THREADS); int is_index = (flags & M_FORMAT_INDEX); #define THREAD_NEW (threads \ && hdr->collapsed \ && hdr->num_hidden > 1 \ && mutt_thread_contains_unread(ctx, hdr) == 1) #define THREAD_OLD (threads \ && hdr->collapsed \ && hdr->num_hidden > 1 \ && mutt_thread_contains_unread(ctx, hdr) == 2) size_t len; hdr = hfi->hdr; ctx = hfi->ctx; dest[0] = 0; switch (op) { case 'A': if (hdr->env->reply_to && hdr->env->reply_to->mailbox) { mutt_format_s(dest, destlen, prefix, mutt_addr_for_display(hdr->env->reply_to)); break; } /* fall through if 'A' returns nothing */ case 'a': if (hdr->env->from && hdr->env->from->mailbox) { mutt_format_s(dest, destlen, prefix, mutt_addr_for_display(hdr->env->from)); } else dest[0] = '\0'; break; case 'B': if (!first_mailing_list(dest, destlen, hdr->env->to) && !first_mailing_list(dest, destlen, hdr->env->cc)) dest[0] = 0; if (dest[0]) { strfcpy(buf2, dest, sizeof(buf2)); mutt_format_s(dest, destlen, prefix, buf2); break; } /* fall through if 'B' returns nothing */ case 'b': if (ctx) { if ((p = strrchr(ctx->path, '/'))) strfcpy(dest, p + 1, destlen); else strfcpy(dest, ctx->path, destlen); } else strfcpy(dest, "(null)", destlen); strfcpy(buf2, dest, sizeof(buf2)); mutt_format_s(dest, destlen, prefix, buf2); break; case 'c': mutt_pretty_size(buf2, sizeof(buf2), (long)hdr->content->length); mutt_format_s(dest, destlen, prefix, buf2); break; case 'C': snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, hdr->msgno + 1); break; case 'd': case 'D': case '{': case '[': case '(': case '<': /* preprocess $date_format to handle %Z */ { const char *cp; struct tm *tm; time_t T; p = dest; cp = (op == 'd' || op == 'D') ? (NONULL(DateFmt)) : src; if (*cp == '!') { do_locales = 0; cp++; } else do_locales = 1; len = destlen - 1; while (len > 0 && (((op == 'd' || op == 'D') && *cp) || (op == '{' && *cp != '}') || (op == '[' && *cp != ']') || (op == '(' && *cp != ')') || (op == '<' && *cp != '>'))) { if (*cp == '%') { cp++; if (((*cp == 'Z') || (*cp == 'z')) && ((op == 'd') || (op == '{'))) { if (len >= 5) { sprintf(p, "%c%02u%02u", hdr->zoccident ? '-' : '+', hdr->zhours, hdr->zminutes); p += 5; len -= 5; } else break; /* not enough space left */ } else { if (len >= 2) { *p++ = '%'; *p++ = *cp; len -= 2; } else break; /* not enough space */ } cp++; } else { *p++ = *cp++; len--; } } *p = 0; if (do_locales && Locale) setlocale(LC_TIME, Locale); if ((op == '[') || (op == 'D')) tm = localtime(&hdr->date_sent); else if (op == '(') tm = localtime(&hdr->received); else if (op == '<') { T = time(NULL); tm = localtime(&T); } else { /* restore sender's time zone */ T = hdr->date_sent; if (hdr->zoccident) T -= (hdr->zhours * 3600 + hdr->zminutes * 60); else T += (hdr->zhours * 3600 + hdr->zminutes * 60); tm = gmtime(&T); } strftime(buf2, sizeof(buf2), dest, tm); if (do_locales) setlocale(LC_TIME, "C"); mutt_format_s(dest, destlen, prefix, buf2); if ((len > 0) && (op != 'd') && (op != 'D')) /* Skip ending op */ src = cp + 1; break; } case 'e': snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, mutt_messages_in_thread(ctx, hdr, 1)); break; case 'E': if (!optional) { snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, mutt_messages_in_thread(ctx, hdr, 0)); } else if (mutt_messages_in_thread(ctx, hdr, 0) <= 1) optional = 0; break; case 'f': buf2[0] = 0; rfc822_write_address(buf2, sizeof(buf2), hdr->env->from, 1); mutt_format_s(dest, destlen, prefix, buf2); break; case 'F': if (!optional) { make_from(hdr->env, buf2, sizeof(buf2), 0); mutt_format_s(dest, destlen, prefix, buf2); } else if (mutt_addr_is_user(hdr->env->from)) optional = 0; break; case 'H': /* (Hormel) spam score */ if (optional) optional = hdr->env->spam ? 1 : 0; if (hdr->env->spam) mutt_format_s(dest, destlen, prefix, NONULL(hdr->env->spam->data)); else mutt_format_s(dest, destlen, prefix, ""); break; case 'i': mutt_format_s(dest, destlen, prefix, hdr->env->message_id ? hdr->env->message_id : "<no.id>"); break; case 'l': if (!optional) { snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, (int)hdr->lines); } else if (hdr->lines <= 0) optional = 0; break; case 'L': if (!optional) { make_from(hdr->env, buf2, sizeof(buf2), 1); mutt_format_s(dest, destlen, prefix, buf2); } else if (!check_for_mailing_list(hdr->env->to, NULL, NULL, 0) && !check_for_mailing_list(hdr->env->cc, NULL, NULL, 0)) { optional = 0; } break; case 'm': if (ctx) { snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, ctx->msgcount); } else strfcpy(dest, "(null)", destlen); break; case 'n': mutt_format_s(dest, destlen, prefix, mutt_get_name(hdr->env->from)); break; case 'N': if (!optional) { snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, hdr->score); } else { if (hdr->score == 0) optional = 0; } break; case 'O': if (!optional) { make_from_addr(hdr->env, buf2, sizeof(buf2), 1); if (!globals.has_option(OPTSAVEADDRESS) && (p = strpbrk(buf2, "%@"))) *p = 0; mutt_format_s(dest, destlen, prefix, buf2); } else if (!check_for_mailing_list_addr(hdr->env->to, NULL, 0) && !check_for_mailing_list_addr(hdr->env->cc, NULL, 0)) { optional = 0; } break; case 'M': snprintf(fmt, sizeof(fmt), "%%%sd", prefix); if (!optional) { if (threads && is_index && hdr->collapsed && (hdr->num_hidden > 1)) snprintf(dest, destlen, fmt, hdr->num_hidden); else if (is_index && threads) mutt_format_s(dest, destlen, prefix, " "); else *dest = '\0'; } else { if (!(threads && is_index && hdr->collapsed && (hdr->num_hidden > 1))) optional = 0; } break; case 'P': strfcpy(dest, NONULL(hfi->pager_progress), destlen); break; case 's': if (flags & M_FORMAT_TREE && !hdr->collapsed) { if (flags & M_FORMAT_FORCESUBJ) { mutt_format_s(dest, destlen, "", NONULL(hdr->env->subject)); snprintf(buf2, sizeof(buf2), "%s%s", hdr->tree, dest); mutt_format_s_tree(dest, destlen, prefix, buf2); } else mutt_format_s_tree(dest, destlen, prefix, hdr->tree); } else mutt_format_s(dest, destlen, prefix, NONULL(hdr->env->subject)); break; case 'S': if (hdr->deleted) ch = 'D'; else if (hdr->attach_del) ch = 'd'; else if (hdr->tagged) ch = '*'; else if (hdr->flagged) ch = '!'; else if (hdr->replied) ch = 'r'; else if (hdr->read && (ctx && (ctx->msgnotreadyet != hdr->msgno))) ch = '-'; else if (hdr->old) ch = 'O'; else ch = 'N'; /* FOO - this is probably unsafe, but we are not likely to have such a short string passed into this routine */ *dest = ch; *(dest + 1) = 0; break; case 't': buf2[0] = 0; if (!check_for_mailing_list(hdr->env->to, "To ", buf2, sizeof(buf2)) && !check_for_mailing_list(hdr->env->cc, "Cc ", buf2, sizeof(buf2))) { if (hdr->env->to) snprintf(buf2, sizeof(buf2), "To %s", mutt_get_name( hdr->env->to)); else if (hdr->env->cc) snprintf(buf2, sizeof(buf2), "Cc %s", mutt_get_name( hdr->env->cc)); } mutt_format_s(dest, destlen, prefix, buf2); break; case 'T': snprintf(fmt, sizeof(fmt), "%%%sc", prefix); snprintf(dest, destlen, fmt, (Tochars && ((i = mutt_user_is_recipient(hdr))) < mutt_strlen( Tochars)) ? Tochars[i] : ' '); break; case 'u': if (hdr->env->from && hdr->env->from->mailbox) { strfcpy(buf2, mutt_addr_for_display(hdr->env->from), sizeof(buf2)); if ((p = strpbrk(buf2, "%@"))) *p = 0; } else buf2[0] = 0; mutt_format_s(dest, destlen, prefix, buf2); break; case 'v': if (mutt_addr_is_user(hdr->env->from)) { if (hdr->env->to) mutt_format_s(buf2, sizeof(buf2), prefix, mutt_get_name(hdr->env->to)); else if (hdr->env->cc) mutt_format_s(buf2, sizeof(buf2), prefix, mutt_get_name(hdr->env->cc)); else *buf2 = 0; } else mutt_format_s(buf2, sizeof(buf2), prefix, mutt_get_name(hdr->env->from)); if ((p = strpbrk(buf2, " %@"))) *p = 0; mutt_format_s(dest, destlen, prefix, buf2); break; case 'Z': ch = ' '; if (WithCrypto && hdr->security & GOODSIGN) ch = 'S'; else if (WithCrypto && hdr->security & ENCRYPT) ch = 'P'; else if (WithCrypto && hdr->security & SIGN) ch = 's'; else if ((WithCrypto & APPLICATION_PGP) && hdr->security & PGPKEY) ch = 'K'; snprintf(buf2, sizeof(buf2), "%c%c%c", (THREAD_NEW ? 'n' : (THREAD_OLD ? 'o' : ((hdr->read && (ctx && ctx->msgnotreadyet != hdr->msgno)) ? (hdr->replied ? 'r' : ' ') : ( hdr->old ? 'O' : 'N')))), hdr->deleted ? 'D' : (hdr->attach_del ? 'd' : ch), hdr->tagged ? '*' : (hdr->flagged ? '!' : (Tochars && ((i = mutt_user_is_recipient(hdr)) < mutt_strlen(Tochars)) ? Tochars[i] : ' '))); mutt_format_s(dest, destlen, prefix, buf2); break; case 'X': { int count = mutt_count_body_parts(ctx, hdr); /* The recursion allows messages without depth to return 0. */ if (optional) optional = count != 0; snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, count); break; } case 'y': if (optional) optional = hdr->env->x_label ? 1 : 0; mutt_format_s(dest, destlen, prefix, NONULL(hdr->env->x_label)); break; case 'Y': if (hdr->env->x_label) { i = 1; /* reduce reuse recycle */ htmp = NULL; if (flags & M_FORMAT_TREE && (hdr->thread->prev && hdr->thread->prev->message && hdr->thread->prev->message->env->x_label)) htmp = hdr->thread->prev->message; else if (flags & M_FORMAT_TREE && (hdr->thread->parent && hdr->thread->parent->message && hdr->thread->parent->message->env->x_label)) htmp = hdr->thread->parent->message; if (htmp && (mutt_strcasecmp(hdr->env->x_label, htmp->env->x_label) == 0)) i = 0; } else i = 0; if (optional) optional = i; if (i) mutt_format_s(dest, destlen, prefix, NONULL(hdr->env->x_label)); else mutt_format_s(dest, destlen, prefix, ""); break; default: snprintf(dest, destlen, "%%%s%c", prefix, op); break; } if (optional) mutt_FormatString(dest, destlen, col, ifstring, hdr_format_str, (unsigned long)hfi, flags); else if (flags & M_FORMAT_OPTIONAL) mutt_FormatString(dest, destlen, col, elsestring, hdr_format_str, (unsigned long)hfi, flags); return src; #undef THREAD_NEW #undef THREAD_OLD }
static const char * sidebar_format_str(char *dest, size_t destlen, size_t col, char op, const char *src, const char *prefix, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) { /* casting from unsigned long - srsly?! */ struct sidebar_entry *sbe = (struct sidebar_entry *)data; unsigned int optional; char fmt[SHORT_STRING], buf[SHORT_STRING]; optional = flags & M_FORMAT_OPTIONAL; switch (op) { case 'F': if (!optional) { snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, sbe->flagged); } else if (sbe->flagged == 0) { optional = 0; } break; case '!': if (sbe->flagged == 0) mutt_format_s(dest, destlen, prefix, ""); if (sbe->flagged == 1) mutt_format_s(dest, destlen, prefix, "!"); if (sbe->flagged == 2) mutt_format_s(dest, destlen, prefix, "!!"); if (sbe->flagged > 2) { snprintf(buf, sizeof(buf), "%d!", sbe->flagged); mutt_format_s(dest, destlen, prefix, buf); } break; case 'S': snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, sbe->size); break; case 'N': if (!optional) { snprintf(fmt, sizeof(fmt), "%%%sd", prefix); snprintf(dest, destlen, fmt, sbe->new_messages); } else if (sbe->new_messages == 0) { optional = 0; } break; case 'B': mutt_format_s(dest, destlen, prefix, sbe->box); break; } if (optional) mutt_FormatString(dest, destlen, col, ifstring, sidebar_format_str, (unsigned long)sbe, flags); else if (flags & M_FORMAT_OPTIONAL) mutt_FormatString(dest, destlen, col, elsestring, sidebar_format_str, (unsigned long)sbe, flags); return src; }
static const char *_mutt_fmt_smime_command(char *dest, size_t destlen, size_t col, char op, const char *src, const char *prefix, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) { char fmt[16]; struct smime_command_context *cctx =(struct smime_command_context *) data; int optional =(flags & M_FORMAT_OPTIONAL); switch(op) { case 'C': { if (!optional) { char path[_POSIX_PATH_MAX]; char buf1[LONG_STRING], buf2[LONG_STRING]; struct stat sb; strfcpy(path, NONULL(SmimeCALocation), sizeof(path)); mutt_expand_path(path, sizeof(path)); mutt_quote_filename(buf1, sizeof(buf1), path); if (stat(path, &sb) != 0 || !S_ISDIR(sb.st_mode)) snprintf(buf2, sizeof(buf2), "-CAfile %s", buf1); else snprintf(buf2, sizeof(buf2), "-CApath %s", buf1); snprintf(fmt, sizeof(fmt), "%%%ss", prefix); snprintf(dest, destlen, fmt, buf2); } else if (!SmimeCALocation) optional = 0; break; } case 'c': { /* certificate(list) */ if (!optional) { snprintf(fmt, sizeof(fmt), "%%%ss", prefix); snprintf(dest, destlen, fmt, NONULL(cctx->certificates)); } else if (!cctx->certificates) optional = 0; break; } case 'i': { /* intermediate certificates */ if (!optional) { snprintf(fmt, sizeof(fmt), "%%%ss", prefix); snprintf(dest, destlen, fmt, NONULL(cctx->intermediates)); } else if (!cctx->intermediates) optional = 0; break; } case 's': { /* detached signature */ if (!optional) { snprintf(fmt, sizeof(fmt), "%%%ss", prefix); snprintf(dest, destlen, fmt, NONULL(cctx->sig_fname)); } else if (!cctx->sig_fname) optional = 0; break; } case 'k': { /* private key */ if (!optional) { snprintf(fmt, sizeof(fmt), "%%%ss", prefix); snprintf(dest, destlen, fmt, NONULL(cctx->key)); } else if (!cctx->key) optional = 0; break; } case 'a': { /* algorithm for encryption */ if (!optional) { snprintf(fmt, sizeof(fmt), "%%%ss", prefix); snprintf(dest, destlen, fmt, NONULL(cctx->cryptalg)); } else if (!cctx->key) optional = 0; break; } case 'f': { /* file to process */ if (!optional) { snprintf(fmt, sizeof(fmt), "%%%ss", prefix); snprintf(dest, destlen, fmt, NONULL(cctx->fname)); } else if (!cctx->fname) optional = 0; break; } default: *dest = '\0'; break; } if (optional) mutt_FormatString(dest, destlen, col, ifstring, _mutt_fmt_smime_command, data, 0); else if (flags & M_FORMAT_OPTIONAL) mutt_FormatString(dest, destlen, col, elsestring, _mutt_fmt_smime_command, data, 0); return(src); }
const char *_mutt_fmt_pgp_command (char *dest, size_t destlen, char op, const char *src, const char *prefix, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) { char fmt[16]; struct pgp_command_context *cctx = (struct pgp_command_context *) data; int optional = (flags & M_FORMAT_OPTIONAL); switch (op) { case 'r': { if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, NONULL (cctx->ids)); } else if (!cctx->ids) optional = 0; break; } case 'a': { if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, NONULL (cctx->signas)); } else if (!cctx->signas) optional = 0; break; } case 's': { if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, NONULL (cctx->sig_fname)); } else if (!cctx->sig_fname) optional = 0; break; } case 'f': { if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, NONULL (cctx->fname)); } else if (!cctx->fname) optional = 0; break; } case 'p': { if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, cctx->need_passphrase ? "PGPPASSFD=0" : ""); } else if (!cctx->need_passphrase || pgp_use_gpg_agent ()) optional = 0; break; } default: { *dest = '\0'; break; } } if (optional) mutt_FormatString (dest, destlen, ifstring, _mutt_fmt_pgp_command, data, 0); else if (flags & M_FORMAT_OPTIONAL) mutt_FormatString (dest, destlen, elsestring, _mutt_fmt_pgp_command, data, 0); return (src); }
static void mutt_smime_command(char *d, size_t dlen, struct smime_command_context *cctx, const char *fmt) { mutt_FormatString(d, dlen, 0, NONULL(fmt), _mutt_fmt_smime_command, (unsigned long) cctx, 0); }
static const char *mix_entry_fmt (char *dest, size_t destlen, size_t col, int cols, char op, const char *src, const char *prefix, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) { char fmt[16]; REMAILER *remailer = (REMAILER *) data; int optional = (flags & MUTT_FORMAT_OPTIONAL); switch (op) { case 'n': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sd", prefix); snprintf (dest, destlen, fmt, remailer->num); } break; case 'c': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, mix_format_caps(remailer)); } break; case 's': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, NONULL(remailer->shortname)); } else if (!remailer->shortname) optional = 0; break; case 'a': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, NONULL(remailer->addr)); } else if (!remailer->addr) optional = 0; break; default: *dest = '\0'; } if (optional) mutt_FormatString (dest, destlen, col, cols, ifstring, mutt_attach_fmt, data, 0); else if (flags & MUTT_FORMAT_OPTIONAL) mutt_FormatString (dest, destlen, col, cols, elsestring, mutt_attach_fmt, data, 0); return (src); }
void mutt_FormatString (char *dest, /* output buffer */ size_t destlen, /* output buffer len */ const char *src, /* template string */ format_t *callback, /* callback for processing */ unsigned long data, /* callback data */ format_flag flags) /* callback flags */ { char prefix[SHORT_STRING], buf[LONG_STRING], *cp, *wptr = dest, ch; char ifstring[SHORT_STRING], elsestring[SHORT_STRING]; size_t wlen, count, len; destlen--; /* save room for the terminal \0 */ wlen = (flags & M_FORMAT_ARROWCURSOR && option (OPTARROWCURSOR)) ? 3 : 0; while (*src && wlen < destlen) { if (*src == '%') { if (*++src == '%') { *wptr++ = '%'; wlen++; src++; continue; } if (*src == '?') { flags |= M_FORMAT_OPTIONAL; src++; } else { flags &= ~M_FORMAT_OPTIONAL; /* eat the format string */ cp = prefix; count = 0; while (count < sizeof (prefix) && (isdigit ((unsigned char) *src) || *src == '.' || *src == '-')) { *cp++ = *src++; count++; } *cp = 0; } if (!*src) break; /* bad format */ ch = *src++; /* save the character to switch on */ if (flags & M_FORMAT_OPTIONAL) { if (*src != '?') break; /* bad format */ src++; /* eat the `if' part of the string */ cp = ifstring; count = 0; while (count < sizeof (ifstring) && *src && *src != '?' && *src != '&') { *cp++ = *src++; count++; } *cp = 0; /* eat the `else' part of the string (optional) */ if (*src == '&') src++; /* skip the & */ cp = elsestring; count = 0; while (count < sizeof (elsestring) && *src && *src != '?') { *cp++ = *src++; count++; } *cp = 0; if (!*src) break; /* bad format */ src++; /* move past the trailing `?' */ } /* handle generic cases first */ if (ch == '>') { /* right justify to EOL */ ch = *src++; /* pad char */ /* calculate space left on line. if we've already written more data than will fit on the line, ignore the rest of the line */ count = (COLS < destlen ? COLS : destlen); if (count > wlen) { count -= wlen; /* how many chars left on this line */ mutt_FormatString (buf, sizeof (buf), src, callback, data, flags); len = mutt_strlen (buf); if (count > len) { count -= len; /* how many chars to pad */ memset (wptr, ch, count); wptr += count; wlen += count; } if (len + wlen > destlen) len = destlen - wlen; memcpy (wptr, buf, len); wptr += len; wlen += len; } break; /* skip rest of input */ } else if (ch == '|') { /* pad to EOL */ ch = *src++; if (destlen > COLS) destlen = COLS; if (destlen > wlen) { count = destlen - wlen; memset (wptr, ch, count); wptr += count; } break; /* skip rest of input */ } else { short tolower = 0; if (ch == '_') { ch = *src++; tolower = 1; } /* use callback function to handle this case */ src = callback (buf, sizeof (buf), ch, src, prefix, ifstring, elsestring, data, flags); if (tolower) mutt_strlower (buf); if ((len = mutt_strlen (buf)) + wlen > destlen) len = (destlen - wlen > 0) ? (destlen - wlen) : 0; memcpy (wptr, buf, len); wptr += len; wlen += len; } } else if (*src == '\\') { if (!*++src) break; switch (*src) { case 'n': *wptr = '\n'; break; case 't': *wptr = '\t'; break; case 'r': *wptr = '\r'; break; case 'f': *wptr = '\f'; break; case 'v': *wptr = '\v'; break; default: *wptr = *src; break; } src++; wptr++; wlen++; } else { *wptr++ = *src++; wlen++; } } *wptr = 0; if (flags & M_FORMAT_MAKEPRINT) { /* Make sure that the string is printable by changing all non-printable chars to dots, or spaces for non-printable whitespace */ for (cp = dest ; *cp ; cp++) if (!IsPrint (*cp) && !((flags & M_FORMAT_TREE) && (*cp <= M_TREE_MAX))) *cp = isspace ((unsigned char) *cp) ? ' ' : '.'; } }
void mutt_pgp_command (char *d, size_t dlen, struct pgp_command_context *cctx, const char *fmt) { mutt_FormatString (d, dlen, 0, MuttIndexWindow->cols, NONULL (fmt), _mutt_fmt_pgp_command, (unsigned long) cctx, 0); dprint (2, (debugfile, "mutt_pgp_command: %s\n", d)); }