if((fpin = fopen(a->filename, "r")) && (fpout = safe_fopen(tempfile, "w")))
{
mutt_copy_stream (fpin, fpout);
- FREE(&a->filename);
- a->filename = safe_strdup(tempfile);
+ mutt_str_replace (&a->filename, tempfile);
a->unlink = 1;
if(a->stamp >= st.st_mtime)
}
else
{
- safe_free ((void **) &Mask.pattern);
+ mutt_str_replace (&Mask.pattern, buf);
regfree (Mask.rx);
safe_free ((void **) &Mask.rx);
- Mask.pattern = safe_strdup (buf);
Mask.rx = rx;
Mask.not = not;
if ((p = pgp_ask_for_key (_("Sign as: "), NULL, KEYFLAG_CANSIGN, PGP_PUBRING)))
{
snprintf (input_signas, sizeof (input_signas), "0x%s", pgp_keyid (p));
- safe_free((void **) &PgpSignAs); PgpSignAs = safe_strdup (input_signas);
- safe_free((void **) &PgpSignMicalg); PgpSignMicalg = safe_strdup (pgp_pkalg_to_mic (p->algorithm));
+ mutt_str_replace (&PgpSignAs, input_signas);
+ mutt_str_replace (&PgpSignMicalg, pgp_pkalg_to_mic (p->algorithm));
pgp_free_key (&p);
bits |= PGPSIGN;
mutt_error _("Unknown MIC algorithm, valid ones are: pgp-md5, pgp-sha1, pgp-rmd160");
}
else
- {
- safe_free ((void **) &PgpSignMicalg);
- PgpSignMicalg = safe_strdup (input_micalg);
- }
+ mutt_str_replace (&PgpSignMicalg, input_micalg);
}
}
break;
buf[0] = 0;
if (mutt_get_field ("Subject: ", buf, sizeof (buf), 0) == 0)
{
- safe_free ((void **) &msg->env->subject);
- msg->env->subject = safe_strdup (buf);
+ mutt_str_replace (&msg->env->subject, buf);
move (HDR_SUBJECT, HDR_XOFFSET);
clrtoeol ();
if (msg->env->subject)
/* header names should not be translated */
if (mutt_get_field ("Description: ", buf, sizeof (buf), 0) == 0)
{
- safe_free ((void **) &idx[menu->current]->content->description);
- idx[menu->current]->content->description = safe_strdup (buf);
+ mutt_str_replace (&idx[menu->current]->content->description, buf);
menu->redraw = REDRAW_CURRENT;
}
break;
if(mutt_rename_file (idx[menu->current]->content->filename, fname))
break;
- safe_free ((void **) &idx[menu->current]->content->filename);
- idx[menu->current]->content->filename = safe_strdup (fname);
+ mutt_str_replace (&idx[menu->current]->content->filename, fname);
menu->redraw = REDRAW_CURRENT;
if(idx[menu->current]->content->stamp >= st.st_mtime)
menu->max = idxlen;
idx[menu->current]->content->type = itype;
- safe_free ((void **) &idx[menu->current]->content->subtype);
- idx[menu->current]->content->subtype = safe_strdup (p);
+ mutt_str_replace (&idx[menu->current]->content->subtype, p);
idx[menu->current]->content->unlink = 1;
menu->redraw |= REDRAW_INDEX | REDRAW_STATUS;
if (Context)
{
- FREE (&LastFolder);
- LastFolder = safe_strdup (Context->path);
- }
+ mutt_str_replace (&LastFolder, Context->path);
- if (Context)
- {
if (mx_close_mailbox (Context) != 0)
{
menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
addstr ("Subject: ");
strfcpy (tmp, e->subject ? e->subject: "", sizeof (tmp));
if (mutt_enter_string ((unsigned char *) tmp, sizeof (tmp), LINES-1, 9, 0) == 0)
- {
- safe_free ((void **) &e->subject);
- e->subject = safe_strdup (tmp);
- }
+ mutt_str_replace (&e->subject, tmp);
addch ('\n');
}
addstr (_("missing filename.\n"));
break;
case 's':
- safe_free ((void **) &msg->env->subject);
- msg->env->subject = safe_strdup (p);
+ mutt_str_replace (&msg->env->subject, p);
break;
case 't':
msg->env->to = rfc822_parse_adrlist (msg->env->to, p);
if (prev < 0) prev = HistSize - 1;
if (!h->hist[prev] || mutt_strcmp (h->hist[prev], s) != 0)
{
- safe_free ((void **) &h->hist[h->last]);
- h->hist[h->last++] = safe_strdup (s);
+ mutt_str_replace (&h->hist[h->last++], s);
if (h->last > HistSize - 1)
h->last = 0;
}
{
case DT_STR:
if (p->init)
- {
- FREE (p->data);
- *((char **) p->data) = safe_strdup ((char *) p->init);
- }
+ mutt_str_replace ((char **) p->data, (char *) p->init);
break;
case DT_PATH:
if (p->init)
{
char path[_POSIX_PATH_MAX];
- FREE (p->data);
strfcpy (path, (char *) p->init, sizeof (path));
mutt_expand_path (path, sizeof (path));
- *((char **) p->data) = safe_strdup (path);
+ mutt_str_replace ((char **) p->data, path);
}
break;
case DT_ADDR:
return (p);
}
+void mutt_str_replace (char **p, const char *s)
+{
+ if (*p)
+ free (*p);
+ *p = safe_strdup (s);
+}
+
/* convert all characters in the string to lowercase */
char *mutt_strlower (char *s)
{
break;
case 'F':
- FREE (&Muttrc);
- Muttrc = safe_strdup (optarg);
+ mutt_str_replace (&Muttrc, optarg);
break;
case 'f':
_("Reverse search for: "),
buf, sizeof (buf), M_CLEAR) != 0 || !buf[0])
return (-1);
- safe_free ((void **) &menu->searchBuf);
- menu->searchBuf = safe_strdup (buf);
+ mutt_str_replace (&menu->searchBuf, buf);
menu->searchDir = (op == OP_SEARCH) ? M_SEARCH_DOWN : M_SEARCH_UP;
}
else
if (safe_rename (msg->path, full) == 0)
{
if (hdr)
- {
- FREE (&hdr->path);
- hdr->path = safe_strdup (path);
- }
+ mutt_str_replace (&hdr->path, path);
FREE (&msg->path);
return 0;
}
if (safe_rename (msg->path, path) == 0)
{
if (hdr)
- {
- FREE (&hdr->path);
- hdr->path = safe_strdup (tmp);
- }
+ mutt_str_replace (&hdr->path, tmp);
FREE (&msg->path);
return 0;
}
{
snprintf (newpath, _POSIX_PATH_MAX, "%s/%s", ctx->path, h->path);
if ((rc = safe_rename (newpath, oldpath)) == 0)
- {
- FREE (&h->path);
- h->path = safe_strdup (partpath);
- }
+ mutt_str_replace (&h->path, partpath);
}
}
else mx_close_message (&dest);
mutt_perror ("rename");
return (-1);
}
- safe_free ((void **) &h->path);
- h->path = safe_strdup (partpath);
+ mutt_str_replace (&h->path, partpath);
}
return (0);
}
ctx->hdrs[i]->read ? "R" : ""));
if(mutt_strcmp(ctx->hdrs[i]->path, p->h->path))
- {
- safe_free((void **) &ctx->hdrs[i]->path);
- ctx->hdrs[i]->path = safe_strdup(p->h->path);
- }
+ mutt_str_replace (&ctx->hdrs[i]->path, p->h->path);
if(modified)
{
{
if (mutt_strcasecmp (attribute, q->attribute) == 0)
{
- safe_free((void **) &q->value);
- q->value = safe_strdup(value);
+ mutt_str_replace (&q->value, value);
return;
}
}
* have allocated space if a "name=filename" parameter was
* specified.
*/
- safe_free ((void **) &ct->filename);
- ct->filename = safe_strdup (s);
+ mutt_str_replace (&ct->filename, s);
}
if ((s = mutt_get_parameter ("name", parms)) != 0)
ct->form_name = safe_strdup (s);
parse_content_disposition (c, p);
else if (!mutt_strcasecmp ("description", line + 8))
{
- safe_free ((void **) &p->description);
- p->description = safe_strdup (c);
+ mutt_str_replace (&p->description, c);
rfc2047_decode (p->description, p->description, mutt_strlen (p->description) + 1);
}
}
if (!b->parts)
{
b->type = TYPETEXT;
- safe_free ((void **) &b->subtype);
- b->subtype = safe_strdup ("plain");
+ mutt_str_replace (&b->subtype, "plain");
}
}
{
if (hdr)
{
- safe_free ((void **) &hdr->content->description);
- hdr->content->description = safe_strdup (p);
+ mutt_str_replace (&hdr->content->description, p);
rfc2047_decode (hdr->content->description,
hdr->content->description,
mutt_strlen (hdr->content->description) + 1);
case 'd':
if (!mutt_strcasecmp ("ate", line + 1))
{
- safe_free((void **)&e->date);
- e->date = safe_strdup(p);
+ mutt_str_replace (&e->date, p);
if (hdr)
hdr->date_sent = mutt_parse_date (p, hdr);
matched = 1;
if (whatfor)
{
if (l)
- {
- safe_free ((void **) &l->dflt);
- l->dflt = safe_strdup (resp);
- }
+ mutt_str_replace (&l->dflt, resp);
else
{
l = safe_malloc (sizeof (struct pgp_cache));
}
if (set_signas || *pgp_sign_as)
- {
- safe_free((void **) &PgpSignAs);
- PgpSignAs = safe_strdup(pgp_sign_as);
- }
+ mutt_str_replace (&PgpSignAs, pgp_sign_as);
/* the micalg field must not be empty */
if (set_signas && *pgp_sign_micalg)
- {
- safe_free((void **) &PgpSignMicalg);
- PgpSignMicalg = safe_strdup(pgp_sign_micalg);
- }
+ mutt_str_replace (&PgpSignMicalg, pgp_sign_micalg);
return pgp;
}
return -1;
}
- safe_free ((void *) &b->filename);
- b->filename = safe_strdup (file);
+ mutt_str_replace (&b->filename, file);
b->unlink = 1;
if (mutt_is_text_type (b->type, b->subtype))
void mutt_show_error (void);
void mutt_signal_init (void);
void mutt_stamp_attachment (BODY *a);
+void mutt_str_replace (char **p, const char *s);
void mutt_tabs_to_spaces (char *);
void mutt_tag_set_flag (int, int);
void mutt_unblock_signals (void);
if (idx[x]->tree)
{
if (mutt_strcmp (idx[x]->tree, buf) != 0)
- {
- safe_free ((void **) &idx[x]->tree);
- idx[x]->tree = safe_strdup (buf);
- }
+ mutt_str_replace (&idx[x]->tree, buf);
}
else
idx[x]->tree = safe_strdup (buf);
{
field++;
field = mutt_skip_whitespace (field);
- safe_free ((void **) entry);
- *entry = safe_strdup (field);
+ mutt_str_replace (entry, field);
}
return 1;
}
if (ptr->personal)
{
rfc2047_encode_string (buffer, sizeof (buffer), (const unsigned char *)ptr->personal);
- safe_free ((void **) &ptr->personal);
- ptr->personal = safe_strdup (buffer);
+ mutt_str_replace (&ptr->personal, buffer);
}
#ifdef EXACT_ADDRESS
if (ptr->val)
{
rfc2047_encode_string (buffer, sizeof (buffer), (const unsigned char *)ptr->val);
- safe_free ((void **) &ptr->val);
- ptr->val = safe_strdup (buffer);
+ mutt_str_replace (&ptr->val, buffer);
}
#endif
ptr = ptr->next;
mutt_message _("No subject, aborting.");
return (-1);
}
- safe_free ((void **) &en->subject);
- en->subject = safe_strdup (buf);
+ mutt_str_replace (&en->subject, buf);
return 0;
}
if (t->description)
{
rfc2047_encode_string (tmp, sizeof (tmp), (unsigned char *) t->description);
- safe_free ((void **) &t->description);
- t->description = safe_strdup (tmp);
+ mutt_str_replace (&t->description, tmp);
}
if (t->parts)
encode_descriptions (t->parts);
snprintf (tmp, sizeof (tmp), "%s: ", h->data);
len = mutt_strlen (tmp);
rfc2047_encode_string (tmp + len, sizeof (tmp) - len, (unsigned char *) p);
- safe_free ((void **) &h->data);
- h->data = safe_strdup (tmp);
+ mutt_str_replace (&h->data, tmp);
}
}
}
{
rfc2047_encode_string (buffer, sizeof (buffer) - 1,
(unsigned char *) env->subject);
- safe_free ((void **) &env->subject);
- env->subject = safe_strdup (buffer);
+ mutt_str_replace (&env->subject, buffer);
}
encode_headers (env->userhdrs);