Changeset View
Standalone View
mimetreeparser/src/nodehelper.cpp
Show First 20 Lines • Show All 495 Lines • ▼ Show 20 Line(s) | 495 | { | |||
---|---|---|---|---|---|
496 | const QByteArray body = (aAutoDecode) ? node->decodedContent() : node->body(); | 496 | const QByteArray body = (aAutoDecode) ? node->decodedContent() : node->body(); | ||
497 | QMimeDatabase db; | 497 | QMimeDatabase db; | ||
498 | QMimeType mime = db.mimeTypeForData(body); | 498 | QMimeType mime = db.mimeTypeForData(body); | ||
499 | 499 | | |||
500 | QString mimetype = mime.name(); | 500 | QString mimetype = mime.name(); | ||
501 | node->contentType()->setMimeType(mimetype.toLatin1()); | 501 | node->contentType()->setMimeType(mimetype.toLatin1()); | ||
502 | } | 502 | } | ||
503 | 503 | | |||
504 | bool NodeHelper::hasMailHeader(const char *header, const KMime::Message *message) const | ||||
505 | { | ||||
506 | return message->hasHeader(header); | ||||
507 | } | ||||
508 | | ||||
509 | KMime::Headers::Base * NodeHelper::mailHeaderAsBase(const char *header, const KMime::Message *message) const | ||||
510 | { | ||||
511 | return message->headerByType(header); | ||||
512 | } | ||||
513 | | ||||
514 | KMime::Headers::Generics::AddressList * NodeHelper::mailHeaderAsAddressList(const char *header, KMime::Message *message) const | ||||
515 | { | ||||
516 | /* works without this is maybe faster ? | ||||
517 | if(strcmp(header, "to") == 0) { | ||||
518 | return message->to(); | ||||
519 | } else if(strcmp(header, "replyTo") == 0) { | ||||
520 | return message->replyTo(); | ||||
521 | } else if(strcmp(header, "bcc") == 0) { | ||||
522 | return message->bcc(); | ||||
523 | } else if(strcmp(header, "cc") == 0) { | ||||
524 | return message->cc(); | ||||
525 | } */ | ||||
526 | auto addressList = new KMime::Headers::Generics::AddressList(); | ||||
vkrause: where is this deleted again? | |||||
Good point ;D I haven't thought about it - but yes we have to pass QSharedPointer around. knauss: Good point ;D I haven't thought about it - but yes we have to pass QSharedPointer around. | |||||
527 | const auto hrd = message->headerByType(header); | ||||
528 | const QByteArray &data = hrd->as7BitString(false); | ||||
529 | addressList->from7BitString(data); | ||||
vkrause: This encodes and re-parses the header, is there no way to avoid that? | |||||
I don't understand the magic inside KMime not that deeply about all these headers and classes and subclasses. I just copied that part from messageviewer/src/header/headerstyle_util.cpp knauss: I don't understand the magic inside KMime not that deeply about all these headers and classes… | |||||
Well, first of all most of those headers are already of type AddressList, so those should be usable directly. For the one exception (From IIRC) the question is whether we need to convert that or if the consumer could handle that as well. Alternatively it might be worth looking if whatever the consumer expects can be added to From's type in KMime directly. The KMime header class hierarchy pretty much follows the MIME RFCs one to one and uses the same names as defined in the standard. vkrause: Well, first of all most of those headers are already of type AddressList, so those should be… | |||||
we we could enable the shortcuts, but we have more headers that are expected as AddressList: Form. Resent-To, Resent-To, List-Id knauss: we we could enable the shortcuts, but we have more headers that are expected as AddressList… | |||||
Well, do we need the full header object or is this ultimately only used for getting the list of addresses in that header? If so, how about we just get that and pass it along instead of the header object itself? If necessary by adding extra getters to KMime. vkrause: Well, do we need the full header object or is this ultimately only used for getting the list of… | |||||
Yes but it would make sense to have the name and email addresses already splitted... knauss: Yes but it would make sense to have the name and email addresses already splitted... | |||||
530 | return addressList; | ||||
531 | } | ||||
532 | | ||||
533 | QDateTime NodeHelper::dateHeader(KMime::Message *message) const | ||||
534 | { | ||||
535 | return message->date()->dateTime(); | ||||
536 | } | ||||
504 | 537 | | |||
505 | void NodeHelper::setOverrideCodec(KMime::Content *node, const QTextCodec *codec) | 538 | void NodeHelper::setOverrideCodec(KMime::Content *node, const QTextCodec *codec) | ||
506 | { | 539 | { | ||
507 | if (!node) { | 540 | if (!node) { | ||
508 | return; | 541 | return; | ||
509 | } | 542 | } | ||
510 | 543 | | |||
511 | mOverrideCodecs[node] = codec; | 544 | mOverrideCodecs[node] = codec; | ||
▲ Show 20 Lines • Show All 527 Lines • Show Last 20 Lines |
where is this deleted again?