Extended header setting. name is the header field to add. keyword arguments can be used to set additional parameters for the header field, with underscores converted to dashes. Normally the parameter will be added as key="value" unless value is None, in which case
(self, _name, _value, **_params)
| 557 | return values |
| 558 | |
| 559 | def add_header(self, _name, _value, **_params): |
| 560 | """Extended header setting. |
| 561 | |
| 562 | name is the header field to add. keyword arguments can be used to set |
| 563 | additional parameters for the header field, with underscores converted |
| 564 | to dashes. Normally the parameter will be added as key="value" unless |
| 565 | value is None, in which case only the key will be added. If a |
| 566 | parameter value contains non-ASCII characters it can be specified as a |
| 567 | three-tuple of (charset, language, value), in which case it will be |
| 568 | encoded according to RFC2231 rules. Otherwise it will be encoded using |
| 569 | the utf-8 charset and a language of ''. |
| 570 | |
| 571 | Examples: |
| 572 | |
| 573 | msg.add_header('content-disposition', 'attachment', filename='bud.gif') |
| 574 | msg.add_header('content-disposition', 'attachment', |
| 575 | filename=('utf-8', '', 'Fußballer.ppt')) |
| 576 | msg.add_header('content-disposition', 'attachment', |
| 577 | filename='Fußballer.ppt')) |
| 578 | """ |
| 579 | parts = [] |
| 580 | for k, v in _params.items(): |
| 581 | if v is None: |
| 582 | parts.append(k.replace('_', '-')) |
| 583 | else: |
| 584 | parts.append(_formatparam(k.replace('_', '-'), v)) |
| 585 | if _value is not None: |
| 586 | parts.insert(0, _value) |
| 587 | self[_name] = SEMISPACE.join(parts) |
| 588 | |
| 589 | def replace_header(self, _name, _value): |
| 590 | """Replace a header. |