mail: commonalize send_r_n()

function                                             old     new   delta
send_mail_command                                     85      55     -30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2020-12-17 12:34:25 +01:00
parent 25b2680056
commit b6237c0657
4 changed files with 12 additions and 10 deletions

View File

@ -69,6 +69,13 @@ void FAST_FUNC launch_helper(const char **argv)
// parent goes on // parent goes on
} }
void FAST_FUNC send_r_n(const char *s)
{
if (G.verbose)
bb_error_msg("send:'%s'", s);
printf("%s\r\n", s);
}
char* FAST_FUNC send_mail_command(const char *fmt, const char *param) char* FAST_FUNC send_mail_command(const char *fmt, const char *param)
{ {
char *msg; char *msg;
@ -77,9 +84,7 @@ char* FAST_FUNC send_mail_command(const char *fmt, const char *param)
msg = (char*)fmt; msg = (char*)fmt;
if (fmt) { if (fmt) {
msg = xasprintf(fmt, param); msg = xasprintf(fmt, param);
if (G.verbose) send_r_n(msg);
bb_error_msg("send:'%s'", msg);
printf("%s\r\n", msg);
} }
fflush_all(); fflush_all();
return msg; return msg;

View File

@ -28,6 +28,7 @@ struct globals {
void launch_helper(const char **argv) FAST_FUNC; void launch_helper(const char **argv) FAST_FUNC;
void get_cred_or_die(int fd) FAST_FUNC; void get_cred_or_die(int fd) FAST_FUNC;
void send_r_n(const char *s) FAST_FUNC;
char *send_mail_command(const char *fmt, const char *param) FAST_FUNC; char *send_mail_command(const char *fmt, const char *param) FAST_FUNC;
void printbuf_base64(const char *buf, unsigned len) FAST_FUNC; void printbuf_base64(const char *buf, unsigned len) FAST_FUNC;

View File

@ -68,6 +68,7 @@
static void pop3_checkr(const char *fmt, const char *param, char **ret) static void pop3_checkr(const char *fmt, const char *param, char **ret)
{ {
char *msg = send_mail_command(fmt, param); char *msg = send_mail_command(fmt, param);
//FIXME: limit max len!!!
char *answer = xmalloc_fgetline(stdin); char *answer = xmalloc_fgetline(stdin);
if (answer && '+' == answer[0]) { if (answer && '+' == answer[0]) {
free(msg); free(msg);

View File

@ -102,13 +102,6 @@
// set to 0 to not limit // set to 0 to not limit
#define MAX_HEADERS 256 #define MAX_HEADERS 256
static void send_r_n(const char *s)
{
if (G.verbose)
bb_error_msg("send:'%s'", s);
printf("%s\r\n", s);
}
static int smtp_checkp(const char *fmt, const char *param, int code) static int smtp_checkp(const char *fmt, const char *param, int code)
{ {
char *answer; char *answer;
@ -119,6 +112,7 @@ static int smtp_checkp(const char *fmt, const char *param, int code)
// if code = -1 then just return this number // if code = -1 then just return this number
// if code != -1 then checks whether the number equals the code // if code != -1 then checks whether the number equals the code
// if not equal -> die saying msg // if not equal -> die saying msg
//FIXME: limit max len!!!
while ((answer = xmalloc_fgetline(stdin)) != NULL) { while ((answer = xmalloc_fgetline(stdin)) != NULL) {
if (G.verbose) if (G.verbose)
bb_error_msg("recv:'%.*s'", (int)(strchrnul(answer, '\r') - answer), answer); bb_error_msg("recv:'%.*s'", (int)(strchrnul(answer, '\r') - answer), answer);
@ -426,6 +420,7 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
// this means we scan stdin for To:, Cc:, Bcc: lines until an empty line // this means we scan stdin for To:, Cc:, Bcc: lines until an empty line
// and then use the rest of stdin as message body // and then use the rest of stdin as message body
code = 0; // set "analyze headers" mode code = 0; // set "analyze headers" mode
//FIXME: limit max len!!!
while ((s = xmalloc_fgetline(G.fp0)) != NULL) { while ((s = xmalloc_fgetline(G.fp0)) != NULL) {
dump: dump:
// put message lines doubling leading dots // put message lines doubling leading dots