# include "config.h"
#endif
-#include "mutt.h"
-#include "rfc1524.h"
-
-#include "lib/mem.h"
-#include "lib/intl.h"
-#include "lib/str.h"
-#include "lib/debug.h"
-
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
+#include <lib-lib/mem.h>
+#include <lib-lib/str.h>
+#include <lib-lib/ascii.h>
+#include <lib-lib/macros.h>
+#include <lib-lib/file.h>
+
+#include <lib-sys/unix.h>
+
+#include "mutt.h"
+#include "rfc1524.h"
+#include "attach.h"
+
/* The command semantics include the following:
* %s is the filename that contains the mail body data
* %t is the content type, like text/plain
char buf[LONG_STRING];
char type[LONG_STRING];
- strfcpy (type, _type, sizeof (type));
+ m_strcpy(type, sizeof(type), _type);
if (option (OPTMAILCAPSANITIZE))
mutt_sanitize_filename (type, 0);
- while (command[x] && x < clen && y < sizeof (buf)) {
+ while (command[x] && x < clen && y < ssizeof (buf)) {
if (command[x] == '\\') {
x++;
buf[y++] = command[x++];
int z = 0;
x++;
- while (command[x] && command[x] != '}' && z < sizeof (param))
+ while (command[x] && command[x] != '}' && z < ssizeof (param))
param[z++] = command[x++];
param[z] = '\0';
_pvalue = mutt_get_parameter (param, a->parameter);
- strfcpy (pvalue, NONULL (_pvalue), sizeof (pvalue));
+ m_strcpy(pvalue, sizeof(pvalue), NONULL(_pvalue));
if (option (OPTMAILCAPSANITIZE))
mutt_sanitize_filename (pvalue, 0);
buf[y++] = command[x++];
}
buf[y] = '\0';
- strfcpy (command, buf, clen);
+ m_strcpy(command, clen, buf);
return needspipe;
}
s++;
}
else {
- *ch++ = 0;
- SKIPWS (ch);
+ *ch++ = '\0';
+ ch = vskipspaces(ch);
break;
}
}
- str_skip_trailws (s);
+ m_strrtrim(s);
return ch;
}
static int get_field_text (char *field, char **entry,
char *type, char *filename, int line)
{
- field = str_skip_initws (field);
+ field = vskipspaces(field);
if (*field == '=') {
if (entry) {
- field++;
- field = str_skip_initws (field);
- str_replace (entry, field);
+ field = vskipspaces(field + 1);
+ m_strreplace(entry, field);
}
return 1;
}
{
FILE *fp;
char *buf = NULL;
- size_t buflen;
+ ssize_t buflen;
char *ch;
char *field;
int found = FALSE;
btlen = ch - type;
if ((fp = fopen (filename, "r")) != NULL) {
- while (!found && (buf = mutt_read_line (buf, &buflen, fp, &line)) != NULL) {
+ while (!found && (buf = mutt_read_line(buf, &buflen, fp, &line)) != NULL) {
/* ignore comments */
if (*buf == '#')
continue;
- debug_print (2, ("mailcap entry: %s\n", buf));
/* check type */
ch = get_field (buf);
if (ascii_strcasecmp (buf, type) && (ascii_strncasecmp (buf, type, btlen) || (buf[btlen] != 0 && /* implicit wild */
- mutt_strcmp (buf + btlen, "/*")))) /* wildsubtype */
+ m_strcmp(buf + btlen, "/*")))) /* wildsubtype */
continue;
/* next field is the viewcommand */
field = ch;
ch = get_field (ch);
if (entry)
- entry->command = safe_strdup (field);
+ entry->command = m_strdup(field);
/* parse the optional fields */
found = TRUE;
while (ch) {
field = ch;
ch = get_field (ch);
- debug_print (2, ("field: %s\n", field));
if (!ascii_strcasecmp (field, "needsterminal")) {
if (entry)
* if this is the right entry.
*/
char *test_command = NULL;
- size_t len;
+ ssize_t len;
if (get_field_text (field + 4, &test_command, type, filename, line)
&& test_command) {
- len = mutt_strlen (test_command) + STRING;
- safe_realloc (&test_command, len);
+ len = m_strlen(test_command) + STRING;
+ p_realloc(&test_command, len);
rfc1524_expand_command (a, a->filename, type, test_command, len);
if (mutt_system (test_command)) {
/* a non-zero exit code means test failed */
found = FALSE;
}
- FREE (&test_command);
+ p_delete(&test_command);
}
}
} /* while (ch) */
if (!found) {
/* reset */
if (entry) {
- FREE (&entry->command);
- FREE (&entry->composecommand);
- FREE (&entry->composetypecommand);
- FREE (&entry->editcommand);
- FREE (&entry->printcommand);
- FREE (&entry->nametemplate);
- FREE (&entry->convert);
+ p_delete(&entry->command);
+ p_delete(&entry->composecommand);
+ p_delete(&entry->composetypecommand);
+ p_delete(&entry->editcommand);
+ p_delete(&entry->printcommand);
+ p_delete(&entry->nametemplate);
+ p_delete(&entry->convert);
entry->needsterminal = 0;
entry->copiousoutput = 0;
}
} /* while (!found && (buf = mutt_read_line ())) */
fclose (fp);
} /* if ((fp = fopen ())) */
- FREE (&buf);
+ p_delete(&buf);
return found;
}
rfc1524_entry *rfc1524_new_entry (void)
{
- return (rfc1524_entry *) safe_calloc (1, sizeof (rfc1524_entry));
+ return p_new(rfc1524_entry, 1);
}
void rfc1524_free_entry (rfc1524_entry ** entry)
{
rfc1524_entry *p = *entry;
- FREE (&p->command);
- FREE (&p->testcommand);
- FREE (&p->composecommand);
- FREE (&p->composetypecommand);
- FREE (&p->editcommand);
- FREE (&p->printcommand);
- FREE (&p->nametemplate);
- FREE (entry);
+ p_delete(&p->command);
+ p_delete(&p->testcommand);
+ p_delete(&p->composecommand);
+ p_delete(&p->composetypecommand);
+ p_delete(&p->editcommand);
+ p_delete(&p->printcommand);
+ p_delete(&p->nametemplate);
+ p_delete(entry);
}
/*
while (!found && *curr) {
x = 0;
- while (*curr && *curr != ':' && x < sizeof (path) - 1) {
+ while (*curr && *curr != ':' && x < ssizeof (path) - 1) {
path[x++] = *curr;
curr++;
}
path[x] = '\0';
mutt_expand_path (path, sizeof (path));
- debug_print (2, ("Checking mailcap file: %s\n", path));
found = rfc1524_mailcap_parse (a, path, type, entry, opt);
}
* Returns 1 if newfile specified
*/
-static void strnfcpy (char *d, char *s, size_t siz, size_t len)
-{
- if (len > siz)
- len = siz - 1;
- strfcpy (d, s, len);
-}
-
int rfc1524_expand_filename (char *nametemplate,
- char *oldfile, char *newfile, size_t nflen)
+ char *oldfile, char *newfile, ssize_t nflen)
{
int i, j, k, ps, r;
char *s;
if (!nametemplate) {
if (oldfile)
- strfcpy (newfile, oldfile, nflen);
+ m_strcpy(newfile, nflen, oldfile);
}
else if (!oldfile) {
mutt_expand_fmt (newfile, nflen, nametemplate, "mutt");
rmatch = 1;
- for (r = 0, j = mutt_strlen (oldfile) - 1, k =
- mutt_strlen (nametemplate) - 1;
+ for (r = 0, j = m_strlen(oldfile) - 1, k =
+ m_strlen(nametemplate) - 1;
j >= (lmatch ? i : 0) && k >= i + 2; j--, k--) {
if (nametemplate[k] != oldfile[j]) {
rmatch = 0;
if (lmatch)
*left = 0;
else
- strnfcpy (left, nametemplate, sizeof (left), i);
+ m_strncpy(left, sizeof(left), nametemplate, i);
if (rmatch)
*right = 0;
else
- strfcpy (right, nametemplate + i + 2, sizeof (right));
+ m_strcpy(right, sizeof(right), nametemplate + i + 2);
snprintf (newfile, nflen, "%s%s%s", left, oldfile, right);
}
else {
/* no "%s" in the name template. */
- strfcpy (newfile, nametemplate, nflen);
+ m_strcpy(newfile, nflen, nametemplate);
}
}
- mutt_adv_mktemp (newfile, nflen);
+ mutt_adv_mktemp (NULL, newfile, nflen);
if (rmatch && lmatch)
return 0;