POP3 client, Step 2

myline

In this step, I'm going to show you how to view a specific message + how to delete a specific message from the remote mailbox. Before I start my blah...blah..., I guess it will be good idea to give you a sample session using this step:

   POP server[192.168.1.1]: 
   username at 192.168.1.1 [jchakma]: 
   Enter password for jchakma@192.168.1.1: 
   Ok, now trying to get connected to 192.168.1.1 ....
   Connected successfully to 192.168.1.1
   Now trying to login...
   You got 3 mail(s) in 192.168.1.1
    1  chakma junan  testing big file....
    2  chakma junan  testing 4
    3  chakma junan  testing 5
    View   message ---> v[msg_no]
    Delete message ---> d[msg_no]
    Show all  hdrs ---> s        
    Quit           ---> q/Q      

   COMMAND> 

Now, you can view/delete a message by typing:

   COMMAND> v2    # to view message number 2
   COMMAND> d2    # to dele message number 2
   COMMAND> s     # to show all headers

Ok, here comes some nasty subroutines to get my job done.

showheaders subroutine

This subroutine simply shows all the headers in the remote mailbox --- if you are following all the previous steps, you need not go through this subroutine! It just greps all the headers and shows the From and Subject line.

viewmessage subroutine

This subroutine simply retrieves a message from the remote mailserver and prints that message(including headers). This is more or less same as 'showheaders' subroutine. The important part is:

   $allmsg = $remoteserver->get($msg_no);

   foreach $line (@$allmsg)
   {
      print "$line";
   }

Since, get method returns a reference to an array, we access the contents of that array by '@$allmsg'.

deletemessage subroutine

This subroutine simply marks a message for deletion --- it doesn't actually delete the message. The actual message deletion is done after you close your connection from the remote mail server. This subroutine also prompts you for reconfirmation. However, at the end of a session, the script again prompts for an updating-reconfirmation --- if you want to redo everything you done on a session, you can choose 'n' (meaning 'no') at the end of a session. An example session:

   You got 3 mail(s) in 192.168.1.1
    1  chakma junan  testing big file....
    2  chakma junan  testing 4
    3  chakma junan  testing 5
    View   message ---> v[msg_no]
    Delete message ---> d[msg_no]
    Show all  hdrs ---> s        
    Quit           ---> q/Q      

    COMMAND> d2
   Deleting Message: 2[y/n] y
   Mark for deletion is set for message: 2
     View   message ---> v[msg_no]
     Delete message ---> d[msg_no]
     Show all  hdrs ---> s        
     Quit           ---> q/Q      

    COMMAND> q
Do you want to update your remote mbox?[y/n] n
Closing the connection from 192.168.1.1 now...

The next step

I haven't done anything on saving the mails retrieved from the remote mailserver --- all I did is to quickly view a summary of the remote mailbox. I hope to further develop this script so that you can as well save all the retrieved mails in your local mailbox(when? I'm not sure). Have fun. Bye!

So, here goes the new code. Check it out!

myline

this page is maintained by:
jchakma@yahoo.com

1