about summary refs log tree commit diff
path: root/imbox.c
diff options
context:
space:
mode:
Diffstat (limited to 'imbox.c')
-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]);