开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 1

cpp_workspace/poco

forked from sulayman_tien/poco
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (119)
标签 (59)
master
devel
poco-1.12.5
3990-reactor-performance
poll-closed-server-test
upgrade-ci-actions-to-v3
poco-1.9.5-not-released
3925-c-mysql-compile-fail
poco-1.11.6
poco-1.12.4
poco-1.11.5
poco-1.11.4
poco-1.12.3
feat/acceptor-service-handler-args
poco-1.12.2
fix/posix-sleep
poco-1.12.1
poco-1.12.0
issue-templates
revert-3646-avoid_clang_warning
poco-1.11.6-release
poco-1.12.4-release
poco-1.11.5-release
poco-1.11.4-release
poco-1.12.3-release
poco-1.12.2-release
poco-1.12.1-release
poco-1.12.0-release
poco-1.11.3-release
poco-1.11.2-release
poco-1.11.1-release
poco-1.11.1
poco-1.11.0-release
poco-1.10.1-release
poco-1.10.0-release
poco-1.9.4-release
poco-1.9.3-release
poco-1.9.2-release
poco-1.9.1-release
poco-1.9.0-release
master
分支 (119)
标签 (59)
master
devel
poco-1.12.5
3990-reactor-performance
poll-closed-server-test
upgrade-ci-actions-to-v3
poco-1.9.5-not-released
3925-c-mysql-compile-fail
poco-1.11.6
poco-1.12.4
poco-1.11.5
poco-1.11.4
poco-1.12.3
feat/acceptor-service-handler-args
poco-1.12.2
fix/posix-sleep
poco-1.12.1
poco-1.12.0
issue-templates
revert-3646-avoid_clang_warning
poco-1.11.6-release
poco-1.12.4-release
poco-1.11.5-release
poco-1.11.4-release
poco-1.12.3-release
poco-1.12.2-release
poco-1.12.1-release
poco-1.12.0-release
poco-1.11.3-release
poco-1.11.2-release
poco-1.11.1-release
poco-1.11.1
poco-1.11.0-release
poco-1.10.1-release
poco-1.10.0-release
poco-1.9.4-release
poco-1.9.3-release
poco-1.9.2-release
poco-1.9.1-release
poco-1.9.0-release
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (119)
标签 (59)
master
devel
poco-1.12.5
3990-reactor-performance
poll-closed-server-test
upgrade-ci-actions-to-v3
poco-1.9.5-not-released
3925-c-mysql-compile-fail
poco-1.11.6
poco-1.12.4
poco-1.11.5
poco-1.11.4
poco-1.12.3
feat/acceptor-service-handler-args
poco-1.12.2
fix/posix-sleep
poco-1.12.1
poco-1.12.0
issue-templates
revert-3646-avoid_clang_warning
poco-1.11.6-release
poco-1.12.4-release
poco-1.11.5-release
poco-1.11.4-release
poco-1.12.3-release
poco-1.12.2-release
poco-1.12.1-release
poco-1.12.0-release
poco-1.11.3-release
poco-1.11.2-release
poco-1.11.1-release
poco-1.11.1
poco-1.11.0-release
poco-1.10.1-release
poco-1.10.0-release
poco-1.9.4-release
poco-1.9.3-release
poco-1.9.2-release
poco-1.9.1-release
poco-1.9.0-release
poco
/
Net
/
src
/
MailMessage.cpp
poco
/
Net
/
src
/
MailMessage.cpp
MailMessage.cpp 17.37 KB
一键复制 编辑 原始数据 按行查看 历史
Aleksandar Fabijanic 提交于 2022年07月09日 00:28 +08:00 . Release 1.12.0 (#3674)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
//
// MailMessage.cpp
//
// Library: Net
// Package: Mail
// Module: MailMessage
//
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Net/MailMessage.h"
#include "Poco/Net/MediaType.h"
#include "Poco/Net/MultipartReader.h"
#include "Poco/Net/MultipartWriter.h"
#include "Poco/Net/PartSource.h"
#include "Poco/Net/PartHandler.h"
#include "Poco/Net/StringPartSource.h"
#include "Poco/Net/QuotedPrintableEncoder.h"
#include "Poco/Net/QuotedPrintableDecoder.h"
#include "Poco/Net/NameValueCollection.h"
#include "Poco/Base64Encoder.h"
#include "Poco/Base64Decoder.h"
#include "Poco/StreamCopier.h"
#include "Poco/DateTimeFormat.h"
#include "Poco/DateTimeFormatter.h"
#include "Poco/DateTimeParser.h"
#include "Poco/String.h"
#include "Poco/StringTokenizer.h"
#include "Poco/StreamCopier.h"
#include "Poco/NumberFormatter.h"
#include <sstream>
using Poco::Base64Encoder;
using Poco::Base64Decoder;
using Poco::StreamCopier;
using Poco::DateTimeFormat;
using Poco::DateTimeFormatter;
using Poco::DateTimeParser;
using Poco::StringTokenizer;
using Poco::icompare;
namespace Poco {
namespace Net {
namespace
{
class MultiPartHandler: public PartHandler
/// This is a default part handler for multipart messages, used when there
/// is no external handler provided to he MailMessage. This handler
/// will handle all types of message parts, including attachments.
{
public:
MultiPartHandler(MailMessage* pMsg): _pMsg(pMsg)
/// Creates multi part handler.
/// The pMsg pointer points to the calling MailMessage
/// and will be used to properly populate it, so the
/// message content could be written out unmodified
/// in its entirety, including attachments.
{
}
~MultiPartHandler()
/// Destroys string part handler.
{
}
void handlePart(const MessageHeader& header, std::istream& stream)
/// Handles a part. If message pointer was provided at construction time,
/// the message pointed to will be properly populated so it could be written
/// back out at a later point in time.
{
std::string tmp;
Poco::StreamCopier::copyToString(stream, tmp);
if (_pMsg)
{
MailMessage::ContentTransferEncoding cte = MailMessage::ENCODING_7BIT;
if (header.has(MailMessage::HEADER_CONTENT_TRANSFER_ENCODING))
{
std::string enc = header[MailMessage::HEADER_CONTENT_TRANSFER_ENCODING];
if (enc == MailMessage::CTE_8BIT)
cte = MailMessage::ENCODING_8BIT;
else if (enc == MailMessage::CTE_QUOTED_PRINTABLE)
cte = MailMessage::ENCODING_QUOTED_PRINTABLE;
else if (enc == MailMessage::CTE_BASE64)
cte = MailMessage::ENCODING_BASE64;
}
std::string contentType = header.get(MailMessage::HEADER_CONTENT_TYPE, "");
std::string contentDisp = header.get(MailMessage::HEADER_CONTENT_DISPOSITION, "");
std::string filename;
if (!contentDisp.empty())
filename = getParamFromHeader(contentDisp, "filename");
if (filename.empty())
filename = getParamFromHeader(contentType, "name");
PartSource* pPS = _pMsg->createPartStore(tmp, contentType, filename);
poco_check_ptr (pPS);
NameValueCollection::ConstIterator it = header.begin();
NameValueCollection::ConstIterator end = header.end();
bool added = false;
for (; it != end; ++it)
{
if (!added && MailMessage::HEADER_CONTENT_DISPOSITION == it->first)
{
if (it->second == "inline")
_pMsg->addContent(pPS, cte);
else
_pMsg->addAttachment("", pPS, cte);
added = true;
}
pPS->headers().set(it->first, it->second);
}
if (contentDisp.empty())
{
_pMsg->addContent(pPS, cte);
added = true;
}
if (!added) delete pPS;
}
}
private:
std::string getParamFromHeader(const std::string& header, const std::string& param)
{
StringTokenizer st(header, ";=", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
StringTokenizer::Iterator it = st.begin();
StringTokenizer::Iterator end = st.end();
for (; it != end; ++it) { if (*it == param) break; }
if (it != end)
{
++it;
if (it == end) return "";
return *it;
}
return "";
}
MailMessage* _pMsg;
};
class StringPartHandler: public PartHandler
/// This is a default part handler, used when there is no
/// external handler provided to the MailMessage. This handler
/// handles only single-part messages.
{
public:
StringPartHandler(std::string& content): _str(content)
/// Creates string part handler.
/// The content parameter represents the part content.
{
}
~StringPartHandler()
/// Destroys string part handler.
{
}
void handlePart(const MessageHeader& header, std::istream& stream)
/// Handles a part.
{
std::string tmp;
Poco::StreamCopier::copyToString(stream, tmp);
_str.append(tmp);
}
private:
std::string& _str;
};
}
const std::string MailMessage::HEADER_SUBJECT("Subject");
const std::string MailMessage::HEADER_FROM("From");
const std::string MailMessage::HEADER_TO("To");
const std::string MailMessage::HEADER_CC("CC");
const std::string MailMessage::HEADER_BCC("BCC");
const std::string MailMessage::HEADER_DATE("Date");
const std::string MailMessage::HEADER_CONTENT_TYPE("Content-Type");
const std::string MailMessage::HEADER_CONTENT_TRANSFER_ENCODING("Content-Transfer-Encoding");
const std::string MailMessage::HEADER_CONTENT_DISPOSITION("Content-Disposition");
const std::string MailMessage::HEADER_CONTENT_ID("Content-ID");
const std::string MailMessage::HEADER_MIME_VERSION("Mime-Version");
const std::string MailMessage::EMPTY_HEADER;
const std::string MailMessage::TEXT_PLAIN("text/plain");
const std::string MailMessage::CTE_7BIT("7bit");
const std::string MailMessage::CTE_8BIT("8bit");
const std::string MailMessage::CTE_QUOTED_PRINTABLE("quoted-printable");
const std::string MailMessage::CTE_BASE64("base64");
MailMessage::MailMessage(PartStoreFactory* pStoreFactory):
_encoding(),
_pStoreFactory(pStoreFactory)
{
Poco::Timestamp now;
setDate(now);
setContentType("text/plain");
}
MailMessage::~MailMessage()
{
for (auto& part: _parts)
{
delete part.pSource;
}
}
void MailMessage::addRecipient(const MailRecipient& recipient)
{
_recipients.push_back(recipient);
}
void MailMessage::setRecipients(const Recipients& recipients)
{
_recipients.assign(recipients.begin(), recipients.end());
}
void MailMessage::setSender(const std::string& sender)
{
set(HEADER_FROM, sender);
}
const std::string& MailMessage::getSender() const
{
if (has(HEADER_FROM))
return get(HEADER_FROM);
else
return EMPTY_HEADER;
}
void MailMessage::setSubject(const std::string& subject)
{
set(HEADER_SUBJECT, subject);
}
const std::string& MailMessage::getSubject() const
{
if (has(HEADER_SUBJECT))
return get(HEADER_SUBJECT);
else
return EMPTY_HEADER;
}
void MailMessage::setContent(const std::string& content, ContentTransferEncoding encoding)
{
_content = content;
_encoding = encoding;
set(HEADER_CONTENT_TRANSFER_ENCODING, contentTransferEncodingToString(encoding));
}
void MailMessage::setContentType(const std::string& mediaType)
{
set(HEADER_CONTENT_TYPE, mediaType);
}
void MailMessage::setContentType(const MediaType& mediaType)
{
setContentType(mediaType.toString());
}
const std::string& MailMessage::getContentType() const
{
if (has(HEADER_CONTENT_TYPE))
return get(HEADER_CONTENT_TYPE);
else
return TEXT_PLAIN;
}
void MailMessage::setDate(const Poco::Timestamp& dateTime)
{
set(HEADER_DATE, DateTimeFormatter::format(dateTime, DateTimeFormat::RFC1123_FORMAT));
}
Poco::Timestamp MailMessage::getDate() const
{
const std::string& dateTime = get(HEADER_DATE);
int tzd;
return DateTimeParser::parse(dateTime, tzd).timestamp();
}
bool MailMessage::isMultipart() const
{
MediaType mediaType = getContentType();
return mediaType.matches("multipart");
}
void MailMessage::addPart(const std::string& name, PartSource* pSource, ContentDisposition disposition, ContentTransferEncoding encoding)
{
poco_check_ptr (pSource);
makeMultipart();
Part part;
part.name = name;
part.pSource = pSource;
part.disposition = disposition;
part.encoding = encoding;
_parts.push_back(part);
}
void MailMessage::addContent(PartSource* pSource, ContentTransferEncoding encoding)
{
addPart("", pSource, CONTENT_INLINE, encoding);
}
void MailMessage::addAttachment(const std::string& name, PartSource* pSource, ContentTransferEncoding encoding)
{
addPart(name, pSource, CONTENT_ATTACHMENT, encoding);
}
void MailMessage::read(std::istream& istr, PartHandler& handler)
{
readHeader(istr);
if (isMultipart())
{
readMultipart(istr, handler);
}
else
{
StringPartHandler handler(_content);
readPart(istr, *this, handler);
}
}
void MailMessage::read(std::istream& istr)
{
readHeader(istr);
if (isMultipart())
{
MultiPartHandler handler(this);
readMultipart(istr, handler);
}
else
{
StringPartHandler handler(_content);
readPart(istr, *this, handler);
}
}
void MailMessage::write(std::ostream& ostr) const
{
MessageHeader header(*this);
setRecipientHeaders(header);
if (isMultipart())
{
writeMultipart(header, ostr);
}
else
{
writeHeader(header, ostr);
std::istringstream istr(_content);
writeEncoded(istr, ostr, _encoding);
}
}
void MailMessage::makeMultipart()
{
if (!isMultipart())
{
MediaType mediaType("multipart", "mixed");
setContentType(mediaType);
}
}
void MailMessage::writeHeader(const MessageHeader& header, std::ostream& ostr) const
{
header.write(ostr);
ostr << "\r\n";
}
void MailMessage::writeMultipart(MessageHeader& header, std::ostream& ostr) const
{
if (_boundary.empty()) _boundary = MultipartWriter::createBoundary();
MediaType mediaType(getContentType());
mediaType.setParameter("boundary", _boundary);
header.set(HEADER_CONTENT_TYPE, mediaType.toString());
header.set(HEADER_MIME_VERSION, "1.0");
writeHeader(header, ostr);
MultipartWriter writer(ostr, _boundary);
for (const auto& part: _parts)
{
writePart(writer, part);
}
writer.close();
}
void MailMessage::writePart(MultipartWriter& writer, const Part& part)
{
MessageHeader partHeader(part.pSource->headers());
MediaType mediaType(part.pSource->mediaType());
if (!part.name.empty())
mediaType.setParameter("name", part.name);
partHeader.set(HEADER_CONTENT_TYPE, mediaType.toString());
partHeader.set(HEADER_CONTENT_TRANSFER_ENCODING, contentTransferEncodingToString(part.encoding));
std::string disposition;
if (part.disposition == CONTENT_ATTACHMENT)
{
disposition = "attachment";
const std::string& filename = part.pSource->filename();
if (!filename.empty())
{
disposition.append("; filename=");
quote(filename, disposition);
}
}
else disposition = "inline";
partHeader.set(HEADER_CONTENT_DISPOSITION, disposition);
writer.nextPart(partHeader);
writeEncoded(part.pSource->stream(), writer.stream(), part.encoding);
}
void MailMessage::writeEncoded(std::istream& istr, std::ostream& ostr, ContentTransferEncoding encoding)
{
switch (encoding)
{
case ENCODING_7BIT:
case ENCODING_8BIT:
StreamCopier::copyStream(istr, ostr);
break;
case ENCODING_QUOTED_PRINTABLE:
{
QuotedPrintableEncoder encoder(ostr);
StreamCopier::copyStream(istr, encoder);
encoder.close();
}
break;
case ENCODING_BASE64:
{
Base64Encoder encoder(ostr);
StreamCopier::copyStream(istr, encoder);
encoder.close();
}
break;
}
}
void MailMessage::readHeader(std::istream& istr)
{
clear();
MessageHeader::read(istr);
istr.get(); // \r
if ('\n' == istr.peek()) istr.get(); // \n
}
void MailMessage::readMultipart(std::istream& istr, PartHandler& handler)
{
MediaType contentType(getContentType());
_boundary = contentType.getParameter("boundary");
MultipartReader reader(istr, _boundary);
while (reader.hasNextPart())
{
MessageHeader partHeader;
reader.nextPart(partHeader);
readPart(reader.stream(), partHeader, handler);
}
}
void MailMessage::readPart(std::istream& istr, const MessageHeader& header, PartHandler& handler)
{
std::string encoding;
if (header.has(HEADER_CONTENT_TRANSFER_ENCODING))
{
encoding = header.get(HEADER_CONTENT_TRANSFER_ENCODING);
// get rid of a parameter if one is set
std::string::size_type pos = encoding.find(';');
if (pos != std::string::npos)
encoding.resize(pos);
}
if (icompare(encoding, CTE_QUOTED_PRINTABLE) == 0)
{
QuotedPrintableDecoder decoder(istr);
handlePart(decoder, header, handler);
_encoding = ENCODING_QUOTED_PRINTABLE;
}
else if (icompare(encoding, CTE_BASE64) == 0)
{
Base64Decoder decoder(istr);
handlePart(decoder, header, handler);
_encoding = ENCODING_BASE64;
}
else
{
if (icompare(encoding, CTE_7BIT) == 0)
_encoding = ENCODING_7BIT;
else if (icompare(encoding, CTE_8BIT) == 0)
_encoding = ENCODING_8BIT;
handlePart(istr, header, handler);
}
}
void MailMessage::handlePart(std::istream& istr, const MessageHeader& header, PartHandler& handler)
{
handler.handlePart(header, istr);
// Read remaining characters from stream in case
// the handler failed to read the complete stream.
while (istr.good()) istr.get();
}
void MailMessage::setRecipientHeaders(MessageHeader& headers) const
{
std::string to;
std::string cc;
std::string bcc;
for (const auto& rec: _recipients)
{
switch (rec.getType())
{
case MailRecipient::PRIMARY_RECIPIENT:
appendRecipient(rec, to);
break;
case MailRecipient::CC_RECIPIENT:
appendRecipient(rec, cc);
break;
case MailRecipient::BCC_RECIPIENT:
break;
}
}
if (!to.empty()) headers.set(HEADER_TO, to);
if (!cc.empty()) headers.set(HEADER_CC, cc);
}
const std::string& MailMessage::contentTransferEncodingToString(ContentTransferEncoding encoding)
{
switch (encoding)
{
case ENCODING_7BIT:
return CTE_7BIT;
case ENCODING_8BIT:
return CTE_8BIT;
case ENCODING_QUOTED_PRINTABLE:
return CTE_QUOTED_PRINTABLE;
case ENCODING_BASE64:
return CTE_BASE64;
default:
poco_bugcheck();
}
return CTE_7BIT;
}
int MailMessage::lineLength(const std::string& str)
{
int n = 0;
std::string::const_reverse_iterator it = str.rbegin();
std::string::const_reverse_iterator end = str.rend();
while (it != end && *it != '\n') { ++n; ++it; }
return n;
}
void MailMessage::appendRecipient(const MailRecipient& recipient, std::string& str)
{
if (!str.empty()) str.append(", ");
const std::string& realName = recipient.getRealName();
const std::string& address = recipient.getAddress();
std::string rec;
if (!realName.empty())
{
quote(realName, rec, true);
rec.append(" ");
}
rec.append("<");
rec.append(address);
rec.append(">");
if (lineLength(str) + rec.length() > 70) str.append("\r\n\t");
str.append(rec);
}
std::string MailMessage::encodeWord(const std::string& text, const std::string& charset)
{
bool containsNonASCII = false;
for (auto ch: text)
{
if (static_cast<unsigned char>(ch) > 127)
{
containsNonASCII = true;
break;
}
}
if (!containsNonASCII) return text;
std::string encodedText;
std::string::size_type lineLength = 0;
for (auto ch: text)
{
if (lineLength == 0)
{
encodedText += "=?";
encodedText += charset;
encodedText += "?q?";
lineLength += charset.length() + 5;
}
switch (ch)
{
case ' ':
encodedText += '_';
lineLength++;
break;
case '=':
case '?':
case '_':
case '(':
case ')':
case '[':
case ']':
case '<':
case '>':
case ',':
case ';':
case ':':
case '.':
case '@':
encodedText += '=';
NumberFormatter::appendHex(encodedText, static_cast<unsigned>(static_cast<unsigned char>(ch)), 2);
lineLength += 3;
break;
default:
if (ch > 32 && ch < 127)
{
encodedText += ch;
lineLength++;
}
else
{
encodedText += '=';
NumberFormatter::appendHex(encodedText, static_cast<unsigned>(static_cast<unsigned char>(ch)), 2);
lineLength += 3;
}
}
if ((lineLength >= 64 && (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')) || lineLength >= 72)
{
encodedText += "?=\r\n ";
lineLength = 0;
}
}
if (lineLength > 0)
{
encodedText += "?=";
}
return encodedText;
}
PartSource* MailMessage::createPartStore(const std::string& content, const std::string& mediaType, const std::string& filename)
{
if (!_pStoreFactory) return new StringPartSource(content, mediaType, filename);
else return _pStoreFactory->createPartStore(content, mediaType, filename);
}
MultipartSource::MultipartSource(const std::string contentType):
PartSource(contentTypeWithBoundary(contentType))
{
}
MultipartSource::~MultipartSource()
{
for (auto& part: _parts)
{
delete part.pSource;
}
}
void MultipartSource::addPart(const std::string& name,
PartSource* pSource,
MailMessage::ContentDisposition disposition,
MailMessage::ContentTransferEncoding encoding)
{
MailMessage::Part part;
part.name = name;
part.pSource = pSource;
part.disposition = disposition;
part.encoding = encoding;
_parts.push_back(part);
}
std::istream& MultipartSource::stream()
{
MediaType mt(mediaType());
std::string boundary = mt.getParameter("boundary");
MultipartWriter writer(_content, boundary);
for (const auto& part: _parts)
{
MailMessage::writePart(writer, part);
}
writer.close();
return _content;
}
std::string MultipartSource::contentTypeWithBoundary(const std::string& contentType)
{
MediaType mediaType(contentType);
mediaType.setParameter("boundary", MultipartWriter::createBoundary());
return mediaType.toString();
}
} } // namespace Poco::Net
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

mirror of poco on github
暂无标签
BSL-1.0
使用 BSL-1.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/cpp_workspace/poco.git
git@gitee.com:cpp_workspace/poco.git
cpp_workspace
poco
poco
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /