home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 2 / AUCD2.iso / internet / acornet.spk / !Acornet / Apps / !POP / NB055trans / POP / sendmail (.txt) < prev   
RISC OS BBC BASIC V Source  |  1995-07-13  |  6KB  |  260 lines

  1.  >SendMail
  2.  takes a mail message file and copies to outgoing directory
  3.  ** Kludged for !POP mail transport
  4. " at line ";
  5. "OS_GetEnv" 
  6. ver$="0.55"
  7. cf$="":file$="":test%=
  8. getpar(A$," ")
  9. "-c":cf$=
  10. getpar(A$," ")
  11. "-test":test%=
  12.  A$=""
  13.  cf$=""
  14. exit(1,"No control file parameter")
  15. checkdirs
  16.  tmp%300,nbuf%4096
  17.  no fixed upper limit, let memory be the factor...
  18. tomax%=(
  19. -1000)
  20.  to$(tomax%)
  21. >gate$=
  22. varval("NewsBase$RemoteHost"):
  23.  gate$<5
  24.  gate$=""
  25.  ** Following changed from host name to mail name for !POP
  26. 3localhost$=
  27. lower(
  28. varval("NewsBase$MailName"))
  29.  now extract to/from info from control file...
  30. from$="":to$="":count%=0
  31. GC1%=
  32. openin(cf$):
  33.  C1%=0 
  34. exit(1,"Couldn't open control file "+cf$)
  35.   A$=
  36.   B$=
  37. getpar(A$,":")
  38. "S":from$=A$
  39. "D":file$=A$
  40. %6    
  41.  count%<tomax%
  42.  to$(count%)=A$:count%+=1
  43. cf(C1%)
  44.  from$=""
  45. exit(1,"Couldn't decode sender")
  46. from$,"@")<1
  47. localhost$>""
  48.  from$+="@"+localhost$
  49. file$=
  50. dir(cf$)+"."+file$
  51. objtype(file$)<>1
  52. exit(1,"Message file not found "+file$)
  53.  test%
  54. "ka9q sendmail "+ver$+" test output: "+file$
  55. "Maximum recipients = ";tomax%
  56. "From: "+from$
  57. "To: "+to$(0)
  58.  l%=1
  59. tomax%:
  60.  to$(l%)>""
  61. "    "+to$(l%)
  62. exit(0,"test run")
  63.  now make mqueue.work file...
  64.  three choices...
  65.  1) multiple recipients, smtp gateway defined; send as one file via gateway
  66.  2) single recipient, send direct
  67.  3) multiple recipients, no gateway; send separately directly.
  68.  count%>1
  69. gate$>""
  70.   seq%=
  71.   to$=to$(0)
  72. C5  test%=
  73. from$," "):
  74.  test%>1 from$=
  75. from$,test%)
  76. D2  o$="<POP$MailDir>.spool.mqueue.work."+
  77.  seq%
  78.   C%=
  79. openout(o$)
  80. F8    
  81.  C%=0 
  82. exit(1,"Couldn't open output work file")
  83. #C%,gate$
  84. #C%,from$
  85.  l%=0
  86. count%-1
  87. J$      
  88.  to$(l%)>""
  89. #C%,to$(l%)
  90. K        
  91. cf(C%):
  92. settype(o$,&FFF)
  93. M2  o$="<POP$MailDir>.spool.mqueue.text."+
  94.  seq%
  95. N.  F%=
  96. movefile(file$,o$):
  97. settype(o$,&FFF)
  98. exit(1,"Couldn't move to spool area")
  99.  l%=0
  100. count%-1
  101.     seq%=
  102.     to$=to$(l%)
  103.  to$>""
  104.       at%=
  105. to$,"@",1)+1
  106. V=      tosite$=
  107. to$,at%):
  108.  at%<1
  109. tosite$=""
  110.  tosite$=gate$
  111. WI      
  112.  tosite$=""
  113. exit(1,"Couldn't send; no destination or gateway")
  114. X9      test%=
  115. from$," "):
  116.  test%>1 from$=
  117. from$,test%)
  118. Y6      o$="<POP$MailDir>.spool.mqueue.work."+
  119.  seq%
  120.       C%=
  121. openout(o$)
  122. [<        
  123.  C%=0 
  124. exit(1,"Couldn't open output work file")
  125.         
  126. #C%,tosite$
  127.         
  128. #C%,from$
  129.         
  130. #C%,to$
  131. _%        
  132. cf(C%):
  133. settype(o$,&FFF)
  134. `6      o$="<POP$MailDir>.spool.mqueue.text."+
  135.  seq%
  136. a2      F%=
  137. copyfile(file$,o$):
  138. settype(o$,&FFF)
  139. b5      
  140. exit(1,"Couldn't move to spool area")
  141. c        
  142.   F%=
  143. delfile(file$)
  144.  finished, so remove source files
  145. "remove "+file$
  146. "remove "+cf$
  147. exit(0,"Mail sent")
  148. movefile(s$,d$)
  149. "XOS_FSControl",25,s$,d$
  150. "XOS_FSControl",26,s$,d$,(1<<7) 
  151. copyfile(s$,d$)
  152. "XOS_FSControl",26,s$,d$ 
  153. delfile(f$)
  154. "XOS_File",6,f$
  155. exit(n%,a$)
  156. ("set NewsBase$ReturnCode "+
  157. ("set NewsBase$ReturnInfo "+a$)
  158. checkdirs
  159. objtype("<POP$MailDir>")<2 
  160. exit(1,"!MailDir not found")
  161. ensuredir("<POP$MailDir>.spool")
  162. ensuredir("<POP$MailDir>.spool.mqueue")
  163. ensuredir("<POP$MailDir>.spool.mqueue.text")
  164. ensuredir("<POP$MailDir>.spool.mqueue.work")
  165. objtype("<POP$MailDir>.spool.mqueue.text")<2 
  166. objtype("<POP$MailDir>.spool.mqueue.work")<2 
  167. exit(1,"SMTP spool directories not created")
  168. ensuredir(f$)
  169. objtype(f$)
  170.  t%<2
  171. "XOS_File",8,f$
  172. sget(h%)
  173.  return line from file without error if too long...
  174.  a$,C%
  175.  C%<>10:C%=
  176.  a$<253
  177. C%<>10
  178. C%<>13:a$+=
  179. objtype(f$)
  180. "XOS_File",17,f$
  181. t%;F%
  182. settype(f$,t%)
  183. "XOS_File",18,f$,t%
  184.  h%<>0 
  185. "XOS_Find",0,h%:h%=0
  186. varval(A$)
  187.  L%,F%
  188. "XOS_ReadVarVal",A$,tmp%,256,0,3 
  189. ,,L%;F%
  190. L%>256 
  191. tmp%?L%=13:=$tmp%
  192. lower(A$)
  193.  B$,l%,c%,a%,z%,d%
  194. "A":z%=
  195. "Z":d%=
  196. "a"-a%
  197.  A$>0
  198.  l%=1
  199.   c%=
  200. A$,l%,1)
  201.  c%>=a%
  202. c%<=z%
  203.  c%+=d%
  204.   B$+=
  205.  read in sequence numer, and update
  206.  seq%,C%
  207. .seq$="<POP$MailDir>.spool.mqueue.sequence"
  208. objtype(seq$)=0 
  209.   seq%=1
  210. objtype("<POP$MailDir>.spool.mqueue.text."+
  211.  seq%)>0:seq%+=1:
  212. A  C%=
  213. openin(seq$):
  214.  C%=0 
  215. exit(1,"Can't open sequence file")
  216. "  seq%=
  217. #C%):
  218. cf(C%):seq%+=1
  219. openout(seq$):
  220.  seq%:
  221. cf(C%)
  222.     =seq%
  223. openin(f$)
  224.  h%,F%
  225. "XOS_Find",&4F,f$ 
  226. h%;F%:
  227. 1)<>0
  228.  h%=0
  229. openup(f$)
  230.  h%,F%
  231. "XOS_Find",&CF,f$
  232. h%;F%
  233. "XOS_Find",&8F,f$
  234. h%;F%:
  235. 1)<>0
  236.  h%=0
  237. openout(f$)
  238.  h%,F%
  239. "XOS_Find",&8F,f$
  240. h%;F%:
  241. 1)<>0
  242.  h%=0
  243. getpar(
  244.  A$,s$)
  245.  B$,l%
  246. A$,s$)
  247.  l%>0
  248.   B$=
  249. A$,l%-1):A$=
  250. A$,l%+1)
  251.   B$=A$:A$=""
  252. tmpfile
  253.  f$="<NewsBase$Data>.scratch.tmp"+
  254. (10000))
  255. objtype(f$)=0
  256. dir(f$)
  257.  l%-=1:
  258. f$,l%,1)="."
  259. f$,l%-1)
  260.