This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

script to set variables based on user input

3 posts · 4519 views

I am using the mew email reader in emacs. The reader accesses your pop accounts based on lisp variables you set in its configuration file. I am trying to write an interactive function which will set these variables based on user input (e.g. type 'y' for yahoo account, 'm' for msn, etc...) When I run the function below it ends up executing the else statement that 'the email account does not exist'.

Just from doing some rudimentary debugging i think the problem is that the user-entered character is being interpreted as an integer. I tried a function to convert an integer back to a character, but the function was void (int-char).
(defun popmail (account)

  "check the specified popmail account for mail"

  (interactive "cWhich account should I check? ")

  (if (char-equal account "y")
      ((setq mew-smtp-server "smtp.mail.yahoo.com")
       (setq mew-pop-user "rubinglen")
       (setq mew-pop-server "pop.mail.yahoo.com")
       (setq mew-pop-auth 'pass)
       (setq mew-pop-port nil)
       (setq mew-pop-ssl t)
       (setq mew-smtp-ssl t)
       (setq mew-smtp-port 465)
       (setq mew-pop-ssl-port 995)
       (setq mew-ssl-verify-level 0))

    (if (char-equal account "g") ; else part is another if
	((setq mew-smtp-server "smtp.gawab.com")
	 (setq mew-pop-user "[email protected]")
	 (setq mew-pop-server "pop.gawab.com")
	 (setq mew-pop-auth 'pass)
	 (setq mew-pop-ssl t)
	 (setq mew-pop-ssl-port 995)
	 (setq mew-pop-port 110)
	 (setq mew-smtp-port 25)
	 (setq mew-smtp-ssl nil)
	 (setq mew-ssl-verify-level nil))

      (message "email account does not exist"))));else the user entered the wrong letter

Re: script to set variables based on user input

rubing wrote:Just from doing some rudimentary debugging i think the problem is that the user-entered character is being interpreted as an integer. I tried a function to convert an integer back to a character, but the function was void (int-char).
In Emacs Lisp characters are integers. Which is unfortunate for various reasons, but in your case the problem is that CHAR-EQUAL takes two characters, and you are giving it a string "y" which is not a character, but a string. The literal syntax for characters in Emacs Lisp would be ?y. See: Basic Char Syntax in the Emacs Lisp Reference Manual. Also, you probably want COND or possibly CASE (from cl-macs extension) rather than chained IFs.

Re: script to set variables based on user input

Great, thanks for the advice! made the changes and works fine. here's the code now in my .mew.el file in case anyone wants to use it for themselves:
;; Optional setup (Read Mail menu for Emacs 21):
(if (boundp 'read-mail-command)
(setq read-mail-command 'mew))

;; Optional setup (e.g. C-xm for sending a message):
(autoload 'mew-user-agent-compose "mew" nil t)
(if (boundp 'mail-user-agent)
(setq mail-user-agent 'mew-user-agent))
(if (fboundp 'define-mail-user-agent)
(define-mail-user-agent
'mew-user-agent
'mew-user-agent-compose
'mew-draft-send-message
'mew-draft-kill
'mew-send-hook))

(defun popmail (account)
"check the specified popmail account for mail"
(interactive "cWhich account should I check? ")

(cond ((char-equal account ?y)
(setq mew-smtp-server "smtp.mail.yahoo.com")
(setq mew-pop-user "rubinglen")
(setq mew-pop-server "pop.mail.yahoo.com")
(setq mew-pop-auth 'pass)
(setq mew-pop-port nil)
(setq mew-pop-ssl t)
(setq mew-smtp-ssl t)
(setq mew-smtp-port 465)
(setq mew-pop-ssl-port 995)
(setq mew-ssl-verify-level 0)
(mew-summary-retrieve))
((char-equal account ?g)
(setq mew-smtp-server "smtp.gawab.com")
(setq mew-pop-user "[email protected]")
(setq mew-pop-server "pop.gawab.com")
(setq mew-pop-auth 'pass)
(setq mew-pop-ssl nil)
(setq mew-pop-ssl-port nil)
(setq mew-pop-port 110)
(setq mew-smtp-port 25)
(setq mew-smtp-ssl nil)
(setq mew-ssl-verify-level nil)
(mew-summary-retrieve))
((char-equal account ?q)
(message "mail check aborted"))
(message "invalid mail account"))) ; next add recursive call to fcn + 'try again'