Skip to content

Instantly share code, notes, and snippets.

@html
Created July 11, 2014 13:47
Show Gist options
  • Save html/157401a38fd5c002b288 to your computer and use it in GitHub Desktop.
Save html/157401a38fd5c002b288 to your computer and use it in GitHub Desktop.
Guerrilla mail api functions
(defvar *last-email-id* nil)
(defvar *last-email*)
(defvar *guerrilla-cookie*)
(defun drakma-request (&rest args)
; posible errors 'drakma::drakma-simple-error
; usocket:timeout-error
(let ((result))
(loop do
(setf result (ignore-errors (apply #'drakma:http-request args)))
(if result
(return-from drakma-request
(if (stringp result)
result
(flexi-streams:octets-to-string result)))
(progn
(format t "Failed to get result from ~A, trying again~%" (car args))
(sleep 3))))))
(defun guerrilla-get-email-address ()
(let* ((cookie (make-instance 'drakma:cookie-jar))
(result (drakma-request "http://api.guerrillamail.com/ajax.php?f=get_email_address" :cookie-jar cookie))
(decoded (json:decode-json-from-string result)))
(setf *last-email-id* (cdr (assoc :alias decoded)))
(setf *last-email* (cdr (assoc :email--addr decoded)))
(setf *guerrilla-cookie* cookie)))
(defun guerrilla-get-last-email ()
(cdr
(assoc :list (json:decode-json-from-string
(drakma-request (format nil "http://api.guerrillamail.com/ajax.php?f=check_email&seq=~A" *last-email-id*)
:cookie-jar *guerrilla-cookie*)))))
(defun guerrilla-list-emails ()
(cdr
(assoc :list (json:decode-json-from-string
(drakma-request (format nil "http://api.guerrillamail.com/ajax.php?f=get_email_list&offset=0")
:cookie-jar *guerrilla-cookie*)))))
(defun print-guerrilla-emails ()
(loop for i in (guerilla-list-emails)
do
(format t "~20A | ~A~%" (subseq (cdr (assoc :mail--subject i)) 0 20) (subseq (substitute #\Space #\Newline (cdr (assoc :mail--excerpt i))) 0 50))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment