static int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen, char *newdir, size_t ndlen) { const char *basename; char parent[_POSIX_PATH_MAX]; char *p; strfcpy (parent, NONULL (path), sizeof (parent)); if ((p = strrchr (parent, '/'))) { *p = '\0'; basename = p + 1; } else { strfcpy (parent, ".", sizeof (parent)); basename = path; } snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX"); if (mkdtemp(newdir) == NULL) { dprint(1, (debugfile, "mutt_mkwrapdir: mkdtemp() failed\n")); return -1; } if (snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename)) >= nflen) { rmdir(newdir); dprint(1, (debugfile, "mutt_mkwrapdir: string was truncated\n")); return -1; } return 0; }
int mutt_addrlist_to_local (ADDRESS *a) { char *user, *domain; char *tmp = NULL; for (; a; a = a->next) { if (!a->mailbox) continue; if (!check_idn (a)) continue; if (mbox_to_udomain (a->mailbox, &user, &domain) == -1) continue; if (mutt_idna_to_local (domain, &tmp, 0) == 0) { safe_realloc (&a->mailbox, mutt_strlen (user) + mutt_strlen (tmp) + 2); sprintf (a->mailbox, "%s@%s", NONULL (user), NONULL (tmp)); /* __SPRINTF_CHECKED__ */ a->idn_checked = 0; } FREE (&tmp); } return 0; }
/* convert just for displaying purposes */ const char *mutt_addr_for_display (ADDRESS *a) { static char *buff = NULL; char *tmp = NULL; /* user and domain will be either allocated or reseted to the NULL in * the mbox_to_udomain(), but for safety... */ char *domain = NULL; char *user = NULL; FREE (&buff); if (!check_idn (a)) return a->mailbox; if (mbox_to_udomain (a->mailbox, &user, &domain) != 0) return a->mailbox; if (mutt_idna_to_local (domain, &tmp, MI_MAY_BE_IRREVERSIBLE) != 0) { FREE (&tmp); return a->mailbox; } safe_realloc (&buff, mutt_strlen (tmp) + mutt_strlen (user) + 2); sprintf (buff, "%s@%s", NONULL(user), NONULL(tmp)); /* __SPRINTF_CHECKED__ */ FREE (&tmp); return buff; }
static int mutt_mkwrapdir (const char *path, char *newfile, size_t nflen, char *newdir, size_t ndlen) { const char *basename; char parent[_POSIX_PATH_MAX]; char *p; int rv; strfcpy (parent, NONULL (path), sizeof (parent)); if ((p = strrchr (parent, '/'))) { *p = '\0'; basename = p + 1; } else { strfcpy (parent, ".", sizeof (parent)); basename = path; } do { snprintf (newdir, ndlen, "%s/%s", parent, ".muttXXXXXX"); mktemp (newdir); } while ((rv = mkdir (newdir, 0700)) == -1 && errno == EEXIST); if (rv == -1) return -1; snprintf (newfile, nflen, "%s/%s", newdir, NONULL(basename)); return 0; }
ADDRESS *mutt_default_from (void) { ADDRESS *adr; const char *fqdn = mutt_fqdn(1); /* * Note: We let $from override $realname here. Is this the right * thing to do? */ if (From) adr = rfc822_cpy_adr_real (From); else if (option (OPTUSEDOMAIN)) { adr = rfc822_new_address (); adr->mailbox = safe_malloc (mutt_strlen (Username) + mutt_strlen (fqdn) + 2); sprintf (adr->mailbox, "%s@%s", NONULL(Username), NONULL(fqdn)); /* __SPRINTF_CHECKED__ */ } else { adr = rfc822_new_address (); adr->mailbox = safe_strdup (NONULL(Username)); } return (adr); }
void _mutt_mktemp (char *s, const char *src, int line) { snprintf (s, _POSIX_PATH_MAX, "%s/muttng-%s-%d-%d-%d-%x%x", NONULL (Tempdir), NONULL (Hostname), (int) getuid (), (int) getpid (), Counter++, (unsigned int) rand(), (unsigned int) rand()); debug_print (1, ("%s:%d: mutt_mktemp returns \"%s\".\n", src, line, s)); unlink (s); }
int mutt_strxcmp(const char *a, const char *b) { size_t xa, xb; xa = strcspn(NONULL(a), "\r\n"); xb = strcspn(NONULL(b), "\r\n"); if (xb != xa) return -1; if (!xa) return 0; return strncmp(NONULL(a), NONULL(b), xa); }
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; }
static bool test_string_set(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); const char *valid[] = { "*****@*****.**", "*****@*****.**", NULL }; const char *name = "Damson"; char *addr = NULL; int rc; for (unsigned int i = 0; i < mutt_array_size(valid); i++) { mutt_buffer_reset(err); rc = cs_str_string_set(cs, name, valid[i], err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); return false; } addr = VarDamson ? VarDamson->mailbox : NULL; if (!TEST_CHECK(mutt_str_strcmp(addr, valid[i]) == 0)) { TEST_MSG("Value of %s wasn't changed\n", name); return false; } TEST_MSG("%s = '%s', set by '%s'\n", name, NONULL(addr), NONULL(valid[i])); } name = "Elderberry"; for (unsigned int i = 0; i < mutt_array_size(valid); i++) { mutt_buffer_reset(err); rc = cs_str_string_set(cs, name, valid[i], err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); return false; } addr = VarElderberry ? VarElderberry->mailbox : NULL; if (!TEST_CHECK(mutt_str_strcmp(addr, valid[i]) == 0)) { TEST_MSG("Value of %s wasn't changed\n", name); return false; } TEST_MSG("%s = '%s', set by '%s'\n", name, NONULL(addr), NONULL(valid[i])); } log_line(__func__); return true; }
static void dump_native(struct ConfigSet *cs, const char *parent, const char *child) { intptr_t pval = cs_str_native_get(cs, parent, NULL); intptr_t cval = cs_str_native_get(cs, child, NULL); struct Address *pa = (struct Address *) pval; struct Address *ca = (struct Address *) cval; char *pstr = pa ? pa->mailbox : NULL; char *cstr = ca ? ca->mailbox : NULL; TEST_MSG("%15s = %s\n", parent, NONULL(pstr)); TEST_MSG("%15s = %s\n", child, NONULL(cstr)); }
void Event::_unsetContext (const char* file, int line) { Event::context context; context = contextStack->back (); contextStack->pop_back (); DEBUGPRINT(D_EVENT,("leave ctx=%s from %s:%d", CtxStr[context], NONULL (file), line)); sigContextChange.emit (context, E_CONTEXT_LEAVE); if (contextStack->size () != 0) { context = contextStack->back (); DEBUGPRINT(D_EVENT,("re-enter ctx=%s from %s:%d", CtxStr[context], NONULL (file), line)); sigContextChange.emit (context, E_CONTEXT_REENTER); } }
static bool test_native_set(struct ConfigSet *cs, struct Buffer *err) { log_line(__func__); struct Address *a = address_new("*****@*****.**"); const char *name = "Ilama"; char *addr = NULL; bool result = false; mutt_buffer_reset(err); int rc = cs_str_native_set(cs, name, (intptr_t) a, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); goto tbns_out; } addr = VarIlama ? VarIlama->mailbox : NULL; if (!TEST_CHECK(mutt_str_strcmp(addr, a->mailbox) == 0)) { TEST_MSG("Value of %s wasn't changed\n", name); goto tbns_out; } TEST_MSG("%s = '%s', set by '%s'\n", name, NONULL(addr), a->mailbox); name = "Jackfruit"; mutt_buffer_reset(err); rc = cs_str_native_set(cs, name, 0, err); if (!TEST_CHECK(CSR_RESULT(rc) == CSR_SUCCESS)) { TEST_MSG("%s\n", err->data); goto tbns_out; } if (!TEST_CHECK(VarJackfruit == NULL)) { TEST_MSG("Value of %s wasn't changed\n", name); goto tbns_out; } addr = VarJackfruit ? VarJackfruit->mailbox : NULL; TEST_MSG("%s = '%s', set by NULL\n", name, NONULL(addr)); log_line(__func__); result = true; tbns_out: address_free(&a); return result; }
static void apply_config(void) { char buff[1024]; if (show_title) { Epplet_gadget_move(in_label, 3, 13); Epplet_gadget_move(out_label, 3, 30); Epplet_gadget_move(in_bar, 3, 22); Epplet_gadget_move(out_bar, 3, 39); Epplet_gadget_show(title); } else { Epplet_gadget_move(in_label, 4, 4); Epplet_gadget_move(out_label, 4, 24); Epplet_gadget_move(in_bar, 4, 14); Epplet_gadget_move(out_bar, 4, 36); Epplet_gadget_hide(title); } Epplet_modify_config("title", (show_title ? "1" : "0")); strcpy(buff, NONULL(Epplet_textbox_contents(cfg_tb_dev))); if (strcmp(buff, device_string)) { Epplet_modify_config("dev", buff); device_string = Epplet_query_config("dev"); last_in = last_out = 0; } timer_cb(NULL); }
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)); }
/* UTF-8 aware string length computing. * Returns the number of elements pushed on the stack. */ static gint luaH_utf8_strlen(lua_State *L) { const gchar *cmd = luaL_checkstring(L, 1); lua_pushnumber(L, (ssize_t) g_utf8_strlen(NONULL(cmd), -1)); return 1; }
/* Modified by blong to accept a "suggestion" for file name. If * that file exists, then construct one with unique name but * keep any extension. This might fail, I guess. * Renamed to mutt_adv_mktemp so I only have to change where it's * called, and not all possible cases. */ void mutt_adv_mktemp (char *s, size_t l) { char buf[_POSIX_PATH_MAX]; char tmp[_POSIX_PATH_MAX]; char *period; size_t sl; struct stat sb; strfcpy (buf, NONULL (Tempdir), sizeof (buf)); mutt_expand_path (buf, sizeof (buf)); if (s[0] == '\0') { snprintf (s, l, "%s/muttXXXXXX", buf); mktemp (s); } else { strfcpy (tmp, s, sizeof (tmp)); mutt_sanitize_filename (tmp, 1); snprintf (s, l, "%s/%s", buf, tmp); if (lstat (s, &sb) == -1 && errno == ENOENT) return; if ((period = strrchr (tmp, '.')) != NULL) *period = 0; snprintf (s, l, "%s/%s.XXXXXX", buf, tmp); mktemp (s); if (period != NULL) { *period = '.'; sl = mutt_strlen(s); strfcpy(s + sl, period, l - sl); } } }
/* mutt_account_match: compare account info (host/port/user) */ int mutt_account_match(const ACCOUNT* a1, const ACCOUNT* a2) { const char* user = NONULL(Username); if (a1->type != a2->type) return 0; if (ascii_strcasecmp(a1->host, a2->host)) return 0; if (a1->port != a2->port) return 0; #if USE_IMAP if (a1->type == M_ACCT_TYPE_IMAP) { if (ImapUser) user = ImapUser; } #endif if (a1->flags & a2->flags & M_ACCT_USER) return (!strcmp(a1->user, a2->user)); if (a1->flags & M_ACCT_USER) return (!strcmp(a1->user, user)); if (a2->flags & M_ACCT_USER) return (!strcmp(a2->user, user)); return 1; }
static void redraw_mix_line (LIST *chain) { int c; char *t; mvaddstr (HDR_MIX, 0, " Mix: "); if (!chain) { addstr ("<no chain defined>"); clrtoeol (); return; } for (c = 12; chain; chain = chain->next) { t = chain->data; if (t && t[0] == '0' && t[1] == '\0') t = "<random>"; if (c + mutt_strlen (t) + 2 >= COLS) break; addstr (NONULL(t)); if (chain->next) addstr (", "); c += mutt_strlen (t) + 2; } }
static void draw_envelope (HEADER *msg, char *fcc) { draw_envelope_addr (HDR_FROM, msg->env->from); draw_envelope_addr (HDR_TO, msg->env->to); draw_envelope_addr (HDR_CC, msg->env->cc); draw_envelope_addr (HDR_BCC, msg->env->bcc); mvprintw (HDR_SUBJECT, 0, TITLE_FMT, Prompts[HDR_SUBJECT - 1]); mutt_paddstr (W, NONULL (msg->env->subject)); draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to); mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]); mutt_paddstr (W, fcc); if (WithCrypto) redraw_crypt_lines (msg); #ifdef MIXMASTER redraw_mix_line (msg->chain); #endif SETCOLOR (MT_COLOR_STATUS); mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments")); clrtoeol (); NORMAL_COLOR; }
/* mutt_account_match: compare account info (host/port/user) */ int mutt_account_match(const ACCOUNT *a1, const ACCOUNT *a2) { const char *user = NONULL(Username); if (a1->type != a2->type) return 0; if (ascii_strcasecmp(a1->host, a2->host)) return 0; if (a1->port != a2->port) return 0; #ifdef USE_POP if ((a1->type == M_ACCT_TYPE_POP) && PopUser) user = PopUser; #endif /* ifdef USE_POP */ if (a1->flags & a2->flags & M_ACCT_USER) return !strcmp(a1->user, a2->user); if (a1->flags & M_ACCT_USER) return !strcmp(a1->user, user); if (a2->flags & M_ACCT_USER) return !strcmp(a2->user, user); return 1; }
static int mh_mkstemp (CONTEXT *dest, FILE **fp, char **tgt) { int fd; char path[_POSIX_PATH_MAX]; FOREVER { snprintf (path, _POSIX_PATH_MAX, "%s/.mutt-%s-%d-%d", dest->path, NONULL (Hostname), (int) getpid (), Counter++); if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0600)) == -1) { if (errno != EEXIST) { mutt_perror (path); return -1; } } else { *tgt = safe_strdup (path); break; } } if ((*fp = fdopen (fd, "w")) == NULL) { FREE (tgt); close (fd); unlink (path); return (-1); } return 0; }
int mh_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr) { int fd; char path[_POSIX_PATH_MAX]; FOREVER { snprintf (path, _POSIX_PATH_MAX, "%s/.mutt-%s-%d-%d", dest->path, NONULL (Hostname), (int) getpid (), Counter++); if ((fd = open (path, O_WRONLY | O_EXCL | O_CREAT, 0600)) == -1) { if (errno != EEXIST) { mutt_perror (path); return -1; } } else { msg->path = safe_strdup (path); break; } } if ((msg->fp = fdopen (fd, "w")) == NULL) { FREE (&msg->path); close (fd); unlink (path); return (-1); } return 0; }
static int smtp_helo (CONNECTION* conn) { char buf[LONG_STRING]; const char* fqdn; memset (Capabilities, 0, sizeof (Capabilities)); if (!Esmtp) { /* if TLS or AUTH are requested, use EHLO */ if (conn->account.flags & M_ACCT_USER) Esmtp = 1; #ifdef USE_SSL if (option (OPTSSLFORCETLS) || quadoption (OPT_SSLSTARTTLS) != M_NO) Esmtp = 1; #endif } if(!(fqdn = mutt_fqdn (0))) fqdn = NONULL (Hostname); snprintf (buf, sizeof (buf), "%s %s\r\n", Esmtp ? "EHLO" : "HELO", fqdn); /* XXX there should probably be a wrapper in mutt_socket.c that * repeatedly calls conn->write until all data is sent. This * currently doesn't check for a short write. */ if (mutt_socket_write (conn, buf) == -1) return smtp_err_write; return smtp_get_resp (conn); }
/** * compress_format_str - Expand the filenames in a command string - Implements ::format_t * * | Expando | Description * |:--------|:-------------------------------------------------------- * | \%f | Compressed file * | \%t | Plaintext, temporary file */ static const char *compress_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, unsigned long data, MuttFormatFlags flags) { if (!buf || (data == 0)) return src; struct Mailbox *m = (struct Mailbox *) data; const char *stuffing = NULL; switch (op) { case 'f': /* Compressed file */ stuffing = mutt_path_escape(m->realpath); break; case 't': /* Plaintext, temporary file */ stuffing = mutt_path_escape(m->path); break; } snprintf(buf, buflen, "%s", NONULL(stuffing)); return src; }
/** UTF-8 aware string length computing. * \param L The Lua VM state. * \return The number of elements pushed on stack. */ static int luaA_mbstrlen(lua_State *L) { const char *cmd = luaL_checkstring(L, 1); lua_pushnumber(L, (ssize_t) mbstowcs(NULL, NONULL(cmd), 0)); return 1; }
static void draw_envelope (HEADER *msg, char *fcc) { draw_envelope_addr (HDR_FROM, msg->env->from); draw_envelope_addr (HDR_TO, msg->env->to); draw_envelope_addr (HDR_CC, msg->env->cc); draw_envelope_addr (HDR_BCC, msg->env->bcc); mvprintw (HDR_SUBJECT, 0, TITLE_FMT "%-*.*s", Prompts[HDR_SUBJECT - 1], W, W, NONULL(msg->env->subject)); draw_envelope_addr (HDR_REPLYTO, msg->env->reply_to); mvprintw (HDR_FCC, 0, TITLE_FMT "%-*.*s", Prompts[HDR_FCC - 1], W, W, fcc); #ifdef HAVE_PGP redraw_pgp_lines (msg->pgp); #endif /* HAVE_PGP */ #ifdef MIXMASTER redraw_mix_line (msg->chain); #endif SETCOLOR (MT_COLOR_STATUS); mvaddstr (HDR_ATTACH - 1, 0, _("-- Attachments")); BKGDSET (MT_COLOR_STATUS); clrtoeol (); BKGDSET (MT_COLOR_NORMAL); SETCOLOR (MT_COLOR_NORMAL); }
static void post_entry (char *s, size_t slen, MUTTMENU *menu, int entry) { CONTEXT *ctx = (CONTEXT *) menu->data; _mutt_make_string (s, slen, NONULL (HdrFmt), ctx, ctx->hdrs[entry], M_FORMAT_ARROWCURSOR); }
/* mutt_account_getuser: retrieve username into ACCOUNT, if necessary */ int mutt_account_getuser (ACCOUNT* account) { char prompt[SHORT_STRING]; /* already set */ if (account->flags & M_ACCT_USER) return 0; #ifdef USE_IMAP else if ((account->type == M_ACCT_TYPE_IMAP) && ImapUser) strfcpy (account->user, ImapUser, sizeof (account->user)); #endif #ifdef USE_POP else if ((account->type == M_ACCT_TYPE_POP) && PopUser) strfcpy (account->user, PopUser, sizeof (account->user)); #endif #ifdef USE_NNTP else if ((account->type == M_ACCT_TYPE_NNTP) && NntpUser) strfcpy (account->user, NntpUser, sizeof (account->user)); #endif else if (option (OPTNOCURSES)) return -1; /* prompt (defaults to unix username), copy into account->user */ else { snprintf (prompt, sizeof (prompt), _("Username at %s: "), account->host); strfcpy (account->user, NONULL (Username), sizeof (account->user)); if (mutt_get_field_unbuffered (prompt, account->user, sizeof (account->user), 0)) return -1; } account->flags |= M_ACCT_USER; return 0; }
/** * Find matching long option. * * This function searches the option list for a long option which * matches the given string. * * @param opt The long option string to match against. * @return The index of the matching option, or -1 if not found. * * @see @link DOXGRP_OPT Command Line Option Parser @endlink, is_valid_option() * @ingroup DOXGRP_OPT */ static spif_int32_t find_long_option(spif_charptr_t opt) { spif_int32_t j; D_OPTIONS(("opt == \"%s\"\n", NONULL(opt))); /* Check to see if we have a long option that matches this. */ for (j = 0; j < SPIFOPT_NUMOPTS_GET(); j++) { size_t l; l = strlen((char *) SPIFOPT_OPT_LONG(j)); /* Look for matches to the part before the =, if any. */ if (!strncasecmp((char *) SPIFOPT_OPT_LONG(j), (char *) opt, l) && (opt[l] == '=' || !opt[l])) { /* Got one. */ D_OPTIONS(("Match found at %d: %s == %s\n", j, SPIFOPT_OPT_LONG(j), opt)); return j; } } /* No matching long option found. Report an error and continue with the next arg. */ libast_print_error("Unrecognized long option --%s\n", opt); CHECK_BAD(); return ((spif_int32_t) -1); }
static void include_header (int quote, FILE * ifp, struct header * hdr, FILE * ofp, char *_prefix) { int chflags = CH_DECODE; char prefix[SHORT_STRING]; if (bit_val(options, OPTWEED)) chflags |= CH_WEED | CH_REORDER; if (quote) { if (_prefix) strfcpy (prefix, _prefix, sizeof (prefix)); else if (!bit_val(options, OPTTEXTFLOWED)) _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), Context, hdr, 0); else strfcpy (prefix, ">", sizeof (prefix)); chflags |= CH_PREFIX; } mutt_copy_header (ifp, hdr, ofp, chflags, quote ? prefix : NULL); }