From 566c484db7a60a0bdbfc84e9b53651b42a3e3552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 13 Jan 2004 16:50:40 +0000 Subject: Add a 'postconnect' keyword to execute a command after closing a SMTP connection. --- smtp.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'smtp.c') diff --git a/smtp.c b/smtp.c index 9fe8aa1..2ca96bb 100644 --- a/smtp.c +++ b/smtp.c @@ -62,6 +62,12 @@ void identity_free(identity_t *identity) if(identity->certificate_passphrase) free(identity->certificate_passphrase); + if(identity->preconnect) + free(identity->preconnect); + + if(identity->postconnect) + free(identity->postconnect); + free(identity); } @@ -563,6 +569,43 @@ void smtp_send(message_t *msg) auth_destroy_context (authctx); auth_client_exit (); + /* Execute post-connect command if one was specified. */ + if (identity->postconnect) + { + int ret, exit_status; + + if (verbose) + fprintf (stdout, "Executing post-connect command: %s\n", identity->postconnect); + + ret = system (identity->postconnect); + exit_status = WEXITSTATUS(ret); + + /* Check whether the child process caught a signal meant for us */ + if (WIFSIGNALED(ret)) + { + int sig = WTERMSIG(ret); + + if (sig == SIGINT || sig == SIGQUIT) + { + fprintf (stderr, "Post-connect command received signal %d\n", sig); + exit (EX_SOFTWARE); + } + } + + if (ret == -1) + { + fputs ("Error executing post-connect command\n", stderr); + exit (EX_OSERR); + } + + if (exit_status != 0) + { + fprintf (stderr, "Post-connect command \"%s\" exited with non-zero status %d\n", + identity->postconnect, exit_status); + exit (EX_SOFTWARE); + } + } + return; failure: -- cgit v1.2.3-2-g168b