1 """Various tools used by MIME-reading or MIME-writing programs."""
8 __all__ = [
"Message",
"choose_boundary",
"encode",
"decode",
"copyliteral",
12 """A derived class of rfc822.Message that knows about MIME headers and
13 contains some hooks for decoding encoded and multipart messages."""
18 self.
getheader(
'content-transfer-encoding')
34 fields = str.split(
'/')
35 for i
in range(len(fields)):
56 self.plist.append(f.strip())
63 name = name.lower() +
'='
75 result.append(p[:i].
lower())
81 return self.encodingheader.lower()
102 """Return a random string usable as a multipart boundary.
103 The method used is so that it is *very* unlikely that the same
104 string of characters will every occur again in the Universe,
105 so the caller needn't check the data it is packing for the
106 occurrence of the boundary.
108 The boundary contains dots so you have to quote it in the header."""
116 hostid = socket.gethostbyname(socket.gethostname())
125 _prefix = hostid +
'.' + uid +
'.' + pid
126 timestamp =
'%.3f' % time.time()
128 return _prefix +
'.' + timestamp +
'.' + seed
134 """Decode common content-transfer-encodings (base64, quopri, uuencode)."""
135 if encoding ==
'base64':
138 if encoding ==
'quoted-printable':
141 if encoding
in (
'uuencode',
'x-uuencode',
'uue',
'x-uue'):
144 if encoding
in (
'7bit',
'8bit'):
145 return output.write(input.read())
146 if decodetab.has_key(encoding):
150 'unknown Content-Transfer-Encoding: %s' % encoding
153 """Encode common content-transfer-encodings (base64, quopri, uuencode)."""
154 if encoding ==
'base64':
157 if encoding ==
'quoted-printable':
160 if encoding
in (
'uuencode',
'x-uuencode',
'uue',
'x-uue'):
163 if encoding
in (
'7bit',
'8bit'):
164 return output.write(input.read())
165 if encodetab.has_key(encoding):
169 'unknown Content-Transfer-Encoding: %s' % encoding
177 sed "s%^begin [0-7][0-7]* .*%begin 600 $TEMP%" | uudecode
183 'uuencode': uudecode_pipe,
184 'x-uuencode': uudecode_pipe,
185 'uue': uudecode_pipe,
186 'x-uue': uudecode_pipe,
187 'quoted-printable':
'mmencode -u -q',
188 'base64':
'mmencode -u -b',
192 'x-uuencode':
'uuencode tempfile',
193 'uuencode':
'uuencode tempfile',
194 'x-uue':
'uuencode tempfile',
195 'uue':
'uuencode tempfile',
196 'quoted-printable':
'mmencode -q',
197 'base64':
'mmencode -b',
201 pipe = os.popen(command,
'w')
207 temp =
open(tempname,
'w')
210 pipe = os.popen(command +
' <' + tempname,
'r')
217 line = input.readline()
224 line = input.read(BUFSIZE)