diff options
Diffstat (limited to 'mailutils/mail.c')
-rw-r--r-- | mailutils/mail.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/mailutils/mail.c b/mailutils/mail.c index 2ad959f7d..6726654f7 100644 --- a/mailutils/mail.c +++ b/mailutils/mail.c | |||
@@ -107,18 +107,7 @@ static char* FAST_FUNC parse_url(char *url, char **user, char **pass) | |||
107 | } | 107 | } |
108 | */ | 108 | */ |
109 | 109 | ||
110 | void FAST_FUNC encode_base64(char *fname, const char *text, const char *eol) | 110 | static void encode_n_base64(const char *fname, const char *text, size_t len) |
111 | { | ||
112 | size_t len = len; | ||
113 | if (text) { | ||
114 | // though we do not call uuencode(NULL, NULL) explicitly | ||
115 | // still we do not want to break things suddenly | ||
116 | len = strlen(text); | ||
117 | } | ||
118 | encode_n_base64(fname, text, len, eol); | ||
119 | } | ||
120 | |||
121 | void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const char *eol) | ||
122 | { | 111 | { |
123 | enum { | 112 | enum { |
124 | SRC_BUF_SIZE = 57, /* This *MUST* be a multiple of 3 */ | 113 | SRC_BUF_SIZE = 57, /* This *MUST* be a multiple of 3 */ |
@@ -130,10 +119,9 @@ void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const | |||
130 | char dst_buf[DST_BUF_SIZE + 1]; | 119 | char dst_buf[DST_BUF_SIZE + 1]; |
131 | 120 | ||
132 | if (fname) { | 121 | if (fname) { |
133 | fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : (FILE *)text; | 122 | fp = (NOT_LONE_DASH(fname)) ? xfopen_for_read(fname) : stdin; |
134 | src_buf = src; | 123 | src_buf = src; |
135 | } else if (!text) | 124 | } |
136 | return; | ||
137 | 125 | ||
138 | while (1) { | 126 | while (1) { |
139 | size_t size; | 127 | size_t size; |
@@ -151,7 +139,7 @@ void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const | |||
151 | // encode the buffer we just read in | 139 | // encode the buffer we just read in |
152 | bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64); | 140 | bb_uuencode(dst_buf, src_buf, size, bb_uuenc_tbl_base64); |
153 | if (fname) { | 141 | if (fname) { |
154 | puts(eol); | 142 | puts(""); |
155 | } else { | 143 | } else { |
156 | src_buf += size; | 144 | src_buf += size; |
157 | len -= size; | 145 | len -= size; |
@@ -163,6 +151,21 @@ void FAST_FUNC encode_n_base64(char *fname, const char *text, size_t len, const | |||
163 | #undef src_buf | 151 | #undef src_buf |
164 | } | 152 | } |
165 | 153 | ||
154 | void FAST_FUNC printstr_base64(const char *text) | ||
155 | { | ||
156 | encode_n_base64(NULL, text, strlen(text)); | ||
157 | } | ||
158 | |||
159 | void FAST_FUNC printbuf_base64(const char *text, unsigned len) | ||
160 | { | ||
161 | encode_n_base64(NULL, text, len); | ||
162 | } | ||
163 | |||
164 | void FAST_FUNC printfile_base64(const char *fname) | ||
165 | { | ||
166 | encode_n_base64(fname, NULL, 0); | ||
167 | } | ||
168 | |||
166 | /* | 169 | /* |
167 | * get username and password from a file descriptor | 170 | * get username and password from a file descriptor |
168 | */ | 171 | */ |