message[int] parse_mail() {
message[int] parsedmail;
// get a map of kmail in html
vprint("Checking mail...",2);
string temp = visit_url("messages.php");
if (contains_text(temp,"There are no messages in this mailbox.")) return parsedmail;
temp = substring( temp , 0 , index_of( temp , "Mailbox:" ) );
matcher m_pages = create_matcher( "<a href='messages\\.php\\?box=Inbox&begin=(\\d+)'>\\[\\d+\\]</a> " , temp );
int pages = 1;
while( m_pages.find() ){
pages = m_pages.group(1).to_int();
}
for page from 1 upto pages{
temp = visit_url( "messages.php?box=Inbox&begin="+page );
temp = substring(temp,index_of(temp,"checkbox name=\"")+15);
string[int] km = split_string(temp,"checkbox name=\"");
int p = 0;
for i from 0 upto count(km)-1 {
if (contains_text(km[i],"I have opted to let you know that I have chosen to run ") ||
contains_text(km[i],"[register ") ||
contains_text(km[i],"[url for ") ||
contains_text(km[i],"[unregister ")) {
// parse html into record structure
parsedmail[p].id = to_int(substring(km[i],3,index_of(km[i],"\"")));
parsedmail[p].text = excise(km[i],"<blockquote>","</blockquote>");
temp = substring(km[i],index_of(km[i],"showplayer.php"));
parsedmail[p].sender = url_encode(substring(temp,index_of(temp,">")+1,index_of(temp,"</a>")));
temp = substring(km[i],index_of(km[i],"<b>Date:</b> ")+13);
parsedmail[p].date = url_encode(substring(temp,0,index_of(temp,"<")));
p = count(parsedmail);
}
}
}
vprint(to_string(count(parsedmail))+" messages queued.","blue",2);
return parsedmail;
}