diff options
Diffstat (limited to 'archive.c')
-rw-r--r-- | archive.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/archive.c b/archive.c index 376e2fc..469c24c 100644 --- a/archive.c +++ b/archive.c @@ -151,11 +151,10 @@ int main(int argc, char *argv[]) { struct List threads = {0}; struct Envelope *envelopes = NULL; - 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) { @@ -165,7 +164,7 @@ int main(int argc, char *argv[]) { switch (state) { break; case Ready: { fprintf( - imap, "%s LOGIN \"%s\" \"%s\"\r\n", + imap.w, "%s LOGIN \"%s\" \"%s\"\r\n", Atoms[login], user, pass ); state = Login; @@ -173,14 +172,14 @@ int main(int argc, char *argv[]) { break; case Login: { if (resp.tag != login) break; - fprintf(imap, "%s EXAMINE \"%s\"\r\n", Atoms[examine], mailbox); + fprintf(imap.w, "%s EXAMINE \"%s\"\r\n", Atoms[examine], mailbox); state = Examine; } break; case Examine: { if (resp.tag == examine) { fprintf( - imap, "%s UID THREAD %s UTF-8 %s\r\n", + imap.w, "%s UID THREAD %s UTF-8 %s\r\n", Atoms[thread], algo, search ); state = Thread; @@ -206,7 +205,7 @@ int main(int argc, char *argv[]) { uidNext = dataCheck(value, Number).number; uint32_t prev = uidRead("UIDNEXT"); if (uidNext == prev) { - fprintf(imap, "ayy LOGOUT\r\n"); + fprintf(imap.w, "ayy LOGOUT\r\n"); state = Logout; } else { exitStatus = EXIT_SUCCESS; @@ -226,11 +225,11 @@ int main(int argc, char *argv[]) { envelopes = calloc(threads.len, sizeof(*envelopes)); if (!envelopes) err(EX_OSERR, "calloc"); - if (exportFetch(imap, export, threads)) { + if (exportFetch(imap.w, export, threads)) { exportTags = 1; state = Export; } else { - concatFetch(imap, concat, threads); + concatFetch(imap.w, concat, threads); state = Concat; } } @@ -239,10 +238,10 @@ int main(int argc, char *argv[]) { if (resp.resp == AtomFetch) { if (!resp.data.len) errx(EX_PROTOCOL, "missing FETCH data"); struct List items = dataCheck(resp.data.ptr[0], List).list; - if (exportData(imap, export, items)) exportTags++; + if (exportData(imap.w, export, items)) exportTags++; } if (resp.tag != export || --exportTags) break; - concatFetch(imap, concat, threads); + concatFetch(imap.w, concat, threads); state = Concat; } @@ -257,15 +256,15 @@ int main(int argc, char *argv[]) { concatThreads(threads, envelopes); concatIndex(threads, envelopes); uidWrite("UIDNEXT", uidNext); - fprintf(imap, "ayy LOGOUT\r\n"); + fprintf(imap.w, "ayy LOGOUT\r\n"); state = Logout; } break; case Logout:; } } - fclose(imapRead); - fclose(imap); + fclose(imap.r); + fclose(imap.w); return exitStatus; } |