mIRC Homepage
Posted By: bwr30060 POP mail checker - 10/02/06 02:59 PM
I've given up on COM objects for now until I can find more examples and tutorials to study and can find something to make with them, but I had an idea and just wanted to see if this was possible. I'd like to make a POP mail checker for mIRC using sockets. Is this possible? I'm not sure about the commands to use to authenticate and then get the data. I'd like to have it so I could see who the email is from and the subject. I don't necessarily need to be able to read the email from mIRC. Another bonus feature would be to delete the email. Thanks.
Posted By: qwerty Re: POP mail checker - 10/02/06 03:33 PM
Check out this tutorial for the basics. Generally, keep in mind that this isn't a mirc-related issue, what you actually have to do is read the related RFC document for the protocol you want to implement. That's of course assuming that you have a good understanding of sockets already (there are tutorials for that too, like this one)
Posted By: bwr30060 Re: POP mail checker - 10/02/06 04:01 PM
Thank you for that help. This looks like it will work pretty easily. One more question for an optional feature. Do you know of any good way to strip out the coding or just retrieve the info that I want. I'd like to see a list of emails, then be able to select one. Once I select one to read, I'd just like to see this:

To: My address here
From: Their address
Body of message

Thanks for your help.
Posted By: bwr30060 Re: POP mail checker - 10/02/06 05:15 PM
I just got this working enough to echo a whole email message but I changed something and now it won't echo. I can't figure out what I did. Any ideas?
Code:
on 1:sockopen:mail:{
  echo -a socket opened
}
on 1:sockread:mail:{
  var %temptext
  sockread %temptext
  if %temptext = +OK POP3 server ready. {
    sockwrite -n $sockname user MyUserName
    sockwrite -n $sockname pass MyPassword
    sockwrite -n $sockname list
    echo -a %temptext    
    else { echo -a %temptext
    }  
  }
}

I get the two lines echoed that say:
socket opened
+OK POP3 server ready.
And, yes. MyUserName and MyPassword are the real things in my script, lol. Thanks.
Posted By: bwr30060 Re: POP mail checker - 10/02/06 05:52 PM
I fixed the problem.
Posted By: MikeChat Re: POP mail checker - 10/02/06 05:54 PM
you need to work on your brackets:
Code:
on 1:sockread:mail:{
  var %temptext
  sockread %temptext
  if %temptext = +OK POP3 server ready. {
    sockwrite -n $sockname user MyUserName
    sockwrite -n $sockname pass MyPassword
    sockwrite -n $sockname list
    echo -a %temptext 
  }
  else { echo -a %temptext }
}  


I cant test it, it doesn't look right to me to post the username and password in the sockREAD, isn't that meant to be on sockOPEN?
Posted By: MikeChat Re: POP mail checker - 10/02/06 05:56 PM
Quote:
I fixed the problem.


Please post your solution here, this helps others in the future who might do a search on the forum and need that same info.
Posted By: bwr30060 Re: POP mail checker - 10/02/06 06:07 PM
I fixed it by setting a variable and having it check if it had authenticated already. Now I'm having a problem trying to get it to put an email in a window. Here's the code with the fix, although the window part isn't working.
Code:
on 1:sockopen:mail:{
  echo -a socket opened
}
on 1:sockread:mail:{
  if ($sockerr) {
    echo -a Error.
    halt
  }  
  else {
    var %temptext
    sockread %temptext
    while (%auth != 1) {
      sockwrite -n $sockname user UserName
      sockwrite -n $sockname pass Password | set %auth 1
      sockwrite -n $sockname list
    }  
  }
  unset %auth
  sockwrite -n $sockname retr 1
  window @mail %temptext
}


I just saw your first post. It might work in either place (sockread or sockopen), but I put it in sockread because when you connect to the mail server, it sends "OK POP3 server ready.", so I figured it would sense that read and work from there.
Posted By: bwr30060 Re: POP mail checker - 10/02/06 06:38 PM
Any ideas on why this keeps putting the same email in the window multiple times? I currently have one email on the server that I sent myself, and I put the %retr variable in to stop it from doing it multiple times, but it still repeats. I'm also getting an "aline invalid parameters" message repeatedly in the status window. Thanks.
Code:
on 1:sockread:mail:{
  window @mail
  if ($sockerr) {
    echo -a Error.
    halt
  }  
  else {
    var %temptext
    sockread %temptext
    while (%auth != 1) {
      sockwrite -n $sockname user User
      sockwrite -n $sockname pass Password | set %auth 1
      sockwrite -n $sockname list
    }  
  }
  unset %auth
  while (%retr != 1) {
    sockwrite -n $sockname retr 1 
    set %retr 1
  }
  unset %retr
  aline @mail %temptext
}
Posted By: MikeChat Re: POP mail checker - 10/02/06 08:00 PM
Quote:
Any ideas on why this keeps putting the same email in the window multiple times? I currently have one email on the server that I sent myself, and I put the %retr variable in to stop it from doing it multiple times, but it still repeats. I'm also getting an "aline invalid parameters" message repeatedly in the status window. Thanks.
Code:
on 1:sockread:mail:{
  window @mail
  if ($sockerr) {
    echo -a Error.
    halt
  }  
  else {
    var %temptext
    sockread %temptext
    [color:red]while (%auth != 1) {[/color]
      sockwrite -n $sockname user User
      sockwrite -n $sockname pass Password | set  [color:red]%auth 1[/color]
      sockwrite -n $sockname list
    }  
  }
  [color:red] unset %auth[/color]
  while (%retr != 1) {
    sockwrite -n $sockname retr 1 
[color:red]    set %retr 1
  }
  unset %retr[/color]
  aline @mail %temptext
}


you set then right away unset your %vars that are used to check whether or not the script should do that, so every time the sockread fires it logs in, unsets the var then retrieves then unsets that var. put the Unsets in a sockclose event to start with, see what you get then.

on *:sockclose:mail:{
unset %retr
unset %auth
}
Posted By: MikeChat Re: POP mail checker - 10/02/06 08:14 PM
without diging deeper you probably should do it more like this:
Code:
on *:sockopen:mail:{
  sockwrite -n $sockname user User
  sockwrite -n $sockname pass Password
  sockwrite -n $sockname list
  sockwrite -n $sockname retr 1 
}

on 1:sockread:mail:{
  if (!$window(mail)) { window @mail }
  window @mail
  if ($sockerr) {
    echo -a Error.
    halt
  }  
  var %temptext
  sockread %temptext
  if (%temptext) {    
    aline @mail %temptext
  }
}


give that a shot

you need to go back and look at documentation for email via mIRC sockets because there is a lot you are missing
fex you only get the first email, as that is all you are requesting (and in this example too! I didnt change that)

anyway, try this change and see what you get
Posted By: bwr30060 Re: POP mail checker - 10/02/06 08:26 PM
Thanks. I'll try your code. I only have it checking for the first message just because I'm testing. It'll check for all of them once I get it working better. Thanks again.
Posted By: bwr30060 Re: POP mail checker - 10/02/06 08:38 PM
I tried yours and it worked once, and then a bunch of times it only said "+OK POP3 server ready." in the window. I think I might need IF statements for when it's asking for username and password. I think throwing all of the lines at it at the same time can mess it up sometimes. It didn't give me errors, but it didn't do anything else.
Posted By: MikeChat Re: POP mail checker - 10/02/06 09:23 PM
once retieved, does the mail still exist on the server?
though I didn't see a command in your code to tell the server to del after you retrieved. Try accessing the mailbox with regular mail software, and send a fresh email to the mailbox.
Posted By: bwr30060 Re: POP mail checker - 10/02/06 09:58 PM
The mail still exists on the server. I'm not actually retrieving it, just viewing it from there (when it works). I have a hunch that it might be that the script is executing the next sockwrite before the mail server is ready for it. I just ran it now and only got:
+OK POP3 server ready.
This means that the socket opened, but nothing else happened. It's a little odd and frustrating that I didn't get any errors. Do you think that's the case that the script is going too fast for the server? Do I need to analyze everything the server sends me, so I'd have a bunch of statements like:
Code:
if (%temptext == +OK POP3 server ready.) { sockwrite -n $sockname user UserName }
if (%temptext == +OK please send PASS command) { sockwrite -n pass Password }

That would make it longer, but I might have to do that.
Posted By: MikeChat Re: POP mail checker - 10/02/06 11:31 PM
you may be right,
before burning too many braincells you might try this Link
Posted By: FiberOPtics Re: POP mail checker - 11/02/06 01:53 AM
Thanks for referring to my addon.

Note that in the addon pop3 isn't used because Gmail's pop3 requires SSL, something you cannot accomplish with mIRC's socket features, atleast not without a third party application like stunnel.

The addon is tailored specifically for Gmail as what it does is simulate what a web browser sends, and uses COM for some specific parts.

For other email accounts he will not be able to use my addon, but hopefully their pop3 service will not require SSL.
Posted By: MikeChat Re: POP mail checker - 11/02/06 04:26 AM
ah ok, I did a quick search of the forum and yours came up, I remembered you had done one just recently so thought it would be a good one to sample from.

Looks like I may have confused things worse!
Posted By: bwr30060 Re: POP mail checker - 11/02/06 04:00 PM
I found this POP mail checker and it uses sockmarks. I haven't used them and I'm not familiar with how they work or what they do exactly. Does this make sure they're executed in the right order, and do you need to put something before a line like this to mark them? I didn't see where that was done in this case. I'll post the lines using what I believe are sockmarks.
Code:
if ($sock($sockname).mark == 1) { mail.write USER %mail.user | mail.mark 2 | return }
      if ($sock($sockname).mark == 2) { mail.write PASS %mail.pass | mail.mark 3 | return }
      if ($sock($sockname).mark == 3) { mail.write STAT | mail.mark 4 | return }
      if ($sock($sockname).mark == 4) { echo -a -> /mail.check: $2 new mail(s) | mail.write QUIT | mail.mark 5 | unset %mail.user %mail.pass | return }
Posted By: MikeChat Re: POP mail checker - 11/02/06 06:10 PM
I dont know what to tell you, I look back in this thread and see where Qwerty gave you two really good links to help with this, you can also do a forum search for "email" expand the search period to 5 years and I bet with some diligence you will find good examples (other than the links mentioned above)
Posted By: bwr30060 Re: POP mail checker - 12/02/06 02:09 PM
My script is still only working sometimes. I've decided to put IF statements to see what point it's at before sending the next command. My question is: Is there a way to refer to what it has just read, like how other "ON" events use $1- to refer to what triggered the event? Would $sockbr equal the text in the buffer or just a 1 or 0 to show whether there is something in the buffer? Thanks.

I'd like to add checks to make sure it is getting the right response before sending the next command. How/where would I put these into the script I have in this thread?
I'll assume for now that $sockbr will return the contents of the buffer.
Code:
if ($sockbr == +OK POP3 server ready.) { sockwrite -n $sockname user UserName }
if ($sockbr == +OK please send PASS command) { sockwrite -n $sockname pass Password }
if ($sockbr == +OK MyName is welcome here) { sockwrite -n $sockname list }

Thanks.
Posted By: bwr30060 Re: POP mail checker - 12/02/06 03:36 PM
I figured out the problem. I had two sockreads, so it was skipping over some things that it needed in the buffer. I'll post the new code.
Code:
on *:sockopen:mail:{
  var %temptext
  sockread %temptext
}
on 1:sockread:mail:{
  ;sockwrite -n $sockname user bwraab
  sockread %temptext
  if (!$window(mail)) { window @mail }
  window @mail
  if (%temptext == +OK POP3 server ready.) { sockwrite -n $sockname user UserName }
  if (%temptext == +OK please send PASS command) { sockwrite -n $sockname pass Password }
  if (%temptext == +OK MyName is welcome here) { sockwrite -n $sockname list }
  if (%temptext == +OK 1 messages) { sockwrite -n $sockname retr 1 }
  if ($sockerr) {
    echo -a Error.
    halt
  }  
  if (%temptext) {    
    aline @mail %temptext
  }
  ;sockwrite -n $sockname quit
}

I hard coded "retr 1" in there just for testing purposes, because I knew there was 1 message on the server. I'm still working on this script, so it will change.
© mIRC Discussion Forums