#include <lib-lib/str.h>
#include <lib-lib/macros.h>
#include <lib-lib/file.h>
-#include <lib-lib/debug.h>
#include <lib-sys/exit.h>
#include <lib-sys/mutt_signal.h>
static void transform_to_7bit (BODY * a, FILE * fpin);
-static void encode_quoted (FGETCONV * fc, FILE * fout, int istext)
+static void encode_quoted (fgetconv_t * fc, FILE * fout, int istext)
{
int c, linelen = 0;
char line[77], savechar;
}
-static void encode_base64 (FGETCONV * fc, FILE * fout, int istext)
+static void encode_base64 (fgetconv_t * fc, FILE * fout, int istext)
{
int ch, ch1 = EOF;
fputc ('\n', fout);
}
-static void encode_8bit (FGETCONV * fc, FILE * fout, int istext)
+static void encode_8bit (fgetconv_t * fc, FILE * fout, int istext)
{
int ch;
char send_charset[SHORT_STRING];
FILE *fpin;
BODY *t;
- FGETCONV *fc;
+ fgetconv_t *fc;
if (a->type == TYPEMULTIPART) {
/* First, find the boundary to use */
if (!(p = mutt_get_parameter ("boundary", a->parameter))) {
- debug_print (1, ("no boundary parameter found!\n"));
mutt_error _("No boundary parameter found! [report this error]");
return (-1);
}
if ((fpin = fopen (a->filename, "r")) == NULL) {
- debug_print (1, ("%s no longer exists!\n", a->filename));
mutt_error (_("%s no longer exists!"), a->filename);
return -1;
}
rs[BOUNDARYLEN] = 0;
for (i = 0; i < BOUNDARYLEN; i++)
- *p++ = __m_b64chars[LRAND() % sizeof(__m_b64chars)];
+ *p++ = __m_b64chars[lrand48() % sizeof(__m_b64chars)];
*p = 0;
mutt_set_parameter ("boundary", rs, parm);
static void update_content_info (CONTENT * info, CONTENT_STATE * s, char *d,
- size_t dlen)
+ ssize_t dlen)
{
int from = s->from;
int whitespace = s->whitespace;
* long as the input for any pair of charsets we might be interested
* in.
*/
-static size_t convert_file_to (FILE * file, const char *fromcode,
+static ssize_t convert_file_to (FILE * file, const char *fromcode,
int ncodes, const char **tocodes,
int *tocode, CONTENT * info)
{
char bufi[256], bufu[512], bufo[4 * sizeof (bufi)];
const char *ib, *ub;
char *ob;
- size_t ibl, obl, ubl, ubl1, n, ret;
+ ssize_t ibl, obl, ubl, ubl1, n, ret;
int i;
CONTENT *infos;
CONTENT_STATE *states;
- size_t *score;
+ ssize_t *score;
cd1 = mutt_iconv_open ("UTF-8", fromcode, 0);
- if (cd1 == (iconv_t) (-1))
+ if (cd1 == MUTT_ICONV_ERROR)
return -1;
cd = p_new(iconv_t, ncodes);
- score = p_new(size_t, ncodes);
+ score = p_new(ssize_t, ncodes);
states = p_new(CONTENT_STATE, ncodes);
infos = p_new(CONTENT, ncodes);
cd[i] = mutt_iconv_open (tocodes[i], "UTF-8", 0);
else
/* Special case for conversion to UTF-8 */
- cd[i] = (iconv_t) (-1), score[i] = (size_t) (-1);
+ cd[i] = MUTT_ICONV_ERROR, score[i] = -1;
rewind (file);
ibl = 0;
ib = bufi;
ob = bufu, obl = sizeof (bufu);
n = my_iconv(cd1, ibl ? &ib : 0, &ibl, &ob, &obl);
- assert (n == (size_t) (-1) || !n || ICONV_NONTRANS);
- if (n == (size_t) (-1) &&
+ assert (n == -1 || !n);
+ if (n == -1 &&
((errno != EINVAL && errno != E2BIG) || ib == bufi)) {
assert (errno == EILSEQ ||
- (errno == EINVAL && ib == bufi && ibl < sizeof (bufi)));
- ret = (size_t) (-1);
+ (errno == EINVAL && ib == bufi && ibl < ssizeof (bufi)));
+ ret = -1;
break;
}
ubl1 = ob - bufu;
/* Convert from UTF-8 */
for (i = 0; i < ncodes; i++)
- if (cd[i] != (iconv_t) (-1) && score[i] != (size_t) (-1)) {
+ if (cd[i] != MUTT_ICONV_ERROR && score[i] != -1) {
ub = bufu, ubl = ubl1;
ob = bufo, obl = sizeof (bufo);
n = my_iconv(cd[i], (ibl || ubl) ? &ub : 0, &ubl, &ob, &obl);
- if (n == (size_t) (-1)) {
+ if (n == -1) {
assert (errno == E2BIG ||
(BUGGY_ICONV && (errno == EILSEQ || errno == ENOENT)));
- score[i] = (size_t) (-1);
+ score[i] = -1;
}
else {
score[i] += n;
update_content_info (&infos[i], &states[i], bufo, ob - bufo);
}
}
- else if (cd[i] == (iconv_t) (-1) && score[i] == (size_t) (-1))
+ else if (cd[i] == MUTT_ICONV_ERROR && score[i] == -1)
/* Special case for conversion to UTF-8 */
update_content_info (&infos[i], &states[i], bufu, ubl1);
if (!ret) {
/* Find best score */
- ret = (size_t) (-1);
+ ret = -1;
for (i = 0; i < ncodes; i++) {
- if (cd[i] == (iconv_t) (-1) && score[i] == (size_t) (-1)) {
+ if (cd[i] == MUTT_ICONV_ERROR && score[i] == -1) {
/* Special case for conversion to UTF-8 */
*tocode = i;
ret = 0;
break;
}
- else if (cd[i] == (iconv_t) (-1) || score[i] == (size_t) (-1))
+ else if (cd[i] == MUTT_ICONV_ERROR || score[i] == -1)
continue;
- else if (ret == (size_t) (-1) || score[i] < ret) {
+ else if (ret == -1 || score[i] < ret) {
*tocode = i;
ret = score[i];
if (!ret)
break;
}
}
- if (ret != (size_t) (-1)) {
+ if (ret != -1) {
memcpy (info, &infos[*tocode], sizeof (CONTENT));
update_content_info (info, &states[*tocode], 0, 0); /* EOF */
}
}
for (i = 0; i < ncodes; i++)
- if (cd[i] != (iconv_t) (-1))
+ if (cd[i] != MUTT_ICONV_ERROR)
iconv_close (cd[i]);
iconv_close (cd1);
* However, if fromcode is zero then fromcodes is assumed to be the
* name of a single charset even if it contains a colon.
*/
-static size_t convert_file_from_to (FILE * file,
+static ssize_t convert_file_from_to (FILE * file,
const char *fromcodes,
const char *tocodes, char **fromcode,
char **tocode, CONTENT * info)
char *fcode;
char **tcode;
const char *c, *c1;
- size_t ret;
+ ssize_t ret;
int ncodes, i, cn;
/* Count the tocodes */
tcode[i] = m_substrdup(c, c1);
}
- ret = (size_t) (-1);
+ ret = -1;
if (fromcode) {
/* Try each fromcode in turn */
for (c = fromcodes; c; c = c1 ? c1 + 1 : 0) {
ret = convert_file_to (file, fcode, ncodes, (const char **) tcode,
&cn, info);
- if (ret != (size_t) (-1)) {
+ if (ret != -1) {
*fromcode = fcode;
*tocode = tcode[cn];
tcode[cn] = 0;
/* There is only one fromcode */
ret = convert_file_to (file, fromcodes, ncodes, (const char **) tcode,
&cn, info);
- if (ret != (size_t) (-1)) {
+ if (ret != -1) {
*tocode = tcode[cn];
tcode[cn] = 0;
}
char *tocode = NULL;
char buffer[100];
char chsbuf[STRING];
- size_t r;
+ ssize_t r;
struct stat sb;
}
if ((fp = fopen (fname, "r")) == NULL) {
- debug_print (1, ("%s: %s (errno %d).\n", fname, strerror (errno), errno));
return (NULL);
}
FileCharset : Charset) : Charset;
if (Charset && (chs || SendCharset) &&
convert_file_from_to (fp, fchs, chs ? chs : SendCharset,
- &fromcode, &tocode, info) != (size_t) (-1)) {
+ &fromcode, &tocode, info) != -1) {
if (!chs) {
- mutt_canonical_charset (chsbuf, sizeof (chsbuf), tocode);
+ charset_canonicalize (chsbuf, sizeof (chsbuf), tocode);
mutt_set_parameter ("charset", chsbuf, &b->parameter);
}
b->file_charset = fromcode;
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
mutt_set_parameter ("charset", (!info->hibin ? "us-ascii" :
Charset
- && !mutt_is_us_ascii (Charset) ? Charset :
+ && !charset_is_us_ascii (Charset) ? Charset :
"unknown-8bit"), &b->parameter);
return info;
m_strcpy(buf, sizeof(buf), SYSCONFDIR "/mime.types");
break;
default:
- debug_print (1, ("Internal error, count = %d.\n", count));
goto bye; /* shouldn't happen */
}
/* Get a body's character set */
-char *mutt_get_body_charset (char *d, size_t dlen, BODY * b)
+char *mutt_get_body_charset (char *d, ssize_t dlen, BODY * b)
{
char *p = NULL;
p = mutt_get_parameter ("charset", b->parameter);
if (p)
- mutt_canonical_charset (d, dlen, NONULL (p));
+ charset_canonicalize (d, dlen, NONULL (p));
else
m_strcpy(d, dlen, "us-ascii");
char chsbuff[STRING];
/* override noconv when it's us-ascii */
- if (mutt_is_us_ascii (mutt_get_body_charset (chsbuff, sizeof (chsbuff), a)))
+ if (charset_is_us_ascii (mutt_get_body_charset (chsbuff, sizeof (chsbuff), a)))
a->noconv = 0;
if (!a->force_charset && !a->noconv)
return b;
}
-char *mutt_make_date (char *s, size_t len)
+char *mutt_make_date (char *s, ssize_t len)
{
time_t t = time (NULL);
struct tm *l = localtime (&t);
}
static const char **
-add_args(const char **args, size_t *argslen, size_t *argsmax, address_t * addr)
+add_args(const char **args, ssize_t *argslen, ssize_t *argsmax, address_t * addr)
{
for (; addr; addr = addr->next) {
/* weed out group mailboxes, since those are for display only */
}
static const char **
-add_option(const char **args, size_t *argslen, size_t *argsmax, const char *s)
+add_option(const char **args, ssize_t *argslen, ssize_t *argsmax, const char *s)
{
if (*argslen == *argsmax) {
p_realloc(&args, *argsmax += 5);
{ /* message contains 8bit chars */
char *ps = NULL, *path = NULL, *s = NULL, *childout = NULL;
const char **args = NULL;
- size_t argslen = 0, argsmax = 0;
+ ssize_t argslen = 0, argsmax = 0;
int i;
#ifdef USE_NNTP
string. */
char *mutt_append_string (char *a, const char *b)
{
- size_t la = m_strlen(a);
+ ssize_t la = m_strlen(a);
p_realloc(&a, la + m_strlen(b) + 1);
strcpy (a + la, b); /* __STRCPY_CHECKED__ */
char *mutt_quote_string (const char *s)
{
char *r, *pr;
- size_t rlen;
+ ssize_t rlen;
rlen = m_strlen(s) + 3;
pr = r = p_new(char, rlen);
*pr++ = '"';
while (*s) {
if (INVALID_CHAR (*s)) {
- size_t o = pr - r;
+ ssize_t o = pr - r;
p_realloc(&r, ++rlen);
pr = r + o;
}
if (dup) {
- debug_print (2, ("Removing %s\n", addr->mailbox));
-
*last = addr->next;
addr->next = NULL;
set_noconv_flags (hdr->content, 1);
if (mx_open_mailbox (path, M_APPEND | M_QUIET, &f) == NULL) {
- debug_print (1, ("unable to open mailbox %s in append-mode, aborting.\n", path));
return (-1);
}
fflush (tempfp);
if (ferror (tempfp)) {
- debug_print (1, ("%s: write failed.\n", tempfile));
fclose (tempfp);
unlink (tempfile);
mx_commit_message (msg, &f); /* XXX - really? */