Commit 4781461c authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Add rfc1524 buffer function interfaces for attach.c conversion.

The rfc1524 functions call, and are called by, many functions that
need to be converted.  But to keep the conversion manageable, install
helper interface functions that pass the buffer->data and
buffer->dsize in and adjust the buffer->dptr afterwards.
parent b231f15a
......@@ -96,6 +96,18 @@ void mutt_buffer_increase_size (BUFFER *buf, size_t new_size)
}
}
/* Ensure buffer->dptr points to the end of the buffer. */
void mutt_buffer_fix_dptr (BUFFER *buf)
{
buf->dptr = buf->data;
if (buf->data)
{
buf->data[buf->dsize - 1] = '\0';
buf->dptr = strchr (buf->data, '\0');
}
}
static int _mutt_buffer_add_printf (BUFFER* buf, const char* fmt, va_list ap)
{
va_list ap_retry;
......
......@@ -39,6 +39,7 @@ BUFFER *mutt_buffer_from (char *);
void mutt_buffer_clear (BUFFER *);
void mutt_buffer_increase_size (BUFFER *, size_t);
void mutt_buffer_fix_dptr (BUFFER *);
/* These two replace the buffer contents. */
int mutt_buffer_printf (BUFFER*, const char*, ...);
......
......@@ -42,6 +42,18 @@
#include <errno.h>
#include <unistd.h>
int mutt_buffer_rfc1524_expand_command (BODY *a, const char *filename, const char *_type,
BUFFER *command)
{
int rc;
mutt_buffer_increase_size (command, LONG_STRING);
rc = rfc1524_expand_command (a, filename, _type, command->data, command->dsize);
mutt_buffer_fix_dptr (command);
return rc;
}
/* The command semantics include the following:
* %s is the filename that contains the mail body data
* %t is the content type, like text/plain
......@@ -55,7 +67,7 @@
* In addition, this function returns a 0 if the command works on a file,
* and 1 if the command works on a pipe.
*/
int rfc1524_expand_command (BODY *a, char *filename, char *_type,
int rfc1524_expand_command (BODY *a, const char *filename, const char *_type,
char *command, int clen)
{
int x=0,y=0;
......@@ -438,15 +450,28 @@ int rfc1524_mailcap_lookup (BODY *a, char *type, rfc1524_entry *entry, int opt)
* Returns 1 if newfile specified
*/
static void strnfcpy(char *d, char *s, size_t siz, size_t len)
static void strnfcpy(char *d, const 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,
int mutt_buffer_rfc1524_expand_filename (const char *nametemplate,
const char *oldfile,
BUFFER *newfile)
{
int rc;
mutt_buffer_increase_size (newfile, LONG_STRING);
rc = rfc1524_expand_filename (nametemplate, oldfile, newfile->data, newfile->dsize);
mutt_buffer_fix_dptr (newfile);
return rc;
}
int rfc1524_expand_filename (const char *nametemplate,
const char *oldfile,
char *newfile,
size_t nflen)
{
......
......@@ -36,9 +36,14 @@ typedef struct rfc1524_mailcap_entry {
rfc1524_entry *rfc1524_new_entry (void);
void rfc1524_free_entry (rfc1524_entry **);
int rfc1524_expand_command (BODY *, char *, char *, char *, int);
int rfc1524_expand_filename (char *, char *, char *, size_t);
int rfc1524_expand_command (BODY *, const char *, const char *, char *, int);
int rfc1524_expand_filename (const char *, const char *, char *, size_t);
int rfc1524_mailcap_lookup (BODY *, char *, rfc1524_entry *, int);
int mutt_rename_file (char *, char *);
/* Temporary BUFFER transition functions */
int mutt_buffer_rfc1524_expand_command (BODY *, const char *, const char *, BUFFER *);
int mutt_buffer_rfc1524_expand_filename (const char *, const char *, BUFFER *);
#endif /* _RFC1524_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment