From b80d8f4d9350ef1a04d4f5fb530a66dcd74821af Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 4 Dec 2020 18:18:00 -0500 Subject: Remove dependency on dig/drill --- imbox.c | 77 +++-------------------------------------------------------------- 1 file changed, 3 insertions(+), 74 deletions(-) (limited to 'imbox.c') diff --git a/imbox.c b/imbox.c index 99b4de8..8c4d351 100644 --- a/imbox.c +++ b/imbox.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include @@ -43,10 +42,6 @@ char * readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags); #include "imap.h" -#ifndef DIG_PATH -#define DIG_PATH "dig" -#endif - #define FETCH_HEADERS \ "Date Subject From Sender Reply-To To Cc Bcc " \ "Message-Id In-Reply-To References " \ @@ -71,72 +66,6 @@ static void mboxrd(char *header, char *body) { printf("\n"); } -static void lookup(const char **host, const char **port, const char *domain) { - static char buf[1024]; - snprintf(buf, sizeof(buf), "_imaps._tcp.%s", domain); - - int rw[2]; - int error = pipe(rw); - if (error) err(EX_OSERR, "pipe"); - - pid_t pid = fork(); - if (pid < 0) err(EX_OSERR, "fork"); - - if (!pid) { - close(rw[0]); - dup2(rw[1], STDOUT_FILENO); - dup2(rw[1], STDERR_FILENO); - close(rw[1]); -#ifdef DRILL_PATH - execlp(DRILL_PATH, "drill", buf, "SRV", NULL); - err(EX_CONFIG, "%s", DRILL_PATH); -#else - execlp(DIG_PATH, "dig", "-t", "SRV", "-q", buf, "+short", NULL); - err(EX_CONFIG, "%s", DIG_PATH); -#endif - } - - int status; - pid = wait(&status); - if (pid < 0) err(EX_OSERR, "wait"); - - close(rw[1]); - FILE *pipe = fdopen(rw[0], "r"); - if (!pipe) err(EX_IOERR, "fdopen"); - - fgets(buf, sizeof(buf), pipe); - if (ferror(pipe)) err(EX_IOERR, "fgets"); - - if (!WIFEXITED(status) || WEXITSTATUS(status)) { - fprintf(stderr, "%s", buf); - exit(WEXITSTATUS(status)); - } - - char *ptr = buf; -#ifdef DRILL_PATH - for (;;) { - char *line = fgets(buf, sizeof(buf), pipe); - if (!line || !strcmp(line, ";; ANSWER SECTION:\n")) break; - } - fgets(buf, sizeof(buf), pipe); - if (ferror(pipe)) err(EX_IOERR, "fgets"); - ptr = strrchr(buf, '\t'); - ptr = (ptr ? ptr + 1 : buf); -#endif - fclose(pipe); - - char *dot = strrchr(ptr, '.'); - if (dot) *dot = '\0'; - strsep(&ptr, " \n"); // priority - strsep(&ptr, " \n"); // weight - *port = strsep(&ptr, " \n"); - *host = strsep(&ptr, " \n"); - if (!*host) { - *host = domain; - *port = "imaps"; - } -} - int main(int argc, char *argv[]) { const char *host = NULL; const char *port = "imaps"; @@ -167,9 +96,9 @@ int main(int argc, char *argv[]) { if (!user) errx(EX_USAGE, "username required"); if (!host) { - const char *domain = strchr(user, '@'); - if (!domain) errx(EX_USAGE, "no domain in username"); - lookup(&host, &port, &domain[1]); + host = strchr(user, '@'); + if (!host) errx(EX_USAGE, "no domain in username"); + host++; } char buf[1024]; -- cgit 1.4.1