sequence eMail_adres
sequence briefje
sequence subject
sequence file_path={}
integer i
include readf.e
include makemail.e
subject=command_line()
if match("peu",lower(subject[1])) then i=4 else i=3 end if
if length(subject)!=i
then puts(1,"Using mailbr begeleidendschrijven_file eMails_file\n") abort(1)
else briefje=subject[length(subject)-1]
eMail_adres=subject[length(subject)]
end if
integer brief_file=open(briefje,"r")
sequence brief,line,aansluitnummer,org_naam,mails
brief=readf(brief_file,',')
if length(brief)<1
then puts(1,"Error in briefhoofd , ( geen onderwerp gegeven )\n") abort(1)
else subject=brief[1]
if length(brief)>1 then file_path=brief[2..] end if
end if
brief={}
line=gets(brief_file)
while sequence(line) do
brief&=line
line=gets(brief_file)
end while
close(brief_file)
brief_file=open(eMail_adres,"r")
line=readf(brief_file,',')
while sequence(line) do
if length(line)>=3 then
org_naam=line[2]
mails={}
i=find(';',line[3])
while i do
if find('@',line[3][1..i-1])
then mails=append(mails,line[3][1..i-1])
end if
line[3]=line[3][i+1..]
i=find(';',line[3])
end while
if find('@',line[3])
then mails=append(mails,line[3])
end if
if length(mails)
then puts(1,"send to: "&line[3]&'\n')
i=find('$',brief)
line=brief[1..i-1]&org_naam&brief[i+1..]
if length(file_path)
then i=sendfile(mails,subject,line,file_path)
else i=sendmail(mails,subject,line)
end if
if i then printf(1,"Error = %d at eMail = %s\n",{i,mails[1]}) abort(1) end if
end if
end if
line=readf(brief_file,',')
end while
close(brief_file)