0

I use gnus configured to read mails from the davmail IMAP server. This one is used to read mails from outlook and translate them according to the IMAP protocol.

When I start gnus, I configured emacs to autostart the davmail server, with following function :

(defun davmail/start ()
  "Run davmail externally for gnus."
  (interactive)
  (if (buffer-live-p "*davmail*")
      (kill-buffer "*davmail*"))
  (let ((default-directory davmail-directory))
    (start-process "davmail" "*davmail*" local-java-path "-jar" davmail-jar davmail-properties)))

The trouble is that davmail often asks to accept the outlook server certificate, which blocks gnus. To overcome this issue, I implemented this function :

(defun davmail/accept_certificate ()
  "Accept certificate."
  (interactive)
  (if (get-process "davmail")
      (process-send-string "davmail" "o\n")
    (message "No running davmail process")))

which retrieves the emacs davmail process and send to it the "o" (accept) string.

It works but it remains a little painful. I would like to trigger this function whenever the davmail process asks for certificate acceptation. Usually, it is a line containing "accept certificate (o/n) ?"

This way, I would not have to do it manually each time it occurs. But i am rather new to emacs/lisp and implementing this overpasses my skills. Could you give me some pieces of advices ?

I am aware that it is not really an emacs related issue, I could as well ask to the davmail developers to implement some kind of auto accept certificate option. But it is a good opportunity for me to improve my emacs skills.

Regards

1

1 Answer 1

0

You can do this by switching to using make-process and specifying a :filter function that checks for the expected output. Something like this:

(defvar davmail-output nil)
(defun davmail/start ()
  "Run davmail externally for gnus."
  (interactive)
  (setq davmail-output nil)
  (let ((default-directory davmail-directory))
    (make-process :name "davmail"
                  :buffer nil
                  :command (list local-java-path "-jar" davmail-jar davmail-properties)
                  :filter (lambda (proc string)
                            (setq davmail-output (concat davmail-output string))
                            (when (string-match "accept certificate" davmail-output)
                              (davmail/accept-certificate))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.