Created
July 11, 2014 13:47
-
-
Save html/157401a38fd5c002b288 to your computer and use it in GitHub Desktop.
Guerrilla mail api functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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