MCPcopy Create free account
hub / github.com/alibaba/async_simple / build_smtp_file

Method build_smtp_file

demo_example/smtp/smtp_client.cpp:275–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273 }
274
275 void build_smtp_file(std::ostream &out) {
276 if (data_.filepath.empty()) {
277 return;
278 }
279
280 std::string filename = data_.filepath.substr(
281 data_.filepath.find_last_of(get_separator()) + 1);
282 out << "--async_simple\r\nContent-Type: application/octet-stream; "
283 "name=\""
284 << filename << "\"\r\n";
285 out << "Content-Transfer-Encoding: base64\r\n";
286 out << "Content-Disposition: attachment; filename=\"" << filename
287 << "\"\r\n";
288 out << "\r\n";
289
290 std::string file_content = load_file_contents(data_.filepath);
291 size_t file_size = file_content.size();
292
293 std::string encoded = base64_encode(file_content);
294
295 int SEND_BUF_SIZE = 1024;
296
297 int no_of_rows = (int)file_size / SEND_BUF_SIZE + 1;
298
299 for (int i = 0; i != no_of_rows; ++i) {
300 std::string sub_buf =
301 encoded.substr(i * SEND_BUF_SIZE, SEND_BUF_SIZE);
302
303 out << sub_buf << "\r\n";
304 }
305 }
306
307 void build_request() {
308 std::ostream out(&request_);

Callers

nothing calls this directly

Calls 3

base64_encodeFunction · 0.85
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected