#include "config.h"
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "gui/lib.h"
#include "lib.h"
#include "pager/lib.h"
#include "context.h"
#include "format_flags.h"
#include "mutt_globals.h"
#include "muttlib.h"
#include "options.h"
#include "nntp/lib.h"
Go to the source code of this file.
|
| ARRAY_HEAD (SendmailArgs, const char *) |
|
static void | alarm_handler (int sig) |
| Async notification of an alarm signal. More...
|
|
static int | send_msg (const char *path, struct SendmailArgs *args, const char *msg, char **tempfile, int wait_time) |
| invoke sendmail in a subshell More...
|
|
static void | add_args_one (struct SendmailArgs *args, const struct Address *addr) |
| Add an Address to a dynamic array. More...
|
|
static void | add_args (struct SendmailArgs *args, struct AddressList *al) |
| Add a list of Addresses to a dynamic array. More...
|
|
int | mutt_invoke_sendmail (struct Mailbox *m, struct AddressList *from, struct AddressList *to, struct AddressList *cc, struct AddressList *bcc, const char *msg, bool eightbit, struct ConfigSubset *sub) |
| Run sendmail. More...
|
|
Send email using sendmail
- Authors
-
- Copyright
- This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file sendmail.c.
◆ EX_OK
◆ ARRAY_HEAD()
ARRAY_HEAD |
( |
SendmailArgs |
, |
|
|
const char * |
|
|
) |
| |
◆ alarm_handler()
static void alarm_handler |
( |
int |
sig | ) |
|
|
static |
Async notification of an alarm signal.
- Parameters
-
Definition at line 67 of file sendmail.c.
◆ send_msg()
static int send_msg |
( |
const char * |
path, |
|
|
struct SendmailArgs * |
args, |
|
|
const char * |
msg, |
|
|
char ** |
tempfile, |
|
|
int |
wait_time |
|
) |
| |
|
static |
invoke sendmail in a subshell
- Parameters
-
[in] | path | Path to program to execute |
[in] | args | Arguments to pass to program |
[in] | msg | Temp file containing message to send |
[out] | tempfile | If sendmail is put in the background, this points to the temporary file containing the stdout of the child process. If it is NULL, stderr and stdout are not redirected. |
[in] | wait_time | How long to wait for sendmail, $sendmail_wait |
- Return values
-
0 | Success |
>0 | Failure, return code from sendmail |
Definition at line 85 of file sendmail.c.
95 sigaddset(&set, SIGTSTP);
96 sigprocmask(SIG_BLOCK, &set, NULL);
98 if ((wait_time >= 0) && tempfile)
109 struct sigaction act, oldalrm;
112 pid_t ppid = getppid();
121 for (
int fd = tempfile ? 1 : 3; fd < OPEN_MAX; fd++)
123 #elif defined(_POSIX_OPEN_MAX)
124 for (
int fd = tempfile ? 1 : 3; fd < _POSIX_OPEN_MAX; fd++)
139 if (open(msg, O_RDONLY, 0) < 0)
146 if ((wait_time >= 0) && tempfile && *tempfile)
149 if (open(*tempfile, O_WRONLY | O_APPEND | O_CREAT | O_EXCL, 0600) < 0)
157 if (open(
"/dev/null", O_WRONLY | O_APPEND) < 0)
159 if (open(
"/dev/null", O_RDWR | O_APPEND) < 0)
165 execvp(path, (
char **) args->entries);
184 act.sa_flags = SA_INTERRUPT;
188 sigemptyset(&act.sa_mask);
189 sigaction(SIGALRM, &act, &oldalrm);
192 else if (wait_time < 0)
195 if (waitpid(pid, &st, 0) > 0)
197 st = WIFEXITED(st) ? WEXITSTATUS(st) :
S_ERR;
198 if (wait_time && (st == (0xff &
EX_OK)) && tempfile && *tempfile)
207 if ((wait_time > 0) && tempfile && *tempfile)
218 sigaction(SIGALRM, &oldalrm, NULL);
221 if ((kill(ppid, 0) == -1) && (errno == ESRCH) && tempfile && *tempfile)
231 sigprocmask(SIG_UNBLOCK, &set, NULL);
233 if ((pid != -1) && (waitpid(pid, &st, 0) > 0))
234 st = WIFEXITED(st) ? WEXITSTATUS(st) :
S_ERR;
◆ add_args_one()
static void add_args_one |
( |
struct SendmailArgs * |
args, |
|
|
const struct Address * |
addr |
|
) |
| |
|
static |
Add an Address to a dynamic array.
- Parameters
-
[in,out] | args | Array to add to |
[in] | addr | Address to add |
Definition at line 248 of file sendmail.c.
◆ add_args()
static void add_args |
( |
struct SendmailArgs * |
args, |
|
|
struct AddressList * |
al |
|
) |
| |
|
static |
Add a list of Addresses to a dynamic array.
- Parameters
-
[in,out] | args | Array to add to |
[in] | al | Addresses to add |
Definition at line 262 of file sendmail.c.
◆ mutt_invoke_sendmail()
int mutt_invoke_sendmail |
( |
struct Mailbox * |
m, |
|
|
struct AddressList * |
from, |
|
|
struct AddressList * |
to, |
|
|
struct AddressList * |
cc, |
|
|
struct AddressList * |
bcc, |
|
|
const char * |
msg, |
|
|
bool |
eightbit, |
|
|
struct ConfigSubset * |
sub |
|
) |
| |
Run sendmail.
- Parameters
-
m | Mailbox |
from | The sender |
to | Recipients |
cc | Recipients |
bcc | Recipients |
msg | File containing message |
eightbit | Message contains 8bit chars |
sub | Config Subset |
- Return values
-
Definition at line 287 of file sendmail.c.
292 char *ps = NULL, *path = NULL, *s = NULL, *childout = NULL;
324 mutt_error(
_(
"$sendmail must be set in order to send mail"));
330 while ((ps = strtok(ps,
" ")))
341 ps = strrchr(ps,
'/');
361 while ((ps = strtok(ps,
" ")))
367 const bool c_use_8bit_mime =
cs_subset_bool(sub,
"use_8bit_mime");
368 if (eightbit && c_use_8bit_mime)
371 const bool c_use_envelope_from =
cs_subset_bool(sub,
"use_envelope_from");
372 if (c_use_envelope_from)
374 const struct Address *c_envelope_from_address =
376 if (c_envelope_from_address)
402 const char **e = NULL;
425 if (i != (
EX_OK & 0xff))
435 if ((stat(childout, &st) == 0) && (st.st_size > 0))
452 if (i == (
EX_OK & 0xff))
◆ SigAlrm
SIG_ATOMIC_VOLATILE_T SigAlrm |
true after SIGALRM is received
Definition at line 59 of file sendmail.c.
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
String manipulation buffer.
#define mutt_buffer_mktemp(buf)
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
#define TAILQ_EMPTY(head)
#define TAILQ_FOREACH(var, head, field)
char * mutt_str_dup(const char *str)
Copy a string, safely.
SIG_ATOMIC_VOLATILE_T SigAlrm
true after SIGALRM is received
static int send_msg(const char *path, struct SendmailArgs *args, const char *msg, char **tempfile, int wait_time)
invoke sendmail in a subshell
WHERE bool OptNoCurses
(pseudo) when sending in batch mode
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
void mutt_sig_unblock_system(bool restore)
Restore previously blocked signals.
#define TAILQ_FIRST(head)
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
void mutt_need_hard_redraw(void)
Force a hard refresh.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
int mutt_do_pager(const char *banner, const char *tempfile, PagerFlags do_color, struct Pager *info)
Display some page-able text to the user.
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
#define ARRAY_FREE(head)
Release all memory.
char * mailbox
Mailbox and host address.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
#define TAILQ_NEXT(elm, field)
void mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t callback, intptr_t data, MuttFormatFlags flags)
Expand expandos (x) in a string.
int nntp_post(struct Mailbox *m, const char *msg)
Post article.
static void add_args(struct SendmailArgs *args, struct AddressList *al)
Add a list of Addresses to a dynamic array.
const char * mutt_str_sysexit(int err_num)
Return a string matching an error code.
WHERE bool OptNewsSend
(pseudo) used to change behavior when posting
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
static void alarm_handler(int sig)
Async notification of an alarm signal.
const char * nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
Expand the newsrc filename - Implements format_t.
void mutt_sig_block_system(void)
Block signals before calling exec()
static void add_args_one(struct SendmailArgs *args, const struct Address *addr)
Add an Address to a dynamic array.