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

[MacPerl] Xmail



I love unix. Love it. Mklinux is the best.

I hate installing unix programs, and I don't like the way they run when I
have them. So: I figured, why not write a text based PERL E-Mail program of
my own? Here it is:

use Socket;
print "\nxmail 1.0\n";
print "\nxmail> ";
&comm;

sub comm {
	$command = <>;
	if ($command =~ /^help/i) {&help;}
	if ($command =~ /^\?/i)   {&help;}
	if ($command =~ /^send/i) {&sendit;}
	if ($command =~ /^exit/i) {die "user exited";}
	if ($command =~ /^list/i) {&list;}
	else {print "\nxmail> ";&comm;}
}

sub help {
print <<HE_LP;
Commands:

	send- sends mail
	help- displays this message
	exit- exits the xmail system
	list- lists mail messages in pop3 mailbox
HE_LP
print "\nxmail> ";&comm;
}

sub sendit {
my $serv = "mail.clarityconnect.com";

	print "Enter your E-Mail Address> ";
	chop (my $addy = <>);
	print "\nEnter the address to send to> ";
	chop (my $to = <>);
	print "Enter the subject> ";
	chop (my $subject = <>);
	print "\nEnter the message, type s on a separate line when done.\n";
	while (<>){
		last if ($_ =~ /^s\n/i);
		chop ($_ = $_);
		my $message .= $_;
		my $message .= "\015\012";
	}


	$/ = "\015\012";
	socket(Seraph, PF_INET, SOCK_STREAM, 6);
		my $sin = sockaddr_in("25",inet_aton("$serv"));
		my $conn = connect(Seraph,$sin);
		select((select(Seraph),$| = 1)[0]);
		die "Connection couldn't be made. $!" if ($conn != 1);
		my $msg = <Seraph>;
		print "$msg";
		if ($msg !~ /^220/) {die "Host not responding correctly";}
		print Seraph "EHLO\015\012";
		my $msg = <Seraph>;
		print "$msg";
		if ($msg !~ /^250/) {die "Host not responding correctly";}

		my $msg = <Seraph>;
		my $msg = <Seraph>;
		my $msg = <Seraph>;

		print Seraph "MAIL FROM: <$addy>\015\012";
	 my $msg = <Seraph>;
		#print STDOUT "$msg";
		if ($msg !~ /^250/) {die "Host not responding to MAIL FROM:
command  correctly";}

		print Seraph "RCPT TO: <$to>\015\012";
		my $msg = <Seraph>;
		#print STDOUT "$msg";
		if ($msg !~ /^250/) {die "Host not responding to RCPT TO:
command  correctly";}

		print Seraph "DATA\015\012";
		my $msg = <Seraph>;
		#print STDOUT "$msg";
		if ($msg !~ /^354/) {die "Host not responding to DATA
command correctly";}

		print Seraph "Subject: $subject\015\012\015\012";
		print Seraph "$message\015\012";
	 print Seraph ".\015\012";
		my $msg = <Seraph>;
		# print STDOUT "$msg";
		if ($msg !~ /^250/) {die "Host not accepting DATA correctly";}
		print STDOUT "Mail sent.\n";
	 print Seraph "QUIT\015\012";
		my $msg = <Seraph>;
		print STDOUT "$msg";
		if ($msg !~ /^221/) {die "Host didn't quit properly";}
	close(Seraph);
	print "\nMailing Complete.\n";
	print "\nxmail> ";&comm;
}

sub list {
	my $serv = "mail.clarityconnect.com";

	print "Enter your username> ";
	chop (my $user = <>);
	print "\nEnter your password> ";
	chop (my $pass = <>);


	$/ = "\015\012";
	socket(Seraph, PF_INET, SOCK_STREAM, 6);
		my $sin = sockaddr_in("110",inet_aton("$serv"));
		my $conn = connect(Seraph,$sin);
		select((select(Seraph),$| = 1)[0]);
		die "Connection couldn't be made. $!" if ($conn != 1);
		my $msg = <Seraph>;
		print "$msg";
		if ($msg !~ /^\+OK/) {die "Host didn't respond correctly.";}
		print Seraph "USER $user\015\012";
		my $msg = <Seraph>;
		print "$msg";
		if ($msg !~ /^\+OK/) {die "Username incorrect";}

		print Seraph "PASS $pass\015\012";
		my $msg = <Seraph>;
		print "$msg";
		if ($msg !~ /^\+OK/) {die "password incorrect";}

		print Seraph "LIST\015\012";
		my $msg = <Seraph>;
		if ($msg !~ /^\+OK/) {die "LIST failed";}
		while (<Seraph>){
			last if ($_ =~ /^\.\n/i);
			chop ($_ = $_);
			my $message .= $_;
			my $message .= "\n";
		}
		print Seraph "QUIT\015\012";
	close(Seraph);
	print "\nList compilation complete.\n";
	if ($message == "") {print "No messages in box.\n";}
	else{print "$message\n";}
	print "\nxmail> ";&comm;
}

after using ANY routine that requires input, I need to put a break after
everything I type (command-.) so that the program continues. I've tried
multiple versions of this, with while (<>) {  and eval() and if () and
nothing works. Any ideas?

-Seraph



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch