Commit da9c204e da9c204ef4ff9b89863a15bd3346331acc7b5679 by Sergey Poznyakoff

comsat: minor changes

* libmailutils/mailbox/mailbox.c (mu_mailbox_open): Fix error
checking condition.
* comsat/action.c (act_getline): Remove.
(open_rc): Return mu_stream_t. Use linecon filter.
1 parent 0138b981
......@@ -17,6 +17,7 @@
#include "comsat.h"
#include <mailutils/io.h>
#include <mailutils/filter.h>
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
#include <obstack.h>
......@@ -39,52 +40,6 @@
number of characters and lines in the expansion.
When omitted, they default to 400, 5. */
static unsigned
act_getline (FILE *fp, char **sptr, size_t *size)
{
char buf[256];
int cont = 1;
size_t used = 0;
unsigned lines = 0;
if (feof (fp))
return 0;
while (cont && fgets (buf, sizeof buf, fp))
{
int len = strlen (buf);
if (buf[len-1] == '\n')
{
lines++;
buf[--len] = 0;
if (buf[len-1] == '\\')
{
buf[--len] = 0;
cont = 1;
}
else
cont = 0;
}
else
cont = 1;
if (len + used + 1 > *size)
{
*sptr = realloc (*sptr, len + used + 1);
if (!*sptr)
return 0;
*size = len + used + 1;
}
memcpy (*sptr + used, buf, len);
used += len;
}
if (*sptr)
(*sptr)[used] = 0;
return lines;
}
static int
expand_escape (char **pp, mu_message_t msg, struct obstack *stk)
{
......@@ -331,11 +286,13 @@ action_exec (FILE *tty, int argc, char **argv)
}
}
static FILE *
static mu_stream_t
open_rc (const char *filename, FILE *tty)
{
struct stat stb;
struct passwd *pw = getpwnam (username);
mu_stream_t stream, input;
int rc;
/* To be on the safe side, we do not allow root to have his .biffrc */
if (!allow_biffrc || pw->pw_uid == 0)
......@@ -357,21 +314,45 @@ open_rc (const char *filename, FILE *tty)
return NULL;
}
}
return fopen (filename, "r");
rc = mu_file_stream_create (&input, filename, MU_STREAM_READ);
if (rc)
{
if (rc != ENOENT)
{
fprintf (tty, _("Cannot open .biffrc file: %s\r\n"),
mu_strerror (rc));
mu_diag_output (MU_DIAG_NOTICE, _("cannot open %s for %s: %s"),
filename, username, mu_strerror (rc));
}
return NULL;
}
rc = mu_filter_create (&stream, input, "LINECON", MU_FILTER_DECODE,
MU_STREAM_READ);
mu_stream_unref (input);
if (rc)
{
fprintf (tty, _("Cannot create filter for your .biffrc file: %s\r\n"),
mu_strerror (rc));
mu_diag_output (MU_DIAG_NOTICE,
_("cannot create filter for file %s of %s: %s"),
filename, username, mu_strerror (rc));
return NULL;
}
return stream;
}
void
run_user_action (FILE *tty, const char *cr, mu_message_t msg)
{
FILE *fp;
mu_stream_t input;
int nact = 0;
char *stmt = NULL;
size_t size = 0;
fp = open_rc (BIFF_RC, tty);
if (fp)
input = open_rc (BIFF_RC, tty);
if (input)
{
unsigned n;
char *stmt = NULL;
size_t size = 0;
size_t n;
char *cwd = mu_getcwd ();
char *rcname;
struct mu_locus locus;
......@@ -381,19 +362,19 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
if (!rcname)
{
mu_diag_funcall (MU_DIAG_ERROR, "mu_make_file_name", NULL, ENOMEM);
fclose (fp);
return;
locus.mu_file = BIFF_RC;
}
else
locus.mu_file = rcname;
locus.mu_line = 1;
locus.mu_col = 0;
while ((n = act_getline (fp, &stmt, &size)))
while (mu_stream_getline (input, &stmt, &size, &n) == 0 && n > 0)
{
struct mu_wordsplit ws;
ws.ws_comment = "#";
if (mu_wordsplit (stmt, &ws, MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT)
if (mu_wordsplit (stmt, &ws,
MU_WRDSF_DEFFLAGS | MU_WRDSF_COMMENT) == 0
&& ws.ws_wordc)
{
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
......@@ -443,9 +424,9 @@ run_user_action (FILE *tty, const char *cr, mu_message_t msg)
}
}
mu_wordsplit_free (&ws);
locus.mu_line += n;
locus.mu_line++;
}
fclose (fp);
mu_stream_destroy (&input);
mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM,
MU_IOCTL_LOGSTREAM_SET_LOCUS, NULL);
free (rcname);
......
......@@ -278,7 +278,7 @@ mu_mailbox_open (mu_mailbox_t mbox, int flag)
if (flag & MU_STREAM_QACCESS)
{
/* Quick access mailboxes are read-only */
if (flag & (MU_STREAM_WRITE | MU_STREAM_RDWR
if (flag & (MU_STREAM_WRITE
| MU_STREAM_APPEND | MU_STREAM_CREAT))
return EINVAL; /* FIXME: Better error code, please? */
}
......