void mutt_free_envelope (ENVELOPE ** p) { if (!*p) return; rfc822_free_address (&(*p)->return_path); rfc822_free_address (&(*p)->from); rfc822_free_address (&(*p)->to); rfc822_free_address (&(*p)->cc); rfc822_free_address (&(*p)->bcc); rfc822_free_address (&(*p)->sender); rfc822_free_address (&(*p)->reply_to); rfc822_free_address (&(*p)->mail_followup_to); mem_free (&(*p)->list_post); mem_free (&(*p)->subject); /* real_subj is just an offset to subject and shouldn't be freed */ mem_free (&(*p)->message_id); mem_free (&(*p)->supersedes); mem_free (&(*p)->date); mem_free (&(*p)->x_label); mem_free (&(*p)->organization); #ifdef USE_NNTP mem_free (&(*p)->newsgroups); mem_free (&(*p)->xref); mem_free (&(*p)->followup_to); mem_free (&(*p)->x_comment_to); #endif mutt_buffer_free (&(*p)->spam); mutt_free_list (&(*p)->references); mutt_free_list (&(*p)->in_reply_to); mutt_free_list (&(*p)->userhdrs); mem_free (p); }
/* imap_free_idata: Release and clear storage in an IMAP_DATA structure. */ void imap_free_idata (IMAP_DATA** idata) { if (!idata) return; FREE (&(*idata)->capstr); mutt_free_list (&(*idata)->flags); imap_mboxcache_free (*idata); mutt_buffer_free(&(*idata)->cmdbuf); FREE (&(*idata)->buf); mutt_bcache_close (&(*idata)->bcache); FREE (&(*idata)->cmds); FREE (idata); /* __FREE_CHECKED__ */ }
/* imap_new_idata: Allocate and initialise a new IMAP_DATA structure. * Returns NULL on failure (no mem) */ IMAP_DATA* imap_new_idata (void) { IMAP_DATA* idata = safe_calloc (1, sizeof (IMAP_DATA)); if (!idata) return NULL; if (!(idata->cmdbuf = mutt_buffer_init (NULL))) FREE (&idata); idata->cmdslots = ImapPipelineDepth + 2; if (!(idata->cmds = safe_calloc(idata->cmdslots, sizeof(*idata->cmds)))) { mutt_buffer_free(&idata->cmdbuf); FREE (&idata); } return idata; }
/* move all the headers from extra not present in base into base */ void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra) { /* copies each existing element if necessary, and sets the element * to NULL in the source so that mutt_free_envelope doesn't leave us * with dangling pointers. */ #define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; } MOVE_ELEM(return_path); MOVE_ELEM(from); MOVE_ELEM(to); MOVE_ELEM(cc); MOVE_ELEM(bcc); MOVE_ELEM(sender); MOVE_ELEM(reply_to); MOVE_ELEM(mail_followup_to); MOVE_ELEM(list_post); MOVE_ELEM(message_id); MOVE_ELEM(supersedes); MOVE_ELEM(date); MOVE_ELEM(x_label); if (!base->refs_changed) { MOVE_ELEM(references); } if (!base->irt_changed) { MOVE_ELEM(in_reply_to); } /* real_subj is subordinate to subject */ if (!base->subject) { base->subject = (*extra)->subject; base->real_subj = (*extra)->real_subj; (*extra)->subject = NULL; (*extra)->real_subj = NULL; } /* spam and user headers should never be hashed, and the new envelope may * have better values. Use new versions regardless. */ mutt_buffer_free (&base->spam); mutt_free_list (&base->userhdrs); MOVE_ELEM(spam); MOVE_ELEM(userhdrs); #undef MOVE_ELEM mutt_free_envelope(extra); }
/** * dump_macro - Dump a macro map to a buffer * @param buf Output buffer * @param menu Map menu * @param map Macro keymap */ static void dump_macro(struct Buffer *buf, struct Mapping *menu, struct Keymap *map) { char key_binding[MAX_SEQ]; km_expand_key(key_binding, MAX_SEQ, map); struct Buffer *tmp = mutt_buffer_new(); escape_string(tmp, map->macro); if (map->desc) { mutt_buffer_add_printf(buf, "macro %s %s \"%s\" \"%s\"\n", menu->name, key_binding, tmp->data, map->desc); } else { mutt_buffer_add_printf(buf, "macro %s %s \"%s\"\n", menu->name, key_binding, tmp->data); } mutt_buffer_free(&tmp); }
/** * icmd_bind - Parse 'bind' and 'macro' commands - Implements ::icommand_t */ static enum CommandResult icmd_bind(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err) { FILE *fp_out = NULL; char tempfile[PATH_MAX]; bool dump_all = false, bind = (data == 0); if (!MoreArgs(s)) dump_all = true; else mutt_extract_token(buf, s, 0); if (MoreArgs(s)) { /* More arguments potentially means the user is using the * ::command_t :bind command thus we delegate the task. */ return MUTT_CMD_ERROR; } struct Buffer *filebuf = mutt_buffer_alloc(4096); if (dump_all || (mutt_str_strcasecmp(buf->data, "all") == 0)) { dump_all_menus(filebuf, bind); } else { const int menu_index = mutt_map_get_value(buf->data, Menus); if (menu_index == -1) { mutt_buffer_printf(err, _("%s: no such menu"), buf->data); mutt_buffer_free(&filebuf); return MUTT_CMD_ERROR; } struct Mapping menu = { buf->data, menu_index }; dump_menu(filebuf, &menu, bind); } if (mutt_buffer_is_empty(filebuf)) { mutt_buffer_printf(err, _("%s: no %s for this menu"), dump_all ? "all" : buf->data, bind ? "binds" : "macros"); mutt_buffer_free(&filebuf); return MUTT_CMD_ERROR; } mutt_mktemp(tempfile, sizeof(tempfile)); fp_out = mutt_file_fopen(tempfile, "w"); if (!fp_out) { mutt_buffer_printf(err, _("Could not create temporary file %s"), tempfile); mutt_buffer_free(&filebuf); return MUTT_CMD_ERROR; } fputs(filebuf->data, fp_out); mutt_file_fclose(&fp_out); mutt_buffer_free(&filebuf); struct Pager info = { 0 }; if (mutt_pager((bind) ? "bind" : "macro", tempfile, 0, &info) == -1) { mutt_buffer_printf(err, _("Could not create temporary file %s"), tempfile); return MUTT_CMD_ERROR; } return MUTT_CMD_SUCCESS; }
/** * dump_config - Write all the config to a file * @param cs ConfigSet to dump * @param style Output style, e.g. #CS_DUMP_STYLE_MUTT * @param flags Flags, see #ConfigDumpFlags * @param fp File to write config to */ bool dump_config(struct ConfigSet *cs, enum CsDumpStyle style, ConfigDumpFlags flags, FILE *fp) { if (!cs) return false; struct HashElem *he = NULL; struct HashElem **list = get_elem_list(cs); if (!list) return false; /* LCOV_EXCL_LINE */ bool result = true; struct Buffer *value = mutt_buffer_alloc(256); struct Buffer *initial = mutt_buffer_alloc(256); struct Buffer *tmp = mutt_buffer_alloc(256); for (size_t i = 0; list[i]; i++) { mutt_buffer_reset(value); mutt_buffer_reset(initial); he = list[i]; const int type = DTYPE(he->type); if ((type == DT_SYNONYM) && !(flags & CS_DUMP_SHOW_SYNONYMS)) continue; // if ((type == DT_DISABLED) && !(flags & CS_DUMP_SHOW_DISABLED)) // continue; if (type != DT_SYNONYM) { /* If necessary, get the current value */ if ((flags & CS_DUMP_ONLY_CHANGED) || !(flags & CS_DUMP_HIDE_VALUE) || (flags & CS_DUMP_SHOW_DEFAULTS)) { int rc = cs_he_string_get(cs, he, value); if (CSR_RESULT(rc) != CSR_SUCCESS) { result = false; /* LCOV_EXCL_LINE */ break; /* LCOV_EXCL_LINE */ } const struct ConfigDef *cdef = he->data; if (IS_SENSITIVE(*cdef) && (flags & CS_DUMP_HIDE_SENSITIVE) && !mutt_buffer_is_empty(value)) { mutt_buffer_reset(value); mutt_buffer_addstr(value, "***"); } if ((type == DT_PATH) && (value->data[0] == '/')) mutt_pretty_mailbox(value->data, value->dsize); if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) && (type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING)) { mutt_buffer_reset(tmp); pretty_var(value->data, tmp); mutt_buffer_strcpy(value, tmp->data); } } /* If necessary, get the default value */ if (flags & (CS_DUMP_ONLY_CHANGED | CS_DUMP_SHOW_DEFAULTS)) { int rc = cs_he_initial_get(cs, he, initial); if (CSR_RESULT(rc) != CSR_SUCCESS) { result = false; /* LCOV_EXCL_LINE */ break; /* LCOV_EXCL_LINE */ } if ((type == DT_PATH) && !(he->type & DT_MAILBOX)) mutt_pretty_mailbox(initial->data, initial->dsize); if ((type != DT_BOOL) && (type != DT_NUMBER) && (type != DT_LONG) && (type != DT_QUAD) && !(flags & CS_DUMP_NO_ESCAPING)) { mutt_buffer_reset(tmp); pretty_var(initial->data, tmp); mutt_buffer_strcpy(initial, tmp->data); } } } if (style == CS_DUMP_STYLE_MUTT) dump_config_mutt(cs, he, value, initial, flags, fp); else dump_config_neo(cs, he, value, initial, flags, fp); } FREE(&list); mutt_buffer_free(&value); mutt_buffer_free(&initial); mutt_buffer_free(&tmp); return result; }