aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--Makefile15
-rw-r--r--README.md10
-rw-r--r--env_tmp.h4
-rw-r--r--main.c72
5 files changed, 106 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3da82e6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.clang-format
+
+*.o
+mailvin
+env.h
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..e212d1f
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,15 @@
+CC = gcc
+COBJS = main.o
+CFLAGS = -Wall -Wextra -pedantic-errors -Wshadow -Wpointer-arith -Wwrite-strings -Wredundant-decls -Wnested-externs -Ofast -lcurl
+
+all: $(COBJS)
+ @$(CC) -o mailvin $< $(CFLAGS)
+
+run: all
+ @./mailvin
+
+%.o: %.c
+ @$(CC) -c -o $@ $< $(CFLAGS)
+
+clean:
+ @rm -f *.o
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3a628d6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+# Mailvin
+
+## Read your emails with style
+
+**WARNING: I created this project because I was bored. Don't use this. Seriously.**
+
+1. Rename `env_tmp.h` to `env.h` and edit it accordingly
+2. Run `make`
+3. Use `./mailvin | less`
+4. Enjoy?
diff --git a/env_tmp.h b/env_tmp.h
new file mode 100644
index 0000000..a337681
--- /dev/null
+++ b/env_tmp.h
@@ -0,0 +1,4 @@
+#define USERNAME "yourusername"
+#define PASSWORD "blablabla"
+#define URL "imaps://domain.tld:993"
+#define BOX "INBOX"
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..3fef37d
--- /dev/null
+++ b/main.c
@@ -0,0 +1,72 @@
+#include "env.h"
+
+#include <curl/curl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+struct string {
+ char *ptr;
+ size_t len;
+};
+
+void init_string(struct string *s)
+{
+ s->len = 0;
+ s->ptr = malloc(s->len + 1);
+ if (s->ptr == NULL) {
+ fprintf(stderr, "malloc() failed\n");
+ exit(EXIT_FAILURE);
+ }
+ s->ptr[0] = '\0';
+}
+
+size_t writefunc(void *ptr, size_t size, size_t nmemb, struct string *s)
+{
+ size_t new_len = s->len + size * nmemb;
+ s->ptr = realloc(s->ptr, new_len + 1);
+ if (s->ptr == NULL) {
+ fprintf(stderr, "realloc() failed\n");
+ exit(EXIT_FAILURE);
+ }
+ memcpy(s->ptr + s->len, ptr, size * nmemb);
+ s->ptr[new_len] = '\0';
+ s->len = new_len;
+
+ return size * nmemb;
+}
+
+int request(CURL *curl, const char *req, struct string *resp)
+{
+ init_string(resp);
+ curl_easy_setopt(curl, CURLOPT_USERNAME, USERNAME);
+ curl_easy_setopt(curl, CURLOPT_PASSWORD, PASSWORD);
+ curl_easy_setopt(curl, CURLOPT_URL, req);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, resp);
+ CURLcode res = curl_easy_perform(curl);
+
+ if (res != CURLE_OK) {
+ fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
+ return 1;
+ } else {
+ return 0;
+ }
+}
+
+int main()
+{
+ CURL *curl = curl_easy_init();
+ if (!curl) {
+ fprintf(stderr, "curl initialization failed\n");
+ exit(EXIT_FAILURE);
+ }
+
+ struct string s;
+ if (!request(curl, URL "/" BOX ";UID=*", &s))
+ printf("%s", s.ptr);
+ free(s.ptr);
+
+ curl_easy_cleanup(curl);
+ return 0;
+}