commit 8c96b677737e7ae1765122d88b0db536043478e8
parent f084c0cd6a224443bbbb160b5472d203e6f50186
Author: Christoph Lohmann <20h@r-36.net>
Date: Tue, 17 Jul 2012 08:10:09 +0200
Handling non-standard clients – again.
Diffstat:
scan.c | | | 66 | ++++++++++++++++++++++++++++++++++++++++++++++++++---------------- |
1 file changed, 50 insertions(+), 16 deletions(-)
diff --git a/scan.c b/scan.c
@@ -39,8 +39,8 @@ scanmain(int argc, char *argv[])
config_t *cfg;
imap_t *imap;
int filelen;
- char *user, *pass, *netspec, *selected, *date, *subject, *from, *id,
- *filec;
+ char *user, *pass, *netspec, *selected, *date, *subject, *from,
+ *id, *filec;
llist_t *ids, *msgs;
llistelem_t *elem, *msg, *datee, *subjecte, *frome, *ide;
mime_t *mime;
@@ -92,22 +92,39 @@ scanmain(int argc, char *argv[])
datee = llist_ciget(mime->hdrs, "date");
frome = llist_ciget(mime->hdrs, "from");
- if (subjecte != NULL && datee != NULL && frome != NULL) {
- subject = mime_decodeheader((char *)subjecte->data);
+ if (subjecte != NULL) {
+ subject = mime_decodeheader(
+ (char *)subjecte->data);
+ } else {
+ subject = "<empty>";
+ }
+
+ if (datee != NULL) {
tim = mime_parsedate((char *)datee->data);
if (tim != NULL)
date = smftime("%F/%H:%M", tim);
else
date = smprintf("invalid");
+ free(tim);
+ } else {
+ date = "<empty>";
+ }
+
+ if (frome != NULL) {
from = mime_decodeheader((char *)frome->data);
+ } else {
+ from = "<empty>";
+ }
- scan_print(NULL, date, from, subject);
+ scan_print("", date, from, subject);
+ if (subjecte != NULL)
free(subject);
- free(tim);
+ if (datee != NULL)
free(date);
+ if (frome != NULL)
free(from);
- }
+
mime_free(mime);
goto scancleanup;
@@ -131,6 +148,7 @@ scanmain(int argc, char *argv[])
if (msgs == NULL)
imap_die(imap, "imap_fetchheaders");
llist_free(ids);
+
scan_print("ID", "Date", "From", "Subject");
forllist(msgs, msg) {
elem = llist_get((llist_t *)msg->data, "literal");
@@ -145,25 +163,41 @@ scanmain(int argc, char *argv[])
datee = llist_ciget(mime->hdrs, "date");
frome = llist_ciget(mime->hdrs, "from");
- if (subjecte != NULL && datee != NULL && frome != NULL) {
- id = (char *)ide->data;
+ id = (char *)ide->data;
+
+ if (subjecte != NULL) {
subject = mime_decodeheader(
- (char *)subjecte->data);
+ (char *)subjecte->data);
+ } else {
+ subject = "<empty>";
+ }
+
+ if (datee != NULL) {
tim = mime_parsedate((char *)datee->data);
- if (tim != NULL) {
+ if (tim != NULL)
date = smftime("%F/%H:%M", tim);
- } else {
+ else
date = smprintf("invalid");
- }
+ free(tim);
+ } else {
+ date = "<empty>";
+ }
+
+ if (frome != NULL) {
from = mime_decodeheader((char *)frome->data);
+ } else {
+ from = "<empty>";
+ }
- scan_print(id, date, from, subject);
+ scan_print(id, date, from, subject);
+ if (subjecte != NULL)
free(subject);
- free(tim);
+ if (datee != NULL)
free(date);
+ if (frome != NULL)
free(from);
- }
+
mime_free(mime);
}
llist_efree(msgs);