home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 2
/
AUCD2.iso
/
internet
/
pop098.spk
/
!POP
/
NB054trans
/
POP
/
sendmail
(
.txt
)
< prev
next >
Wrap
RISC OS BBC BASIC V Source
|
1995-06-25
|
8KB
|
437 lines
>SendMail
takes a mail message file and copies to outgoing directory
*** Version for !POP/SMTP mail transport
*** Identical to G.A's ka9q "sendmail" except I've brought
the mail spool directory out to the front and changed it.
- Daniel Pead
Hspooldir$="<POP$MailDir>.spool":
Set the mail spool directory here
" at line ";
"OS_GetEnv"
ver$="0.52"
N$="":nolocal%=
:test%=
getpar(A$," ")
"-f":N$=
getpar(A$," ")
"-nolocal":nolocal%=
"-test":test%=
A$=""
N$=""
exit(1,"No file parameter")
checkdirs
tmp%300,nbuf%4096
no fixed upper limit, let memory be the factor...
tomax%=(
-1000)
to$(tomax%)
>gate$=
varval("NewsBase$RemoteHost"):
gate$<5
gate$=""
$local$=
varval("NewsBase$Local")
nolocal%
local$=""
!3localhost$=
lower(
varval("NewsBase$HostName"))
now extract to/from info...
$Bfrom$="":to$="":bcc$="":count%=0:into%=
:sender$="":errors$=""
%9C1%=
openin(N$):
C1%=0
exit(1,"Couldn't open file")
A$=
sget(C1%)
A$,6)="From: "
temp$=
A$,7):from$=
getaddress(temp$)
A$,8)="Sender: "
temp$=
A$,9):sender$=
getaddress(temp$)
A$,12)="Errors-To: "
temp$=
A$,9):errors$=
getaddress(temp$)
A$,5)="Bcc: "
bcc$=
A$,7):
note if Bcc: exists
fake continuation lines by faking extra "To:" lines...
A$,1)<>" "
into%=
A$,1)=" "
into%<>0
A$="To:"+A$
A$,4)="To: "
A$,4)="Cc: "
A$,5)="Bcc: "
0+ l%=
A$," "):to$=
A$,l%+1):into%=
temp$=
getaddress(to$)
2=
temp$>""
count%<tomax%
to$(count%)=temp$:count%+=1
to$=""
count%=tomax%
A$=""
cf(C1%)
override envelope return path with errors-to or sender header if present...
errors$>""
from$=errors$
sender$>""
from$=sender$
now take care of some error conditions...
to$(0)=""
exit(1,"No recipients found")
from$=""
exit(1,"Couldn't decode sender")
bcc$>""
removebcc(N$)
test%
"ka9q sendmail "+ver$+" test output: "+N$
"Maximum recipients = ";tomax%
"From: "+from$
"To: "+to$(0)
l%=1
tomax%:
to$(l%)>""
" "+to$(l%)
exit(0,"test run")
now first handle any local mail, saving to <NewsBase$Local>
local$>""
l%=0
count%-1
to$=to$(l%):tosite$=""
to$>""
at%=
to$,"@")
R<
at%>0
tosite$=
lower(
to$,at%+1)):to$=
to$,at%-1)
S(
tosite$=""
tosite$=localhost$
T-
localsave(N$,to$)<>0
to$(l%)=""
U
now make mqueue.work file...
three choices...
1) multiple recipients, smtp gateway defined; send as one file via gateway
2) single recipient, send direct
3) multiple recipients, no gateway; send separately directly.
count%>1
gate$>""
seq%=
to$=to$(0)
c5 test%=
from$," "):
test%>1 from$=
from$,test%)
d) o$=spooldir$+".mqueue.work."+
seq%
C%=
openout(o$)
f8
C%=0
exit(1,"Couldn't open output work file")
#C%,gate$
#C%,from$
l%=0
count%-1
j$
to$(l%)>""
#C%,to$(l%)
k
cf(C%):
settype(o$,&FFF)
m) o$=spooldir$+".mqueue.text."+
seq%
n+ F%=
movefile(N$,o$):
settype(o$,&FFF)
exit(1,"Couldn't move to spool area")
l%=0
count%-1
seq%=
to$=to$(l%)
to$>""
at%=
to$,"@",1)+1
v= tosite$=
to$,at%):
at%<1
tosite$=""
tosite$=gate$
wI
tosite$=""
exit(1,"Couldn't send; no destination or gateway")
x9 test%=
from$," "):
test%>1 from$=
from$,test%)
y- o$=spooldir$+".mqueue.work."+
seq%
C%=
openout(o$)
{<
C%=0
exit(1,"Couldn't open output work file")
#C%,tosite$
#C%,from$
#C%,to$
%
cf(C%):
settype(o$,&FFF)
- o$=spooldir$+".mqueue.text."+
seq%
/ F%=
copyfile(N$,o$):
settype(o$,&FFF)
5
exit(1,"Couldn't move to spool area")
F%=
delfile(N$)
finished, so remove source file
"remove "+N$
exit(0,"Mail sent")
movefile(s$,d$)
"XOS_FSControl",25,s$,d$
"XOS_FSControl",26,s$,d$,(1<<7)
copyfile(s$,d$)
"XOS_FSControl",26,s$,d$
delfile(f$)
"XOS_File",6,f$
exit(n%,a$)
("set NewsBase$ReturnCode "+
("set NewsBase$ReturnInfo "+a$)
checkdirs
objtype(spooldir$)<2
exit(1,spooldir$+" not found")
ensuredir(spooldir$)
ensuredir(spooldir$+".mqueue")
ensuredir(spooldir$+".mqueue.text")
ensuredir(spooldir$+".mqueue.work")
objtype(spooldir$+".mqueue.text")<2
objtype(spooldir$+".mqueue.work")<2
exit(1,"SMTP spool directories not created")
ensuredir(f$)
objtype(f$)
t%<2
"XOS_File",8,f$
sget(h%)
return line from file without error if too long...
a$,C%
C%<>10:C%=
a$<253
C%<>10
C%<>13:a$+=
objtype(f$)
"XOS_File",17,f$
t%;F%
settype(f$,t%)
"XOS_File",18,f$,t%
h%<>0
"XOS_Find",0,h%:h%=0
varval(A$)
L%,F%
"XOS_ReadVarVal",A$,tmp%,256,0,3
,,L%;F%
L%>256
tmp%?L%=13:=$tmp%
lower(A$)
B$,l%,c%,a%,z%,d%
"A":z%=
"Z":d%=
"a"-a%
A$>0
l%=1
c%=
A$,l%,1)
c%>=a%
c%<=z%
c%+=d%
B$+=
getaddress(
B$,C$,at%,end%,brack%
B$="":at%=0:end%=0
l%=0:
end%=0
l%+=1:C$=
A$,l%,1)
B$>""
end%=1
*
"(":brack%=1:
l%+=1:C$=
A$,l%,1)
C$="\"
l%+=1
C$="("
brack%+=1
C$=")"
brack%-=1
brack%<1
"\":l%+=1
$ B$="":
l%+=1:C$=
A$,l%,1)
+
C$="\"
l%+=1:
C$<>">"B$+=C$
C$=">"
!
at%>0
B$,at%,1)="%"
B$+=C$:at%=
skip
)
"""":B$+=C$:
l%+=1:C$=
A$,l%,1)
,
C$="\"
l%+=1:
C$<>""""B$+=C$
-
C$=""""
C$=""""
B$+=C$
:B$+=C$
A$,l%+1)
read in sequence numer, and update
seq%,C%
%seq$=spooldir$+".mqueue.sequence"
objtype(seq$)=0
seq%=1
objtype(spooldir$+".mqueue.text."+
seq%)>0:seq%+=1:
A C%=
openin(seq$):
C%=0
exit(1,"Can't open sequence file")
" seq%=
#C%):
cf(C%):seq%+=1
openout(seq$):
seq%:
cf(C%)
=seq%
removebcc(d$)
f$,a$,r3%:f$=
tmpfile
openin(d$)
f1%>0
f2%=
openout(f$)
f2%>0
inbcc%=
sget(f1%)
!
A$,1)<>" "
inbcc%=
#
A$,4)="Bcc:"
inbcc%=
inbcc%=
#f2%,A$
A$=""
r3%=0
7
r3%=0:
"XOS_GBPB",4,f1%,nbuf%,4096
,,,r3%
9
r3%<4096
"XOS_GBPB",2,f2%,nbuf%,4096-r3%
"
cf(f2%):
settype(f$,&FFF)
6
exit(1,"Couldn't open temp file for mailing")
cf(f1%):F%=
delfile(d$)
localsave(f$,to$)
o$,r3%,ok%
ok%=0:o$=local$+"."+to$
openin(f$)
f1%>0
f2%=
openup(o$)
f2%>0
#f2%=
#f2%,"From "+
r3%=0
&7
r3%=0:
"XOS_GBPB",4,f1%,nbuf%,4096
,,,r3%
'9
r3%<4096
"XOS_GBPB",2,f2%,nbuf%,4096-r3%
)
#f2%,""
+(
cf(f2%):
settype(o$,&FFF):ok%=
cf(f1%)
openin(f$)
h%,F%
"XOS_Find",&4F,f$
h%;F%:
1)<>0
h%=0
openup(f$)
h%,F%
"XOS_Find",&CF,f$
h%;F%
"XOS_Find",&8F,f$
h%;F%:
1)<>0
h%=0
openout(f$)
h%,F%
"XOS_Find",&8F,f$
h%;F%:
1)<>0
h%=0
getpar(
A$,s$)
B$,l%
A$,s$)
l%>0
B$=
A$,l%-1):A$=
A$,l%+1)
B$=A$:A$=""
tmpfile
f$="<NewsBase$Data>.scratch.tmp"+
(10000))
objtype(f$)=0