144
145
the attachment type.
146
147
for name in self._get_client_commands():
147
cmdline = _get_compose_8bit_commandline(name, to, subject,
148
cmdline = [self._encode_path(name, 'executable')]
149
cmdline.extend(self._get_compose_commandline(to, subject,
150
152
subprocess.call(cmdline)
151
153
except OSError, e:
167
169
raise NotImplementedError
169
def _get_compose_8bit_commandline(self, name, to, subject, attach_path):
170
"""Wrapper around _get_compose_commandline()
171
to ensure that resulting command line is plain string.
173
:param name: name of external mail client (first argument).
176
user_encoding = osutils.get_user_encoding()
178
to = to.encode(user_encoding, 'replace')
180
subject = subject.encode(user_encoding, 'replace')
181
cmdline.extend(self._get_compose_commandline(to, subject,
171
def _encode_safe(self, u):
172
"""Encode possible unicode string argument to 8-bit string
173
in user_encoding. Unencodable characters will be replaced
176
:param u: possible unicode string.
177
:return: encoded string if u is unicode, u itself otherwise.
179
if isinstance(u, unicode):
180
return u.encode(bzrlib.user_encoding, 'replace')
183
def _encode_path(self, path, kind):
184
"""Encode unicode path in user encoding.
186
:param path: possible unicode path.
187
:param kind: path kind ('executable' or 'attachment').
188
:return: encoded path if path is unicode,
189
path itself otherwise.
190
:raise: UnableEncodePath.
192
if isinstance(path, unicode):
194
return path.encode(bzrlib.user_encoding)
195
except UnicodeEncodeError:
196
raise errors.UnableEncodePath(path, kind)
186
200
class Evolution(ExternalMailClient):
196
210
if attach_path is not None:
197
211
message_options['attach'] = attach_path
198
212
options_list = ['%s=%s' % (k, urlutils.escape(v)) for (k, v) in
199
message_options.iteritems()]
200
return ['mailto:%s?%s' % (to or '', '&'.join(options_list))]
213
sorted(message_options.iteritems())]
214
return ['mailto:%s?%s' % (self._encode_safe(to or ''),
215
'&'.join(options_list))]
203
218
class Mutt(ExternalMailClient):
209
224
"""See ExternalMailClient._get_compose_commandline"""
210
225
message_options = []
211
226
if subject is not None:
212
message_options.extend(['-s', subject ])
227
message_options.extend(['-s', self._encode_safe(subject)])
213
228
if attach_path is not None:
214
message_options.extend(['-a', attach_path])
229
message_options.extend(['-a',
230
self._encode_path(attach_path, 'attachment')])
215
231
if to is not None:
216
message_options.append(to)
232
message_options.append(self._encode_safe(to))
217
233
return message_options
234
250
"""See ExternalMailClient._get_compose_commandline"""
235
251
message_options = {}
236
252
if to is not None:
237
message_options['to'] = to
253
message_options['to'] = self._encode_safe(to)
238
254
if subject is not None:
239
message_options['subject'] = subject
255
message_options['subject'] = self._encode_safe(subject)
240
256
if attach_path is not None:
241
257
message_options['attachment'] = urlutils.local_path_to_url(
254
270
"""See ExternalMailClient._get_compose_commandline"""
255
271
message_options = []
256
272
if subject is not None:
257
message_options.extend( ['-s', subject ] )
273
message_options.extend(['-s', self._encode_safe(subject)])
258
274
if attach_path is not None:
259
message_options.extend( ['--attach', attach_path] )
275
message_options.extend(['--attach',
276
self._encode_path(attach_path, 'attachment')])
260
277
if to is not None:
261
message_options.extend( [ to ] )
278
message_options.extend([self._encode_safe(to)])
263
279
return message_options
272
288
"""See ExternalMailClient._get_compose_commandline"""
274
290
raise errors.NoMailAddressSpecified()
291
commandline = [self._encode_safe(to)]
276
292
if subject is not None:
277
commandline.extend(['--subject', subject])
293
commandline.extend(['--subject', self._encode_safe(subject)])
278
294
if attach_path is not None:
279
commandline.extend(['--attach', attach_path])
295
commandline.extend(['--attach',
296
self._encode_path(attach_path, 'attachment')])
280
297
return commandline