commit 2231d1aba5ec12aa7e68c8b0095131f1a57f6768
parent f790e6436c15df6e4352da38818f85fb68042e27
Author: Tomas Hlavaty <tom@logand.com>
Date: Thu, 18 Nov 2010 23:11:58 +0100
no argument option added
Diffstat:
M | README | | | 34 | +++++++++++++++++++++++++++++++--- |
M | w3mail.c | | | 25 | ++++++++++++++++++++----- |
2 files changed, 51 insertions(+), 8 deletions(-)
diff --git a/README b/README
@@ -50,7 +50,7 @@ Switch to the new directory and make the w3mail executable:
Configuration
=============
-The command-line arguments of w3mail are: [cmd from to host] url.
+The command-line arguments of w3mail are: [[cmd from to host] url].
In case all arguments are supplied, no configuration is necessary.
@@ -73,7 +73,8 @@ invoke sendmail there.
It is convenient to put the w3mail program somewhere reachable from
$PATH, e.g. create a symlink to the w3mail executable file in your
-~/bin directory or add the w3mail git directory into your $PATH.
+~/bin directory (if the ~/bin directory is in your $PATH) or add the
+w3mail git directory into your $PATH.
Invocation from shell
=====================
@@ -86,7 +87,29 @@ b) Send many web pages:
First save the URLs into a file, one URL per line. Then run:
- $ cat file | xargs -n1 w3mail
+ $ cat file | w3mail
+
+ Or much faster in parallel with maximum 20 processes:
+
+ $ cat file | xargs -n1 -P20 w3mail
+
+c) Run w3mail in background
+
+ First start the server:
+
+ $ echo >~/.w3mail.in; tail -f ~/.w3mail.in | xargs -n1 -P20 w3mail 2>>~/.w3mail.log &
+
+ Then request sending web pages by running:
+
+ $ echo 'url' >>~/.w3mail.in
+
+ or
+
+ $ cat file >>~/.w3mail.in
+
+ Watch the log for errors:
+
+ $ tail -f ~/.w3mail.log
Using w3mail with Emacs
=======================
@@ -123,6 +146,11 @@ Put the following emacs-lisp code into your ~/.emacs file:
Pressing f5 key will ask for the URL of the web page to be send.
+It is better to run the w3mail as a server as mentioned above and then
+it is possible to replace the "w3mail '%s' &" parameter in w3mail
+emacs-lisp function by "echo '%s' >>~/.w3mail.in". This won't block
+emacs at all.
+
Licence
=======
diff --git a/w3mail.c b/w3mail.c
@@ -165,19 +165,34 @@ static void cb_config(void *udata, FILE* in) {
rtrim(fgets(x->host, BLEN, in));
}
-int main(int argc, char *argv[]) {
+static void run(struct w3mail *x) {
char fname[BLEN];
snprintf(fname, BLEN, "/tmp/w3mail-XXXXXX");
- if(argc == 2) {
+ tmpf(x, cb_w3mail, fname);
+}
+
+int main(int argc, char *argv[]) {
+ if(argc == 1) {
+ char cmd[BLEN], from[BLEN], to[BLEN], host[BLEN], url[BLEN];
+ struct w3mail x = {cmd, from, to, host, url};
+ in(&x, cb_config, "cat ~/.w3mail");
+ while(!feof(stdin)) {
+ char *line = fgets(url, BLEN, stdin);
+ if(!line) break;
+ rtrim(line);
+ run(&x);
+ }
+ }
+ else if(argc == 2) {
char cmd[BLEN], from[BLEN], to[BLEN], host[BLEN];
struct w3mail x = {cmd, from, to, host, argv[1]};
in(&x, cb_config, "cat ~/.w3mail");
- tmpf(&x, cb_w3mail, fname);
+ run(&x);
}
else if(argc == 6) {
struct w3mail x = {argv[1], argv[2], argv[3], argv[4], argv[5]};
- tmpf(&x, cb_w3mail, fname);
+ run(&x);
}
- else quit(1, "usage: %s [cmd from to host] url\n", argv[0]);
+ else quit(1, "usage: %s [[cmd from to host] url]\n", argv[0]);
return 0;
}