list_add_last(h, &new->car);
}
+int gmc_pos;
+char gmc_buf[BUFSIZE];
+int gmc_init;
+int gmc_read;
+int gmc_unget;
+
+static int
+give_me_char(int fd)
+{
+ if (! gmc_init) {
+ gmc_pos = 0;
+ gmc_read = read(fd, gmc_buf, BUFSIZE);
+ gmc_init = 1;
+ gmc_unget = EOF;
+ }
+
+ if (gmc_unget != EOF) {
+ int a = gmc_unget;
+ gmc_unget = EOF;
+ return a;
+ }
+
+ if (! gmc_read) {
+ gmc_init = 0;
+ return EOF;
+ }
+
+ if (gmc_pos < gmc_read) {
+ return gmc_buf[gmc_pos++];
+ } else {
+ gmc_pos = 0;
+ gmc_read = read(fd, gmc_buf, BUFSIZE);
+ if (! gmc_read) {
+ gmc_init = 0;
+ return EOF;
+ }
+ else {
+ return gmc_buf[gmc_pos++];
+ }
+ }
+}
+
+static void
+unget_me(int c)
+{
+ gmc_unget = c;
+}
+
struct list*
-make_hlist(void)
+make_hlist(int fd)
{
struct list* l = xmalloc(sizeof(struct list));
char* buf;
buf = xmalloc(BUFSIZE);
curbufsize = BUFSIZE;
- while ((c = getchar()) != EOF){
+ while ((c = give_me_char(fd)) != EOF){
if (c == '\r')
continue;
if (c == '\n'){
if (last == '\n')
break;
- if ((c = getchar()) != ' ' && c != '\t'){
+ if ((c = give_me_char(fd)) != ' ' && c != '\t'){
if (c != EOF)
- ungetc(c, stdin);
+ unget_me(c);
buf[i] = 0;
new_header(buf, l);
i = 0;
}
struct email*
-get_body(void)
+get_body(int rfd)
{
char* buf;
struct email* b;
b->fd = -1;
/* read mail body, if it is too big, try to make tmp file */
- while ((c = getchar()) != EOF){
+ while ((c = give_me_char(rfd)) != EOF){
buf[i++] = c;
if (i >= curbufsize - 1) {
tmpfile = xstrdup("/tmp/umpf.XXXXXX");
/* save rest of the body to the tmpfile */
if (will_save) {
int j = 0;
- while ((c = getchar()) != EOF){
+ while ((c = give_me_char(rfd)) != EOF){
buf[j++] = c;
b->body_len++;
if (j >= MAIL_LEN) {
var_tab[i] = empty;
}
- current_headers = make_hlist();
+ current_headers = make_hlist(0);
// print_headers(current_headers);
- current_body = get_body();
+ current_body = get_body(0);
save_current_headers(var_hash);
interp(&input_code, var_hash);