Prepare the email for sending. This function scans through the email for images & attachments. The resulting MimeMessage has all of the email contents.
| 136 | // the email for images & attachments. The resulting |
| 137 | // MimeMessage has all of the email contents. |
| 138 | void EmailNote::prepareEmailMessage(MimeMessage *message, QString note, QString body) { |
| 139 | MimeHtml *text = new MimeHtml(); |
| 140 | |
| 141 | // Prepare the massage the same as if we were printing it. |
| 142 | QString contents = this->stripContentsForPrint(body); |
| 143 | //QString textContents = editor->page()->currentFrame()->toPlainText(); |
| 144 | QStringList images; |
| 145 | QStringList attachments; |
| 146 | |
| 147 | // Now, go thgough & reformat all the img tags. |
| 148 | int cidCount=0; |
| 149 | QLOG_DEBUG() << contents; |
| 150 | int pos = contents.indexOf("src=\"/"); |
| 151 | while (pos>=0) { |
| 152 | QString localFile = contents.mid(pos+5); |
| 153 | int endPos = localFile.indexOf("\""); |
| 154 | localFile = localFile.mid(0,endPos); |
| 155 | images.append(localFile); |
| 156 | endPos = pos+endPos; |
| 157 | QString part1 = contents.mid(0,pos); |
| 158 | QString part2 = contents.mid(endPos+14); |
| 159 | cidCount++; |
| 160 | contents = part1 + "src='cid:file" +QString::number(cidCount) +"'" + part2; |
| 161 | |
| 162 | pos = contents.indexOf("src=\"/", pos+5); |
| 163 | } |
| 164 | |
| 165 | // next, look for all the attachments |
| 166 | pos = contents.indexOf("href=\"nnres:"); |
| 167 | while (pos >0 -1) { |
| 168 | QString localFile = contents.mid(pos+12); |
| 169 | int endPos = localFile.indexOf("\""); |
| 170 | localFile = localFile.mid(0,endPos); |
| 171 | attachments.append(localFile); |
| 172 | cidCount++; |
| 173 | pos = contents.indexOf("href=\"nnres:", pos+5); |
| 174 | } |
| 175 | |
| 176 | // If the user adds a note, then prepend it to the beginning. |
| 177 | if (note.trimmed() != "") { |
| 178 | int pos = contents.indexOf("<body"); |
| 179 | int endPos = contents.indexOf(">", pos); |
| 180 | contents.insert(endPos+1, Qt::escape(note)+"<p><p><hr><p>"); |
| 181 | } |
| 182 | text->setHtml(contents); |
| 183 | message->addPart(text); |
| 184 | |
| 185 | |
| 186 | // Add all the images |
| 187 | for (int i=0; i<images.size(); i++) { |
| 188 | MimeReference mimeRef; |
| 189 | QString localFile = images[i]; |
| 190 | QString mime = mimeRef.getMimeFromFileName(localFile); |
| 191 | MimeInlineFile *file = new MimeInlineFile(new QFile(localFile)); |
| 192 | QString lidFile = localFile.mid(localFile.lastIndexOf(QDir::separator())+1); |
| 193 | qint32 lid = lidFile.mid(0,lidFile.lastIndexOf(".")).toInt(); |
| 194 | ResourceTable rtable(global.db); |
| 195 | Resource r; |
nothing calls this directly
no test coverage detected