(self, archive, append_msg)
| 272 | self._process_msg(new_msg, append_msg) |
| 273 | |
| 274 | def _explode_archive(self, archive, append_msg): |
| 275 | entries = util.load_yaml(archive, default=[], allowed=(list, set)) |
| 276 | for ent in entries: |
| 277 | # ent can be one of: |
| 278 | # dict { 'filename' : 'value', 'content' : |
| 279 | # 'value', 'type' : 'value' } |
| 280 | # filename and type not be present |
| 281 | # or |
| 282 | # scalar(payload) |
| 283 | if isinstance(ent, str): |
| 284 | ent = {"content": ent} |
| 285 | if not isinstance(ent, (dict)): |
| 286 | # TODO(harlowja) raise? |
| 287 | continue |
| 288 | |
| 289 | content = ent.get("content", "") |
| 290 | mtype = ent.get("type") |
| 291 | if not mtype: |
| 292 | default = ARCHIVE_UNDEF_TYPE |
| 293 | if isinstance(content, bytes): |
| 294 | default = ARCHIVE_UNDEF_BINARY_TYPE |
| 295 | mtype = handlers.type_from_starts_with(content, default) |
| 296 | |
| 297 | maintype, subtype = mtype.split("/", 1) |
| 298 | if maintype == "text": |
| 299 | if isinstance(content, bytes): |
| 300 | content = content.decode() |
| 301 | msg = MIMEText(content, _subtype=subtype) |
| 302 | else: |
| 303 | msg = MIMEBase(maintype, subtype) |
| 304 | msg.set_payload(content) |
| 305 | |
| 306 | if "filename" in ent: |
| 307 | _set_filename(msg, ent["filename"]) |
| 308 | if "launch-index" in ent: |
| 309 | msg.add_header("Launch-Index", str(ent["launch-index"])) |
| 310 | |
| 311 | for header in list(ent.keys()): |
| 312 | if header.lower() in ( |
| 313 | "content", |
| 314 | "filename", |
| 315 | "type", |
| 316 | "launch-index", |
| 317 | "content-disposition", |
| 318 | ATTACHMENT_FIELD.lower(), |
| 319 | CONTENT_TYPE.lower(), |
| 320 | ): |
| 321 | continue |
| 322 | msg.add_header(header, ent[header]) |
| 323 | |
| 324 | self._attach_part(append_msg, msg) |
| 325 | |
| 326 | def _multi_part_count(self, outer_msg, new_count=None): |
| 327 | """ |
no test coverage detected