[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] 'POP3.pm' Functions: 'uidl()' and 'last()' Problems(?)



I wrote the following Code inorder to learn how to use the 'POP3.pm' Functions.

----- Code starts here -----

#!perl #-w

# Demonstrates how to receive e-Mail Messages.

use Net::POP3;	  # Module required for Client POP3 communications

my ($theUser) = 'USER_ID';                      # Users' Login 
Identification - please use your ID here
my ($thePass) = 'USER_PASSWORD';                # Users' Password - 
please use your Password here
my ($theMailAccount) = 'USER_MAIL_ACCOUNT';	# Users' pop Mail 
Account - please use your Mail Account here

my ($theHeaderAndStringLines);	   # Array Reference
my ($messageLines) = 0;	           # Number of Lines of Message to print
my ($theList);                     # Number or Hash Reference
my (@theMessage);                  # Array Reference
my ($lastMessage);
my (@theStats);	                   # Array Reference
my ($uniqueIdentifier);
my ($item);
my ($i, $j, $k);                   # Incrementors
my ($theStatus);

print "\n" . "Creating a connection..." . "\n";	# About to create a 
'Net::POP3' Object.
my ($pop) = Net::POP3->new($theMailAccount);
if ($pop){

  print "Login'ing onto Server..." . "\n";   # About to login to Internet.

# Login to Internet.  If e-Mail exists, Number of e-Mails is returned.
  my ($theCount) = $pop->login($theUser, $thePass);

  if ($theCount){		            # Continue only if e-Mail 
Message(s) exist.

   @theStats = $pop->popstat;
   print "\n" . "Total Number of undeleted e-Mail Messages: " . 
@theStats[0] . " , Total Size of Message: " . @theStats[1] . " 
Bytes." . "\n";
# Print each Element [one Line of e-Mail Message] of the Array
  	print "\n";

   $theList = $pop->list;
   foreach $item (sort(keys(%$theList))){    # Loop through the Hash
    print "Undeleted e-Mail Messages' Message Number: " . $item . ", 
Size of Message: " . $$theList{$item} . " Bytes." . "\n";
# Print each Element [one Line of e-Mail Message] of the Array
   }
   print "\n";

   $uniqueIdentifier = $pop->uidl();
   foreach $item (sort(keys(%$uniqueIdentifier))){   # Loop through the Hash
    print "Undeleted e-Mail Messages' Message Number: " . $item . ", 
Unique Identifier: " . $$uniqueIdentifier{$item} . "." . "\n";
# Print each Element [one Line of e-Mail Message] of the Array
   }

#  for ($i = 1; $i <= 1; $i++){
# I use the above 'for' Line and comment out the next 'for' Line for 
testing my Code - limits the Loop to one [1] Message.
  for ($i = 1; $i <= $theCount; $i++){

# If I un-comment the next two [2] Lines (actually just the next one) 
the '$pop->uidl(x)' Function causes the remaining '$pop->...' 
Functions not to work!
# $uniqueIdentifier = $pop->uidl($i);  # Unique e-Mail Identification Number.
# print "Unique e-Mail ID Number: " . $uniqueIdentifier . "\n" if 
(defined($uniqueIdentifier));
# Print unique e-Mail Identification Number.

   $theList = $pop->list($i);		  # Size in Bytes of 
individual e-Mail Message.
   print "\n" . "e-Mail Message Number: " . $i. " is " . $theList . " 
Bytes; " . $messageLines ." Lines of Message to be shown." . "\n"; 
	# Print out the e-Mail Messages' Size in Bytes.

   $theHeaderAndStringLines = $pop->top ($i, $messageLines);
   print "\n" . "Headers and partial Message: " . "\n\n";	# 
About to print the complete Message [including the Header].
   for ($j = 0; $j < $#$theHeaderAndStringLines; $j++){		# 
Loop through the Array
    print $$theHeaderAndStringLines[$j]; 
 
					# Print each Element [one 
Line of e-Mail Message] of the Array
   }

   print "\n" . "Headers and complete Message:" . "\n\n";
# About to print the complete Message [including the Header].
   $theMessage = $pop->get($i);         # 'pop->get(x)' returns e-Mail 
Message Number 'x'.
   for ($j = 0; $j < $#$theMessage; $j++){	# Loop through the Array
    print $$theMessage[$j]; 
 
							# Print each 
Element [one Line of e-Mail Message] of the Array.
   }

   print "\n" . "____________________________________" . "\n\n";
   }
  }

  $lastMessage = $pop->last();  # Last e-Mail Message.
  print "\n" . "Last e-Mail Message Number: " . $lastMessage . "\n\n"; 
	# Print out the last e-Mail Messages' Number.

  $pop->quit;  # Hmmm, '$pop->close' did not cause a 'Syntax Check' Error!
}

print "Das Ende." ."\n\n";    # Notification of end of Application.

----- Code ends here -----

I wrote similar Code to use the 'delete()' and 'reset()' Functions - 
which works fine.

---

Question 01:
Why if I un-comment these two [2] Lines:

# $uniqueIdentifier = $pop->uidl($i);  # Unique e-Mail Identification Number.
# print "Unique e-Mail ID Number: " . $uniqueIdentifier . "\n" if (defined($uniqueIdentifier));

do I not see '$uniqueIdentifier's Value printed, and the remaining 
'$pop' Functions do not work?


Question 02:

Why do these two [2] Lines:

  $lastMessage = $pop->last();  # Last e-Mail Message.
  print "\n" . "Last e-Mail Message Number: " . $lastMessage . "\n\n"; 
	# Print out the last e-Mail Messages' Number.

not print out the correct (or expected) '$lastMessage' Value?


Question 03:

If one uses the '$pop->login()' Function (with its '$theUser' and 
'$thePass' respective Parameters) to actually log into a Server, when 
would the '$pop->user()' and '$pop->pass' Functions be used?


If possible, please provide a small Example with each Answer.

---

Thanks,

Samuel

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org