home *** CD-ROM | disk | FTP | other *** search
- <%
- #include </utility/global.fts>
- #include </utility/ftgate.fts>
- #include </utility/theme.fts>
- #include </utility/mime.fts>
-
- scripttimeout=6000
-
- const unnamedFilename = "ftgwebmail.unnamed."
- var d=new server.domain
- var m
-
- function outputembedded(id, filename)
- {
- var folder=new m.folder
- filename=number(filename)
-
- // lets look for some embedded stuff
- //
- if (filename)
- {
- var folder=new m.folder
-
- folder.message.selectid(id)
- var msg = folder.message.open()
-
- var index=1
- var loop=msg.mime.first()
-
- while (loop)
- {
- var s = msg.mime.contenttype
- if ((msg.mime.contentdisposition!="attachment")&&(msg.mime.contentdisposition!="inline")&&(s.indexof("image",0)!=-1))
- {
- if (index==filename)
- {
- // found it
-
- output.contenttype=msg.mime.contenttype
-
- msg.mime.next()
-
- msg.mime.seekto()
- for (loop=0; loop<msg.mime.linecount; loop++)
- {
- msg.nexttext()
- output.writemime(msg.text)
- }
-
- break;
- }
- else
- index++
- }
-
- loop=msg.mime.next()
- }
-
- if (!loop)
- {
- log.write(3, "Attachment not found")
- output.write("Attachment not found")
- }
- }
- }
-
- function outputimage(id, filename)
- {
- var folder=new m.folder
- var index
- var s
- var unnamed=1
- var thisFile
-
- filename=string(filename)
- filename=filename.replace(filename, "%20", " ")
- folder.message.selectid(id)
- var msg = folder.message.open()
-
- var loop=msg.mime.first()
- var text=false
- var html=false
- while (loop)
- {
- if ((!html) && (msg.mime.contenttype=="text/html"))
- {
- html=true
- }
- else if ((!text) && (msg.mime.contenttype=="text/plain"))
- {
- text=true
- }
- else
- {
- if (msg.mime.filename)
- thisFile = msg.mime.filename
- else if ((msg.mime.contentdisposition=="attachment")||(msg.mime.contentdisposition=="inline"))
- {
- thisFile = unnamedFilename + unnamed
- unnamed++
- }
-
- if (thisFile==filename)
- {
- if (msie)
- {
- var agent = request.http_user_agent
- if (agent.indexof("MSIE 5.",0)==-1)
- output.protocoltype="1.0"
- }
-
- var contenttype=string(msg.mime.contenttype)
-
- if (contenttype.indexof("x-msdownload",0)!=-1)
- contenttype="application/octet-stream"
- else if (contenttype.indexof("message/delivery-status",0)!=-1)
- contenttype="text/plain"
-
- var html = (contenttype.indexof("html",0)!=-1)
- var encoding
- if (msg.mime.contenttransferencoding=="quoted-printable")
- {
- if (contenttype=="application/octet-stream")
- contenttype="text/plain"
-
- encoding=ENCODING_QUOTED
- }
- else if (msg.mime.contenttransferencoding=="base64")
- encoding=ENCODING_BASE64
- else
- encoding=ENCODING_PLAIN
-
- output.contenttype=contenttype
-
- s = msg.mime.contenttransferencoding
- var base64 = (s.indexof("base64",0)!=-1)
-
- msg.mime.next()
- msg.mime.seekto()
-
- var wm=new server.webmail
- for (loop=0; loop<msg.mime.linecount;loop++)
- {
- msg.nexttext()
-
- if (base64)
- {
- output.writemime(msg.text)
- }
- else
- {
- writeline(msg.text,encoding,html,true)
- }
- }
-
- break
- }
- }
-
- loop=msg.mime.next()
- }
-
- if (!loop)
- outputembedded(id, filename)
- }
-
- function outputmime(s)
- {
- var index
- var domain
- var mailbox
- var id
- var filename=""
- var start=21
-
- s=string(s)
- index=s.indexOf("/",start)
- if (index<0)
- output.write("Attachment not found.")
- else
- {
- domain = s.slice(start,index)
- start=index+1
- index=s.indexOf("/",start)
-
- if (index<0)
- output.write("Attachment not found.")
- else
- {
- mailbox=s.slice(start,index)
- start=index+1
- index=s.indexOf("/",start)
-
- if (index<0)
- output.write("Attachment not found.")
- else
- {
- id=s.slice(start,index)
- filename=s.slice(index+1, s.length)
-
- if (filename!="")
- outputimage(id, filename)
- }
- }
- }
- }
-
- var ok=false
- d.domainname=session.webmail.domain
-
- if ((d.domainname=="")||(d.domainname==null))
- output.write("Invalid Domain")
- else
- {
- m=new d.mailbox
- m.name=session.webmail.mailbox
- if ((m.name=="")||(m.name==null))
- output.write("Invalid Mailbox")
- else
- {
- //if (m.verifypassword(session.webmail.password))
- //{
- // output.write("invalid password")
- //}
- //else
- //{
- ok=true
- }
- }
-
- if (ok)
- {
- var s=Request.http_script_name
-
- if (s.slice(0,13)!="/attachments/")
- {
- output.write("Attachment not found")
- }
- else
- outputmime(s)
- }
- %>
-