about summary refs log tree commit diff
path: root/imbox.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-02-24 14:42:17 -0500
committerJune McEnroe <june@causal.agency>2021-02-24 14:42:17 -0500
commit6a5616b3d4d543998037f7063bd49fa7d5d41433 (patch)
tree61a4d76ba50425112c398025270fa51c58354d60 /imbox.c
parentPipe move fetch after apply to /dev/null (diff)
downloadimbox-6a5616b3d4d543998037f7063bd49fa7d5d41433.tar.gz
imbox-6a5616b3d4d543998037f7063bd49fa7d5d41433.zip
Add -U and -s flags to match unseen and mark as seen
Diffstat (limited to '')
-rw-r--r--imbox.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/imbox.c b/imbox.c
index b385366..70b1270 100644
--- a/imbox.c
+++ b/imbox.c
@@ -68,29 +68,35 @@ static void mboxrd(char *header, char *body) {
 }
 
 int main(int argc, char *argv[]) {
+	int rppFlags = 0;
 	const char *host = NULL;
 	const char *port = "imaps";
 	const char *mailbox = "INBOX";
+
 	const char *subject = "[PATCH";
 	const char *from = NULL;
 	const char *to = NULL;
 	const char *cc = NULL;
-	const char *move = NULL;
+	bool unseen = false;
 	bool idle = false;
-	int rppFlags = 0;
+
+	const char *move = NULL;
+	bool seen = false;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "C:F:M:S:T:h:im:p:vw"))) {
+	while (0 < (opt = getopt(argc, argv, "C:F:M:S:T:Uh:im:p:svw"))) {
 		switch (opt) {
 			break; case 'C': cc = optarg;
 			break; case 'F': from = optarg;
 			break; case 'M': move = optarg;
 			break; case 'S': subject = optarg;
 			break; case 'T': to = optarg;
+			break; case 'U': unseen = true;
 			break; case 'h': host = optarg;
 			break; case 'i': idle = true;
 			break; case 'm': mailbox = optarg;
 			break; case 'p': port = optarg;
+			break; case 's': seen = true;
 			break; case 'v': imapVerbose = true;
 			break; case 'w': rppFlags |= RPP_STDIN;
 			break; default:  return EX_USAGE;
@@ -125,7 +131,7 @@ int main(int argc, char *argv[]) {
 	enum Atom examine = atom("examine");
 	fprintf(
 		imap.w, "%s %s \"%s\"\r\n",
-		Atoms[examine], (move ? "SELECT" : "EXAMINE"), mailbox
+		Atoms[examine], (move || seen ? "SELECT" : "EXAMINE"), mailbox
 	);
 	for (; resp = respOk(imapResp(&imap)), resp.tag != examine; respFree(resp));
 	respFree(resp);
@@ -138,6 +144,7 @@ search:;
 	if (from) fprintf(imap.w, " FROM \"%s\"", from);
 	if (to) fprintf(imap.w, " TO \"%s\"", to);
 	if (cc) fprintf(imap.w, " CC \"%s\"", cc);
+	if (unseen) fprintf(imap.w, " UNSEEN");
 	fprintf(imap.w, "\r\n");
 	for (; resp = respOk(imapResp(&imap)), resp.tag != search; respFree(resp)) {
 		if (resp.resp != AtomSearch) continue;
@@ -185,6 +192,18 @@ search:;
 	}
 	respFree(resp);
 
+	if (seen) {
+		enum Atom sto = atom("store");
+		fprintf(imap.w, "%s STORE ", Atoms[sto]);
+		for (size_t i = 0; i < nums.len; ++i) {
+			uint32_t num = dataCheck(nums.ptr[i], Number).number;
+			fprintf(imap.w, "%s%" PRIu32, (i ? "," : ""), num);
+		}
+		fprintf(imap.w, " +FLAGS.SILENT (\\Seen)\r\n");
+		for (; resp = respOk(imapResp(&imap)), resp.tag != sto; respFree(resp));
+		respFree(resp);
+	}
+
 	if (move) {
 		enum Atom mov = atom("move");
 		fprintf(imap.w, "%s MOVE ", Atoms[mov]);