328
328
This temporary file will be loaded at runtime in
329
329
_get_compose_commandline function.
331
FIXME: this function does not remove the file. That's a wanted
331
This function does not remove the file. That's a wanted
332
332
behaviour since _get_compose_commandline won't run the send
333
333
mail function directly but return the eligible command line.
334
334
Removing our temporary file here would prevent our sendmail
337
A possible workaround could be to load the function here with
338
emacsclient --eval '(load temp)' but this is not robust since
339
emacs could have been stopped between here and the call to
335
function to work. (The file is deleted by some elisp code
336
after being read by Emacs.)
343
339
_defun = r"""(defun bzr-add-mime-att (file)
344
"Attach FILe to a mail buffer as a MIME attachment."
340
"Attach FILE to a mail buffer as a MIME attachment."
345
341
(let ((agent mail-user-agent))
348
342
(if (and file (file-exists-p file))
350
344
((eq agent 'sendmail-user-agent)
348
(if (functionp 'etach-attach)
350
(mail-attach-file file))))
352
351
((or (eq agent 'message-user-agent)(eq agent 'gnus-user-agent))
353
(mml-attach-file file "text/x-patch" "BZR merge" "attachment"))
353
(mml-attach-file file "text/x-patch" "BZR merge" "inline")))
354
((eq agent 'mew-user-agent)
356
(mew-draft-prepare-attachments)
357
(mew-attach-link file (file-name-nondirectory file))
358
(let* ((nums (mew-syntax-nums))
359
(syntax (mew-syntax-get-entry mew-encode-syntax nums)))
360
(mew-syntax-set-cd syntax "BZR merge")
361
(mew-encode-syntax-print mew-encode-syntax))
362
(mew-header-goto-body)))
355
(message "Unhandled MUA")))
364
(message "Unhandled MUA, report it on bazaar@lists.canonical.com")))
356
365
(error "File %s does not exist." file))))
373
382
if to is not None:
374
_to = ("\"%s\"" % self._encode_safe(to))
383
_to = ("\"%s\"" % self._encode_safe(to).replace('"', '\\"'))
375
384
if subject is not None:
376
_subject = ("\"%s\"" % self._encode_safe(subject))
385
_subject = ("\"%s\"" %
386
self._encode_safe(subject).replace('"', '\\"'))
378
388
# Funcall the default mail composition function
379
389
# This will work with any mail mode including default mail-mode
385
395
# Try to attach a MIME attachment using our wrapper function
386
396
if attach_path is not None:
387
397
# Do not create a file if there is no attachment
388
lmmform = '(load "%s")' % self._prepare_send_function()
398
elisp = self._prepare_send_function()
399
lmmform = '(load "%s")' % elisp
389
400
mmform = '(bzr-add-mime-att "%s")' % \
390
401
self._encode_path(attach_path, 'attachment')
402
rmform = '(delete-file "%s")' % elisp
391
403
commandline.append(lmmform)
392
404
commandline.append(mmform)
405
commandline.append(rmform)
394
407
return commandline