summary refs log tree commit diff
path: root/imbox.c
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-12-21 07:16:29 -0500
committerJune McEnroe <june@causal.agency>2019-12-21 07:16:29 -0500
commit99d2563adb5dab48f48a737ada78aec097d7c0be (patch)
tree4ab7db7ed4fa7a652c5243fdd181272971ccc983 /imbox.c
parentRewrite aspirational manual (diff)
downloadimbox-99d2563adb5dab48f48a737ada78aec097d7c0be.tar.gz
imbox-99d2563adb5dab48f48a737ada78aec097d7c0be.zip
Implement -CFST
Diffstat (limited to 'imbox.c')
-rw-r--r--imbox.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/imbox.c b/imbox.c
index 1712615..788f032 100644
--- a/imbox.c
+++ b/imbox.c
@@ -171,18 +171,24 @@ static char *readLiteral(FILE *imap, const char *line) {
 
 int main(int argc, char *argv[]) {
 	const char *host = "imap.fastmail.com";
-	const char *port = "993";
+	const char *port = "imaps";
 	const char *mailbox = "INBOX";
-	const char *search = "SUBJECT \"[PATCH\"";
+	const char *subject = "[PATCH";
+	const char *from = NULL;
+	const char *to = NULL;
+	const char *cc = NULL;
 	int rppFlags = 0;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "h:m:p:s:vw"))) {
+	while (0 < (opt = getopt(argc, argv, "C:F:S:T:h:m:p:vw"))) {
 		switch (opt) {
+			break; case 'C': cc = optarg;
+			break; case 'F': from = optarg;
+			break; case 'S': subject = optarg;
+			break; case 'T': to = optarg;
 			break; case 'h': host = optarg;
 			break; case 'm': mailbox = optarg;
 			break; case 'p': port = optarg;
-			break; case 's': search = optarg;
 			break; case 'v': verbose = true;
 			break; case 'w': rppFlags |= RPP_STDIN;
 			break; default:  return EX_USAGE;
@@ -214,6 +220,7 @@ int main(int argc, char *argv[]) {
 
 	FILE *imap = funopen(client, tlsRead, tlsWrite, NULL, tlsClose);
 	if (!imap) err(EX_SOFTWARE, "funopen");
+	setlinebuf(imap);
 
 	bool login = false;
 	char *uids = NULL;
@@ -247,10 +254,12 @@ int main(int argc, char *argv[]) {
 				fprintf(imap, "%s SELECT %s\r\n", Atoms[Select], mailbox);
 			}
 			break; case Select: {
-				fprintf(
-					imap, "%s UID SEARCH CHARSET UTF-8 %s\r\n",
-					Atoms[Search], search
-				);
+				fprintf(imap, "%s UID SEARCH CHARSET UTF-8", Atoms[Search]);
+				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");
 			}
 			break; case Search: {
 				if (!uids) errx(EX_PROTOCOL, "no search response");