rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

commit 3f256b7a41a5584e667a117803da56d6334b84e1
parent 8383f4962499c2d38c4094723e0a7c5b3821ed27
Author: parazyd <parazyd@dyne.org>
Date:   Thu,  1 Mar 2018 15:47:44 +0100

Add util.c for rputil.

Diffstat:
MMakefile | 2+-
Mbin/rpcomp | 4+++-
Mrohrpost.c | 2++
Autil.c | 42++++++++++++++++++++++++++++++++++++++++++
Autil.h | 12++++++++++++
5 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -5,7 +5,7 @@ include config.mk BIN = $(NAME) -OBJ = $(BIN:=.o) headers.o ind.o sieve.o net.o +OBJ = $(BIN:=.o) headers.o ind.o sieve.o net.o util.o all: $(BIN) cp -f $(NAME) bin diff --git a/bin/rpcomp b/bin/rpcomp @@ -9,12 +9,14 @@ Subject: Subject To: %s Cc: Bcc: +Message-ID: %s User-Agent: rp MIME-Version: 1.0 Content-Type: text/plain; charset=\"utf-8\"\n" \ "$(LANG=C date "+%a, %d %b %Y %T %Z")" \ "$(rpcfg -v defaultfrom)" \ - "$to" + "$to" \ + "$(rputil genmsgid)" printf "\n\nText\n\n" diff --git a/rohrpost.c b/rohrpost.c @@ -12,6 +12,7 @@ #include "ind.h" #include "net.h" #include "sieve.h" +#include "util.h" char *argv0; @@ -35,6 +36,7 @@ struct command cmds[] = { {"rpheaders", DOINSTALL, headersmain}, {"rpsieve", DONTINSTALL, sievemain}, {"rpnet", DOINSTALL, netmain}, + {"rputil", DOINSTALL, utilmain}, }; int main(int argc, char *argv[]) { diff --git a/util.c b/util.c @@ -0,0 +1,42 @@ +/* + * Copy me if you can + * by parazyd + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#include "arg.h" +#include "ind.h" +#include "util.h" + +void utilusage(void) { + die("usage: %s [cmd]\n" + " available commands:\n" + "\tgenmsgid: generates a Message-ID header\n", "rputil"); +} + +int genmsgid(void) { + int n; + char buf[15]; + time_t now = time(0); + strftime(buf, 15, "%Y%m%d%H%M%S", localtime(&now)); + srand(now); /* not secure ;) */ + n = rand() % 9999; + printf("<%s.GA%d@fq>\n", buf, n); + return 0; +} + +int utilmain(int argc, char *argv[]) { + + if (argc < 2) + utilusage(); + + if (!strncmp("genmsgid", argv[1], 8)) + return genmsgid(); + + utilusage(); + return 1; +} diff --git a/util.h b/util.h @@ -0,0 +1,12 @@ +/* + * Copy me if you can + * by parazyd + */ + +#ifndef __RPUTIL_H__ +#define __RPUTIL_H__ + +int utilmain(int argc, char *argv[]); +int genmsgid(void); + +#endif