Exemplo n.º 1
0
 def _write_headers(self, msg):
     # This is almost the same as the string version, except for handling
     # strings with 8bit bytes.
     for h, v in msg._headers:
         self.write('%s: ' % h)
         if isinstance(v, str):
             if _has_surrogates(v):
                 if not self.policy.must_be_7bit:
                     # If we have raw 8bit data in a byte string, we have no idea
                     # what the encoding is.  There is no safe way to split this
                     # string.  If it's ascii-subset, then we could do a normal
                     # ascii split, but if it's multibyte then we could break the
                     # string.  There's no way to know so the least harm seems to
                     # be to not split the string and risk it being too long.
                     self.write(v+NL)
                     continue
                 h = Header(v, charset=_charset.UNKNOWN8BIT, header_name=h)
             else:
                 h = Header(v, header_name=h)
         else:
             # Assume it is a Header-like object.
             h = v
         self.write(h.encode(linesep=self._NL,
                             maxlinelen=self._maxheaderlen)+self._NL)
     # A blank line always separates headers from body
     self.write(self._NL)
Exemplo n.º 2
0
 def _handle_text(self, msg):
     # If the string has surrogates the original source was bytes, so
     # just write it back out.
     if _has_surrogates(msg._payload):
         self.write(msg._payload)
     else:
         super(BytesGenerator,self)._handle_text(msg)
Exemplo n.º 3
0
 def _handle_text(self, msg):
     # If the string has surrogates the original source was bytes, so
     # just write it back out.
     if msg._payload is None:
         return
     if _has_surrogates(msg._payload):
         self.write(msg._payload)
     else:
         super(BytesGenerator, self)._handle_text(msg)
Exemplo n.º 4
0
 def _handle_text(self, msg):
     # If the string has surrogates the original source was bytes, so
     # just write it back out.
     if msg._payload is None:
         return
     if _has_surrogates(msg._payload) and not self.policy.must_be_7bit:
         self.write(msg._payload)
     else:
         super(BytesGenerator,self)._handle_text(msg)
Exemplo n.º 5
0
 def _handle_text(self, msg):
     # If the string has surrogates the original source was bytes, so
     # just write it back out.
     if msg._payload is None:
         return
     if _has_surrogates(msg._payload):
         if self._mangle_from_:
             msg._payload = fcre.sub(">From ", msg._payload)
         self._write_lines(msg._payload)
     else:
         super(BytesGenerator,self)._handle_text(msg)
 def _handle_text(self, msg):
     # If the string has surrogates the original source was bytes, so
     # just write it back out.
     if msg._payload is None:
         return
     if _has_surrogates(msg._payload):
         if self._mangle_from_:
             msg._payload = fcre.sub(">From ", msg._payload)
         self._write_lines(msg._payload)
     else:
         super(BytesGenerator, self)._handle_text(msg)
Exemplo n.º 7
0
 def _handle_text(self, msg):
     payload = msg.get_payload()
     if payload is None:
         return
     if not isinstance(payload, str):
         raise TypeError('string payload expected: %s' % type(payload))
     if _has_surrogates(msg._payload):
         charset = msg.get_param('charset')
         if charset is not None:
             del msg['content-transfer-encoding']
             msg.set_payload(payload, charset)
             payload = msg.get_payload()
     if self._mangle_from_:
         payload = fcre.sub('>From ', payload)
     self._write_lines(payload)
 def _handle_text(self, msg):
     payload = msg.get_payload()
     if payload is None:
         return
     if not isinstance(payload, str):
         raise TypeError('string payload expected: %s' % type(payload))
     if _has_surrogates(msg._payload):
         charset = msg.get_param('charset')
         if charset is not None:
             del msg['content-transfer-encoding']
             msg.set_payload(payload, charset)
             payload = msg.get_payload()
     if self._mangle_from_:
         payload = fcre.sub('>From ', payload)
     self._write_lines(payload)
Exemplo n.º 9
0
 def _write_headers(self, msg):
     # This is almost the same as the string version, except for handling
     # strings with 8bit bytes.
     for h, v in msg._headers:
         self.write('%s: ' % h)
         if isinstance(v, Header):
             self.write(v.encode(maxlinelen=self._maxheaderlen)+self._NL)
         elif _has_surrogates(v):
             # If we have raw 8bit data in a byte string, we have no idea
             # what the encoding is.  There is no safe way to split this
             # string.  If it's ascii-subset, then we could do a normal
             # ascii split, but if it's multibyte then we could break the
             # string.  There's no way to know so the least harm seems to
             # be to not split the string and risk it being too long.
             self.write(v+NL)
         else:
             # Header's got lots of smarts and this string is safe...
             header = Header(v, maxlinelen=self._maxheaderlen,
                             header_name=h)
             self.write(header.encode(linesep=self._NL)+self._NL)
     # A blank line always separates headers from body
     self.write(self._NL)
Exemplo n.º 10
0
 def _write_headers(self, msg):
     # This is almost the same as the string version, except for handling
     # strings with 8bit bytes.
     for h, v in msg._headers:
         self.write('%s: ' % h)
         if isinstance(v, Header):
             self.write(v.encode(maxlinelen=self._maxheaderlen)+NL)
         elif _has_surrogates(v):
             # If we have raw 8bit data in a byte string, we have no idea
             # what the encoding is.  There is no safe way to split this
             # string.  If it's ascii-subset, then we could do a normal
             # ascii split, but if it's multibyte then we could break the
             # string.  There's no way to know so the least harm seems to
             # be to not split the string and risk it being too long.
             self.write(v+NL)
         else:
             # Header's got lots of smarts and this string is safe...
             header = Header(v, maxlinelen=self._maxheaderlen,
                             header_name=h)
             self.write(header.encode(linesep=self._NL)+self._NL)
     # A blank line always separates headers from body
     self.write(self._NL)