MCPcopy Create free account
hub / github.com/baumgarr/nixnote2 / prepareEmailMessage

Method prepareEmailMessage

gui/nbrowserwindow.cpp:2624–2713  ·  view source on GitHub ↗

Prepare the email for sending. This function scans through the email for images & attachments. The resulting MimeMessage has all of the email contents.

Source from the content-addressed store, hash-verified

2622// the email for images & attachments. The resulting
2623// MimeMessage has all of the email contents.
2624void NBrowserWindow::prepareEmailMessage(MimeMessage *message, QString note) {
2625 MimeHtml *text = new MimeHtml();
2626
2627 // Prepare the massage the same as if we were printing it.
2628 QString contents = this->stripContentsForPrint();
2629 QString textContents = editor->page()->currentFrame()->toPlainText();
2630 QStringList images;
2631 QStringList attachments;
2632
2633 // Now, go thgough & reformat all the img tags.
2634 int cidCount=0;
2635 int pos = contents.indexOf("src=\"file:");
2636 while (pos>=0) {
2637 QString localFile = contents.mid(pos+13);
2638 int endPos = localFile.indexOf("\"");
2639 localFile = localFile.mid(0,endPos);
2640 images.append(localFile);
2641 endPos = pos+endPos;
2642 QString part1 = contents.mid(0,pos);
2643 QString part2 = contents.mid(endPos+14);
2644 cidCount++;
2645 contents = part1 + "src='cid:file" +QString::number(cidCount) +"'" + part2;
2646
2647 pos = contents.indexOf("src=\"file:", pos+5);
2648 }
2649
2650 // next, look for all the attachments
2651 pos = contents.indexOf("href=\"nnres:");
2652 while (pos != -1) {
2653 QString localFile = contents.mid(pos+12);
2654 int endPos = localFile.indexOf("\"");
2655 localFile = localFile.mid(0,endPos);
2656 attachments.append(localFile);
2657 cidCount++;
2658 pos = contents.indexOf("href=\"nnres:", pos+5);
2659 }
2660
2661 // If the user adds a note, then prepend it to the beginning.
2662 if (note.trimmed() != "") {
2663 int pos = contents.indexOf("<body");
2664 int endPos = contents.indexOf(">", pos);
2665 contents.insert(endPos+1, Qt::escape(note)+"<p><p><hr><p>");
2666 }
2667 text->setHtml(contents);
2668 message->addPart(text);
2669
2670
2671 // Add all the images
2672 for (int i=0; i<images.size(); i++) {
2673 MimeReference mimeRef;
2674 QString localFile = images[i];
2675 QString mime = mimeRef.getMimeFromFileName(localFile);
2676 MimeInlineFile *file = new MimeInlineFile(new QFile(localFile));
2677 QString lidFile = localFile.mid(localFile.lastIndexOf(QDir::separator())+1);
2678 qint32 lid = lidFile.mid(0,lidFile.lastIndexOf(".")).toInt();
2679 ResourceTable rtable(global.db);
2680 Resource r;
2681 ResourceAttributes ra;

Callers

nothing calls this directly

Calls 10

stripContentsForPrintMethod · 0.95
insertMethod · 0.80
getMimeFromFileNameMethod · 0.80
setContentNameMethod · 0.80
setContentIdMethod · 0.80
setContentTypeMethod · 0.80
setHtmlMethod · 0.45
addPartMethod · 0.45
getMethod · 0.45
isSetMethod · 0.45

Tested by

no test coverage detected