static void
open_control(struct mlmmj_list *list)
{
- if (list->controlfd == -1)
- list->controlfd = openat(list->fd, "control", O_DIRECTORY|O_CLOEXEC);
+ if (list->controlfd != -1)
+ return;
+ list->controlfd = openat(list->fd, "control", O_DIRECTORY|O_CLOEXEC);
if (list->controlfd == -1) {
log_error(LOG_ARGS, "Unable to open %s/control", list->dir);
errx(EXIT_FAILURE, "Unable to open %s/control", list->dir);
}
}
+int
+open_control_file(struct mlmmj_list *list, const char *ctrlstr)
+{
+ open_control(list);
+ return (openat(list->controlfd, ctrlstr, O_RDONLY));
+}
+
static char *
readfile(int dirfd, const char *filename, bool oneline)
{
return new;
}
-
static bool
open_textdirs(struct mlmmj_list *list)
{
return (true);
}
+static int
+open_textfile(struct mlmmj_list *list, const char *filename)
+{
+ if (!open_textdirs(list))
+ return -1;
+ return (openat(list->textfd, filename, O_RDONLY|O_CLOEXEC));
+}
+
text *open_text_file(struct mlmmj_list *list, const char *filename)
{
text *txt;
static void begin_new_source_file(text *txt, char **line_p, char **pos_p,
- int *width_p, const char *filename, int transparent) {
+ int *width_p, int fd, int transparent) {
char *line = *line_p;
char *pos = *pos_p;
char *tmp, *esc;
source *src;
- int fd;
int i;
/* Save any later lines for use after finishing the source */
txt->src->processedwidth = 0;
}
- fd = open(filename, O_RDONLY);
if (fd < 0) {
/* Act as if the source were an empty line */
**pos_p = '\0';
char *pos = *pos_p;
char *token = pos + 1;
char *endpos;
- char *filename;
int limit;
formatted *fmt;
conditional *cond;
} else if(strncmp(token, "control ", 8) == 0) {
token = filename_token(token + 8);
if (token != NULL) {
- filename = concatstr(3, list, "/control/", token);
- begin_new_source_file(txt,
- line_p, pos_p, width_p, filename, 0);
- myfree(filename);
+ int fd = open_control_file(list, token);
+ begin_new_source_file(txt, line_p, pos_p, width_p, fd, 0);
return 0;
}
} else if(strncmp(token, "text ", 5) == 0) {
token = filename_token(token + 5);
if (token != NULL) {
- filename = concatstr(3, list, "/text/", token);
- begin_new_source_file(txt,
- line_p, pos_p, width_p, filename, 0);
- myfree(filename);
+ int fd = open_textfile(list, token);
+ begin_new_source_file(txt, line_p, pos_p, width_p, fd, 0);
return 0;
}
} else if(strncmp(token, "originalmail", 12) == 0 &&
if (token != NULL) limit = atol(token);
}
if (limit != 0) {
+ int fd = open(txt->mailname, O_RDONLY);
begin_new_source_file(txt, line_p, pos_p, width_p,
- txt->mailname, 1);
+ fd, 1);
if (limit == -1) txt->src->limit = -1;
else txt->src->limit = limit - 1;
return 0;