diff options
Diffstat (limited to 'imbox.c')
-rw-r--r-- | imbox.c | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/imbox.c b/imbox.c index 08b7181..e58663e 100644 --- a/imbox.c +++ b/imbox.c @@ -185,11 +185,10 @@ int main(int argc, char *argv[]) { enum Atom login = 0; enum Atom examine = atom("examine"); - FILE *imapRead, *imap; - imapOpen(&imapRead, &imap, host, port); + struct IMAP imap = imapOpen(host, port); for ( struct Resp resp; - resp = imapResp(imapRead), resp.resp != AtomBye; + resp = imapResp(&imap), resp.resp != AtomBye; respFree(resp) ) { if (resp.resp == AtomNo || resp.resp == AtomBad) { @@ -199,33 +198,33 @@ int main(int argc, char *argv[]) { if (!login) { login = atom("login"); fprintf( - imap, "%s LOGIN \"%s\" \"%s\"\r\n", + imap.w, "%s LOGIN \"%s\" \"%s\"\r\n", Atoms[login], user, pass ); } if (resp.tag == login) { - fprintf(imap, "%s EXAMINE \"%s\"\r\n", Atoms[examine], mailbox); + fprintf(imap.w, "%s EXAMINE \"%s\"\r\n", Atoms[examine], mailbox); } if (resp.tag == examine) { - fprintf(imap, "%s SEARCH CHARSET UTF-8", Atoms[AtomSearch]); - if (subject) fprintf(imap, " SUBJECT \"%s\"", subject); - if (from) fprintf(imap, " FROM \"%s\"", from); - if (to) fprintf(imap, " TO \"%s\"", to); - if (cc) fprintf(imap, " CC \"%s\"", cc); - fprintf(imap, "\r\n"); + fprintf(imap.w, "%s SEARCH CHARSET UTF-8", Atoms[AtomSearch]); + if (subject) fprintf(imap.w, " SUBJECT \"%s\"", subject); + if (from) fprintf(imap.w, " FROM \"%s\"", from); + if (to) fprintf(imap.w, " TO \"%s\"", to); + if (cc) fprintf(imap.w, " CC \"%s\"", cc); + fprintf(imap.w, "\r\n"); } if (resp.resp == AtomSearch) { if (!resp.data.len) errx(EX_TEMPFAIL, "no matching messages"); - fprintf(imap, "%s FETCH ", Atoms[AtomFetch]); + fprintf(imap.w, "%s FETCH ", Atoms[AtomFetch]); for (size_t i = 0; i < resp.data.len; ++i) { uint32_t num = dataCheck(resp.data.ptr[i], Number).number; - fprintf(imap, "%s%" PRIu32, (i ? "," : ""), num); + fprintf(imap.w, "%s%" PRIu32, (i ? "," : ""), num); } fprintf( - imap, + imap.w, " (BODY[HEADER.FIELDS (" FETCH_HEADERS ")] BODY[TEXT])\r\n" ); } @@ -254,9 +253,9 @@ int main(int argc, char *argv[]) { } if (resp.tag == AtomFetch) { - fprintf(imap, "ayy LOGOUT\r\n"); + fprintf(imap.w, "ayy LOGOUT\r\n"); } } - fclose(imapRead); - fclose(imap); + fclose(imap.r); + fclose(imap.w); } |