# Rediffmail # supports receiving of mail with attachments # supports sending of text mail # supports sending of text mail with attachments # # @Requires: 1.1 beta3 # @Version: 0.2.1 # german texts (with MrPostman 1.2.2+), module renamed to start with lowercase # @Version: 0.2 # sending of attachments # @Version: 0.1 sub getInfo local(info) info.name = "rediffmail" info.authors[0] = "Srinivasan Bhaskaran " info.version = "0.2.1" info.updateService = "" info.documentationLink = "" info.options["maxNum"].order = 1 info.options["maxNum"].value = 200 info.options["maxNum"].label = "Max Number of Messages" info.options["maxNum"].description = "The maximum number of messages to check for retrieval" #--- german texts info.options["maxNum"].de.label = "Max. Anzahl Nachrichten" info.options["maxNum"].de.description = "Die maximale Anzahl von Nachrichten, die überprüft bzw. heruntergeladen werden sollen" return info end sub getExtensions return list("@rediffmail.com") end sub login(username,password) local(found,id,params,logout_params,status,page,link) #--- set some basic settings to allow MrPostman doing some conversions, ... setbaseurl("http://mail.rediff.com/") size.locale = "en" size.unit[""] = 1024 date.locale = "en" date.format = "dd MMM yyyy h:mm:ss Z" #--- let's log in: found,id = match(username,"(.*)@") login = id params["FormName"] = "existing" params["login"] = id params["passwd"] = password params["x"]="13" params["y"]="9" status,page = post("/cgi-bin/login.cgi",params) #-- Get Logout link pattern_sessionid = "next") while (found and size(msgs)+1 < integer(info.options["maxNum"].value)) msgs1 = list() status,page = get(trim(link)) numfound1,msgs1[].id,msgs1[].link,msgs[].size.value, msgs[].size.unit = matchall(page,msgpat) msgs = join(msgs,msgs1) numfound = numfound + numfound1 found,link = match(page,"prev[^\|]*\|[^<]*next") end info("Total Number of messages found = " & numfound) return true end sub receive(msg) local(status,page,found,attachpat,numfound) info("Getting message " & msg.id & "...") msg.link = replaceall(msg.link,"\"","") status,page = get(msg.link) found,msg.from = match(page,"From:.*?]*>([^<]*)<") msg.from = replaceall(msg.from,"\|","") found,msg.to = match(page,"To:.*?]*>([^<]*)<") found,msg.cc = match(page,"Cc:.*?]*>([^<]*<.*?)") found,msg.bcc = match(page,"Bcc:.*?]*>([^<]*<.*?)") found,msg.subject = match(page,"Subject:.*?]*>([^<]*<.*?)") msg.subject = replaceall(msg.subject, "<.+?>","") found,msg.date = match(page,"Date:.*?]*>([^<]*.*?)") info("Date: " & msg.date) #-- Get the Message body found,msg.text = match(page,"HEADERS[^>]*>\\s*(]*>.*?]*>)",false) if (!found) found,msg.text = match(page,"Subject:([^>]*>).*?Date:",false) end warningif(!found,"Rediffmail: No message text found!") msg.mimetype = "text/html" msg.text = "" & msg.text & "" attachpat = "name=ATTACH.*?([^<]*).*?href=\"([^\"]*)\"\">Download\\s*Attachment" numfound,msg.attachments[].text,msg.attachments[].link = matchall(page,attachpat,true) return msg end sub delete(msgs) local(params, SortOrder, SortField) params["login"] = login params["btn_name1"] = "Delete" params["FormName"] = "sh_folder" params["folder"] = "Inbox" params["moveto_folder1"] = "" i = 0 while (i < size(msgs)) params["SelMsg" & i] = msgs[i].id #--found,session_id = match(msgs[i].link,".*?session_id=([^&]*)\&") i = i+1 end #-- found,SortField = match(msgs[size(msgs)].link,".*?SrtFld=([0-9]*)") #-- found,SortOrder = match(msgs[size(msgs)].link,".*?SrtOrd=([0-9]*)") SortField = 2 SortOrder = 1 params["session_id"] = session_id params["SrtFld"] = SortField params["SrtOrd"] = SortOrder params["MsgCnt"] = "0" params["total"] = "10" status,page = post("/bn/folder.cgi",params) return true end sub loginForSend(username,password) local(page,found) page = login(username,password) found,sendlink = match(page,"href=\"([^\"]*FormName=compose[^\"]*)\">.*?Write\s*Mail",true) return true end sub send(msg) local(status,page,found,params,i,aparams,uparams,attachment,attachtype) local(upload_link,complnk,attach_pattern,list) local(attachlist,att_list) status,page = get(trim(sendlink)) found,complnk = match(trim(sendlink),"([^\?]*)") #--- display attachment window: aparams["login"] = login aparams["FormName"] = "attach" aparams["session_id"] = session_id aparams["sid"] = "5" aparams["cid"] = "70773" url = geturl(complnk,aparams) status,page = get(url) found,upload_link = match(page,"