diff options
author | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
---|---|---|
committer | Jannis Hoffmann <jannis@fehcom.de> | 2024-07-03 15:52:39 +0200 |
commit | a6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch) | |
tree | b88cc7a8457658d67e0321718556ac807f6bccf3 /src/maildirwatch.c | |
parent | 00be7622c428f279872f84569f098ce16150f8a8 (diff) |
format files
Diffstat (limited to 'src/maildirwatch.c')
-rw-r--r-- | src/maildirwatch.c | 103 |
1 files changed, 54 insertions, 49 deletions
diff --git a/src/maildirwatch.c b/src/maildirwatch.c index aea5cbb..1496e20 100644 --- a/src/maildirwatch.c +++ b/src/maildirwatch.c @@ -1,19 +1,24 @@ #include <unistd.h> -#include "getln.h" + #include "buffer.h" -#include "prioq.h" -#include "stralloc.h" -#include "str.h" #include "exit.h" -#include "hfield.h" +#include "getln.h" #include "logmsg.h" #include "open.h" +#include "str.h" +#include "stralloc.h" + #include "headerbody.h" +#include "hfield.h" #include "maildir.h" +#include "prioq.h" #define WHO "maildirwatch" -void die_nomem() { logmsg(WHO,111,FATAL,"out of memory"); } +void die_nomem() +{ + logmsg(WHO, 111, FATAL, "out of memory"); +} stralloc recipient = {0}; stralloc sender = {0}; @@ -22,36 +27,42 @@ stralloc text = {0}; void addtext(char *s, int n) { - if (!stralloc_catb(&text,s,n)) die_nomem(); - if (text.len > 158) text.len = 158; + if (!stralloc_catb(&text, s, n)) die_nomem(); + if (text.len > 158) text.len = 158; } -void dobody(stralloc *h) { addtext(h->s,h->len); } +void dobody(stralloc *h) +{ + addtext(h->s, h->len); +} void doheader(stralloc *h) { int i; - switch (hfield_known(h->s,h->len)) { + switch (hfield_known(h->s, h->len)) { case H_SUBJECT: - i = hfield_skipname(h->s,h->len); - addtext(h->s + i,h->len - i); + i = hfield_skipname(h->s, h->len); + addtext(h->s + i, h->len - i); break; case H_DELIVEREDTO: - i = hfield_skipname(h->s,h->len); + i = hfield_skipname(h->s, h->len); if (i < h->len) - if (!stralloc_copyb(&recipient,h->s + i,h->len - i - 1)) die_nomem(); + if (!stralloc_copyb(&recipient, h->s + i, h->len - i - 1)) die_nomem(); break; case H_RETURNPATH: - i = hfield_skipname(h->s,h->len); + i = hfield_skipname(h->s, h->len); if (i < h->len) - if (!stralloc_copyb(&sender,h->s + i,h->len - i - 1)) die_nomem(); + if (!stralloc_copyb(&sender, h->s + i, h->len - i - 1)) die_nomem(); break; case H_FROM: - if (!stralloc_copyb(&fromline,h->s,h->len - 1)) die_nomem(); + if (!stralloc_copyb(&fromline, h->s, h->len - 1)) die_nomem(); break; } } -void finishheader() { ; } +void finishheader() +{ + ; +} stralloc filenames = {0}; prioq pq = {0}; @@ -65,54 +76,48 @@ int main() int fd; int i; - if (maildir_chdir() == -1) - logmsg(WHO,111,FATAL,"Can't change to maildir"); + if (maildir_chdir() == -1) logmsg(WHO, 111, FATAL, "Can't change to maildir"); for (;;) { maildir_clean(&filenames); - if (maildir_scan(&pq,&filenames,1,0) == -1) - logmsg(WHO,111,FATAL,"Can't read maildir"); + if (maildir_scan(&pq, &filenames, 1, 0) == -1) logmsg(WHO, 111, FATAL, "Can't read maildir"); - buffer_putsflush(buffer_1,"\033[;H\033[;J"); + buffer_putsflush(buffer_1, "\033[;H\033[;J"); - while (prioq_min(&pq,&pe)) { + while (prioq_min(&pq, &pe)) { prioq_delmin(&pq); fd = open_read(filenames.s + pe.id); if (fd == -1) continue; - buffer_init(&bi,read,fd,inbuf,sizeof(inbuf)); + buffer_init(&bi, read, fd, inbuf, sizeof(inbuf)); - if (!stralloc_copys(&sender,"?")) die_nomem(); - if (!stralloc_copys(&recipient,"?")) die_nomem(); - if (!stralloc_copys(&fromline,"")) die_nomem(); - if (!stralloc_copys(&text,"")) die_nomem(); - if (headerbody(&bi,doheader,finishheader,dobody) == -1) - logmsg(WHO,111,FATAL,"trouble reading new message"); + if (!stralloc_copys(&sender, "?")) die_nomem(); + if (!stralloc_copys(&recipient, "?")) die_nomem(); + if (!stralloc_copys(&fromline, "")) die_nomem(); + if (!stralloc_copys(&text, "")) die_nomem(); + if (headerbody(&bi, doheader, finishheader, dobody) == -1) + logmsg(WHO, 111, FATAL, "trouble reading new message"); for (i = 0; i < fromline.len; ++i) - if ((fromline.s[i] < 32) || (fromline.s[i] > 126)) - fromline.s[i] = '/'; + if ((fromline.s[i] < 32) || (fromline.s[i] > 126)) fromline.s[i] = '/'; for (i = 0; i < sender.len; ++i) - if ((sender.s[i] < 32) || (sender.s[i] > 126)) - sender.s[i] = '?'; + if ((sender.s[i] < 32) || (sender.s[i] > 126)) sender.s[i] = '?'; for (i = 0; i < recipient.len; ++i) - if ((recipient.s[i] < 32) || (recipient.s[i] > 126)) - recipient.s[i] = '?'; + if ((recipient.s[i] < 32) || (recipient.s[i] > 126)) recipient.s[i] = '?'; for (i = 0; i < text.len; ++i) - if ((text.s[i] < 32) || (text.s[i] > 126)) - text.s[i] = '/'; - buffer_puts(buffer_1,"FROM "); - buffer_put(buffer_1,sender.s,sender.len); - buffer_puts(buffer_1," TO <"); - buffer_put(buffer_1,recipient.s,recipient.len); - buffer_puts(buffer_1,">\n"); + if ((text.s[i] < 32) || (text.s[i] > 126)) text.s[i] = '/'; + buffer_puts(buffer_1, "FROM "); + buffer_put(buffer_1, sender.s, sender.len); + buffer_puts(buffer_1, " TO <"); + buffer_put(buffer_1, recipient.s, recipient.len); + buffer_puts(buffer_1, ">\n"); if (fromline.len) { - buffer_puts(buffer_1,"\033[1m"); - buffer_put(buffer_1,fromline.s,fromline.len); - buffer_puts(buffer_1,"\033[0m\n"); + buffer_puts(buffer_1, "\033[1m"); + buffer_put(buffer_1, fromline.s, fromline.len); + buffer_puts(buffer_1, "\033[0m\n"); } - buffer_put(buffer_1,text.s,text.len); - buffer_puts(buffer_1,"\n\n"); + buffer_put(buffer_1, text.s, text.len); + buffer_puts(buffer_1, "\n\n"); close(fd); } |