AC_DEFINE(HAVE_LANGINFO_YESEXPR,1,[ Define if you have <langinfo.h> and nl_langinfo(YESEXPR). ])
fi
+AC_CHECK_FUNCS(fmemopen open_memstream)
+
dnl Documentation tools
have_openjade="no"
AC_PATH_PROG([OSPCAT], [ospcat], [none])
int origType;
char *savePrefix = NULL;
FILE *fp = NULL;
+#ifndef HAVE_FMEMOPEN
char tempfile[_POSIX_PATH_MAX];
+#endif
size_t tmplength = 0;
LOFF_T tmpoffset = 0;
int decode = 0;
fseeko (s->fpin, b->offset, 0);
+#ifdef HAVE_FMEMOPEN
+ char *temp;
+ size_t tempsize;
+#endif
+
/* see if we need to decode this part before processing it */
if (b->encoding == ENCBASE64 || b->encoding == ENCQUOTEDPRINTABLE ||
b->encoding == ENCUUENCODED || plaintext ||
{
/* decode to a tempfile, saving the original destination */
fp = s->fpout;
+#ifdef HAVE_FMEMOPEN
+ if ((s->fpout = open_memstream(&temp, &tempsize)) == NULL)
+ {
+ mutt_error _("Unable to open memory stream!");
+ dprint (1, (debugfile, "Can't open memory stream.\n"));
+ return -1;
+ }
+#else
mutt_mktemp (tempfile, sizeof (tempfile));
if ((s->fpout = safe_fopen (tempfile, "w")) == NULL)
{
dprint (1, (debugfile, "Can't open %s.\n", tempfile));
return -1;
}
+#endif
/* decoding the attachment changes the size and offset, so save a copy
* of the "real" values now, and restore them after processing
*/
/* restore final destination and substitute the tempfile for input */
s->fpout = fp;
fp = s->fpin;
+#ifdef HAVE_FMEMOPEN
+ if(tempsize)
+ s->fpin = fmemopen(temp, tempsize, "r");
+ else /* fmemopen cannot handle zero-length buffers */
+ s->fpin = safe_fopen ("/dev/null", "r");
+ if(s->fpin == NULL) {
+ mutt_perror("failed to re-open memstream!");
+ return (-1);
+ }
+#else
s->fpin = fopen (tempfile, "r");
unlink (tempfile);
-
+#endif
/* restore the prefix */
s->prefix = savePrefix;
}
/* restore the original source stream */
safe_fclose (&s->fpin);
+#ifdef HAVE_FMEMOPEN
+ if(tempsize)
+ FREE(&temp);
+#endif
s->fpin = fp;
}
}
static int
msg_search (CONTEXT *ctx, pattern_t* pat, int msgno)
{
- char tempfile[_POSIX_PATH_MAX];
MESSAGE *msg = NULL;
STATE s;
- struct stat st;
FILE *fp = NULL;
long lng = 0;
int match = 0;
HEADER *h = ctx->hdrs[msgno];
char *buf;
size_t blen;
+#ifdef HAVE_FMEMOPEN
+ char *temp;
+ size_t tempsize;
+#else
+ char tempfile[_POSIX_PATH_MAX];
+ struct stat st;
+#endif
if ((msg = mx_open_message (ctx, msgno)) != NULL)
{
memset (&s, 0, sizeof (s));
s.fpin = msg->fp;
s.flags = M_CHARCONV;
+#ifdef HAVE_FMEMOPEN
+ if((s.fpout = open_memstream(&temp, &tempsize)) == NULL)
+ {
+ mutt_perror ("Error opening memstream");
+ return (0);
+ }
+#else
mutt_mktemp (tempfile, sizeof (tempfile));
if ((s.fpout = safe_fopen (tempfile, "w+")) == NULL)
{
mutt_perror (tempfile);
return (0);
}
+#endif
if (pat->op != M_BODY)
mutt_copy_header (msg->fp, h, s.fpout, CH_FROM | CH_DECODE, NULL);
if (s.fpout)
{
safe_fclose (&s.fpout);
+#ifdef HAVE_FMEMOPEN
+ FREE(&temp);
+#else
unlink (tempfile);
+#endif
}
return (0);
}
mutt_body_handler (h->content, &s);
}
+#ifdef HAVE_FMEMOPEN
+ fclose(s.fpout);
+ lng = tempsize;
+
+ if(tempsize) {
+ if ((fp = fmemopen(temp, tempsize, "r")) == NULL) {
+ mutt_perror ("Error re-opening memstream");
+ return (0);
+ }
+ } else { /* fmemopen cannot handle empty buffers */
+ if ((fp = safe_fopen ("/dev/null", "r")) == NULL) {
+ mutt_perror ("Error opening /dev/null");
+ return (0);
+ }
+ }
+#else
fp = s.fpout;
fflush (fp);
fseek (fp, 0, 0);
fstat (fileno (fp), &st);
lng = (long) st.st_size;
+#endif
}
else
{
if (option (OPTTHOROUGHSRC))
{
safe_fclose (&fp);
+#ifdef HAVE_FMEMOPEN
+ if(tempsize)
+ FREE (&temp);
+#else
unlink (tempfile);
+#endif
}
}