(* ================================================== SIMPLE POP 3 Server for MacsThis is an AppleScript 1.1 script showing how to servemail using the POP 3 protocol using TCP/IP. version 1 12/21/94 by John C. Schettino, Jr (js12@gte.com) Copyright © 1994, John Schettino - js12@gte.comMay be freely distributed================================================== *)(* ================================================== REQUIRED osax (available on ftp://gaea.kgs.ukans.edu/applescript/osaxen)Requires TCP/IP Suite Vers 1.1.2 Copyright © 1993Ð1994, Atul Butte. All Rights Reserved.================================================== *)--| Constantsproperty CRLF : (ASCII character of 13) & (ASCII character of 10) -- All TCP/IP interactions end in CR LF--| Settingsproperty username : "yourName" -- set to your user nameproperty password : "yourpassword" -- set to your passwordproperty mailfolder : "For Newton" -- set to your Eudora mail folder containing mail for LunaMail--| global flagsglobal okUser, tcpSocket, deletedon run -- create the POP socket set tcpSocket to (tcp wait for connect port 110 buffer size 10240)end runon quit -- close the POP socket tcp close stream tcpSocket continue quitend quiton idle set okUser to false set userPass to false if connection status of (tcp status stream tcpSocket) is not Connected then return 5 -- wait for a connection... if no connection, try again in 5 seconds end if set deleted to {} -- send greeting tcp write data "+OK POP3 server ready" & CRLF stream tcpSocket -- handle protocol messages repeat try -- read request repeat until (tcp ahead stream tcpSocket characters CRLF) end repeat set msg to tcp read until characters CRLF stream tcpSocket strip characters CRLF -- process request if word 1 of msg = "USER" then if word 2 of msg ­ "js12" then tcp write data "-ERR" & CRLF stream tcpSocket else tcp write data "+OK js12" & CRLF stream tcpSocket set okUser to true end if else if word 1 of msg = "PASS" then if not okUser or word 2 of msg ­ "mindmagi" then tcp write data "-ERR" & CRLF stream tcpSocket set userPass to false set okUser to false else tcp write data "+OK js12" & CRLF stream tcpSocket set userPass to true end if else if word 1 of msg = "QUIT" then tcp write data "+OK later, man" & CRLF stream tcpSocket exit repeat else if not userPass then tcp write data "-ERR no valid user" & CRLF stream tcpSocket else if word 1 of msg = "STAT" then -- find number of email messages and their size tell application "Eudora2.1" set numsg to the number of message in mailbox "For Newton" of mail folder "" set sizemsg to space required of mailbox "For Newton" of mail folder "" end tell tcp write data "+OK " & numsg & " " & sizemsg * 1024 & CRLF stream tcpSocket else if word 1 of msg = "LIST" then if number of words in msg = 2 then set msgNo to word 2 of msg as integer tell application "Eudora2.1" set mmsg to (a reference to message msgNo of mailbox "For Newton" of mail folder "") set sizemsg to (get size of mmsg) end tell tcp write data "+OK " & msgNo & " " & sizemsg & CRLF stream tcpSocket -- err no such message else tcp write data "+OK scan follows" & CRLF stream tcpSocket tell application "Eudora2.1" set numsg to the number of message in mailbox "For Newton" of mail folder "" repeat with msgNo from 1 to numsg set mmsg to (a reference to message msgNo of mailbox "For Newton" of mail folder "") set sizemsg to (get size of mmsg) tcp write data "" & msgNo & " " & sizemsg & CRLF stream tcpSocket end repeat end tell tcp write data "." & CRLF stream tcpSocket end if else if word 1 of msg = "TOP" then set msgNo to word 2 of msg as integer set linesWanted to word 3 of msg as integer tcp write data "+OK top of message follows" & CRLF stream tcpSocket tell application "Eudora2.1" set mmsg to (a reference to message msgNo of mailbox "For Newton" of mail folder "") set sizemsg to (get size of mmsg) set msgtext to contents of mmsg end tell set returnString to "" set numSent to 0 set inBody to false repeat with p in paragraphs of msgtext if contents of p is "." then set p to ">." if length of (contents of p) = 0 then set inBody to true if not inBody or (inBody and numSent ² linesWanted) then if inBody then set numSent to numSent + 1 set returnString to returnString & p & CRLF else exit repeat end if end repeat tcp write data returnString & "." & CRLF stream tcpSocket else if word 1 of msg = "RETR" then set msgNo to word 2 of msg as integer tell application "Eudora2.1" set mmsg to (a reference to message msgNo of mailbox "For Newton" of mail folder "") set sizemsg to (get size of mmsg) tcp write data "+OK " & msgNo & " " & sizemsg & CRLF stream tcpSocket set msgtext to contents of mmsg end tell set returnString to "" repeat with p in paragraphs of msgtext if contents of p is "." then set p to ">." set returnString to returnString & p & CRLF end repeat tcp write data returnString & "." & CRLF stream tcpSocket else if word 1 of msg = "DELE" then set msgNo to word 2 of msg as integer set end of deleted to msgNo tcp write data "+OK " & msgNo & " deleted" & CRLF stream tcpSocket else if word 1 of msg = "NOOP" then tcp write data "+OK" & CRLF stream tcpSocket else if word 1 of msg = "RSET" then -- reset all deleted message set deleted to {} tcp write data "+OK" & CRLF stream tcpSocket end if end if on error str -- some error happened.. give up and close the socket tcp write data "-ERR " & str & CRLF stream tcpSocket set deleted to {} exit repeat end try end repeat -- delete any marked messages tcp close stream tcpSocket set numDel to number of items in deleted if numDel > 0 then tell application "Eudora2.1" repeat with i from 0 to numDel - 1 set mmsg to (a reference to message (item (numDel - i) of deleted) of mailbox "For Newton" of mail folder "") move mmsg to end of mailbox "Trash" of mail folder "" end repeat end tell end if set tcpSocket to (tcp wait for connect port 110 buffer size 10240) return 5end idle