home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / windowsxp / ftgateoffice / ftgateoffice.exe / Main / attachments.fts < prev    next >
Encoding:
Text File  |  2001-11-29  |  4.5 KB  |  243 lines

  1. <%
  2. #include </utility/global.fts>
  3. #include </utility/ftgate.fts>
  4. #include </utility/theme.fts>
  5. #include </utility/mime.fts>
  6.  
  7. scripttimeout=6000
  8.  
  9. const unnamedFilename = "ftgwebmail.unnamed."
  10. var d=new server.domain
  11. var m
  12.  
  13. function outputembedded(id, filename)
  14. {
  15.     var folder=new m.folder
  16.     filename=number(filename)
  17.  
  18.     // lets look for some embedded stuff
  19.     //
  20.     if (filename)
  21.     {
  22.         var folder=new m.folder
  23.  
  24.         folder.message.selectid(id)
  25.         var msg = folder.message.open()
  26.  
  27.         var index=1
  28.         var loop=msg.mime.first()
  29.  
  30.         while (loop)
  31.         {
  32.             var s = msg.mime.contenttype
  33.             if ((msg.mime.contentdisposition!="attachment")&&(msg.mime.contentdisposition!="inline")&&(s.indexof("image",0)!=-1))
  34.             {
  35.                 if (index==filename)
  36.                 {
  37.                     // found it
  38.  
  39.                     output.contenttype=msg.mime.contenttype
  40.  
  41.                     msg.mime.next()
  42.  
  43.                     msg.mime.seekto()
  44.                     for (loop=0; loop<msg.mime.linecount; loop++)
  45.                     {
  46.                             msg.nexttext()
  47.                             output.writemime(msg.text)
  48.                     }
  49.  
  50.                     break;
  51.                 }
  52.                 else
  53.                     index++
  54.             }
  55.  
  56.             loop=msg.mime.next()
  57.         }
  58.  
  59.         if (!loop)
  60.         {
  61.             log.write(3, "Attachment not found")
  62.             output.write("Attachment not found")
  63.         }
  64.     }
  65. }
  66.  
  67. function outputimage(id, filename)
  68. {
  69.   var folder=new m.folder
  70.   var index
  71.   var s
  72.     var unnamed=1
  73.     var thisFile
  74.  
  75.     filename=string(filename)
  76.     filename=filename.replace(filename, "%20", " ")
  77.   folder.message.selectid(id)
  78.   var msg = folder.message.open()
  79.  
  80.   var loop=msg.mime.first()
  81.     var text=false
  82.     var html=false
  83.   while (loop)
  84.   {
  85.         if ((!html) && (msg.mime.contenttype=="text/html"))
  86.         {
  87.             html=true
  88.         }
  89.         else if ((!text) && (msg.mime.contenttype=="text/plain"))
  90.         {
  91.             text=true
  92.         }
  93.         else
  94.         {
  95.             if (msg.mime.filename)
  96.                 thisFile = msg.mime.filename
  97.             else if ((msg.mime.contentdisposition=="attachment")||(msg.mime.contentdisposition=="inline"))
  98.             {
  99.                 thisFile = unnamedFilename + unnamed
  100.                 unnamed++
  101.             }
  102.  
  103.             if (thisFile==filename)
  104.             {
  105.                 if (msie)
  106.                 {
  107.                     var agent = request.http_user_agent
  108.                     if (agent.indexof("MSIE 5.",0)==-1)
  109.                         output.protocoltype="1.0"
  110.                 }
  111.  
  112.                 var contenttype=string(msg.mime.contenttype)
  113.  
  114.                 if (contenttype.indexof("x-msdownload",0)!=-1)
  115.                     contenttype="application/octet-stream"
  116.                 else if (contenttype.indexof("message/delivery-status",0)!=-1)
  117.                     contenttype="text/plain"
  118.  
  119.                 var html = (contenttype.indexof("html",0)!=-1)
  120.                 var encoding
  121.                 if (msg.mime.contenttransferencoding=="quoted-printable")
  122.                 {
  123.                     if (contenttype=="application/octet-stream")
  124.                         contenttype="text/plain"
  125.  
  126.                     encoding=ENCODING_QUOTED
  127.                 }
  128.                 else if (msg.mime.contenttransferencoding=="base64")
  129.                     encoding=ENCODING_BASE64
  130.                 else 
  131.                     encoding=ENCODING_PLAIN
  132.  
  133.                 output.contenttype=contenttype
  134.  
  135.                 s = msg.mime.contenttransferencoding
  136.                 var base64 = (s.indexof("base64",0)!=-1)
  137.  
  138.                 msg.mime.next()
  139.                 msg.mime.seekto()
  140.  
  141.                 var wm=new server.webmail
  142.                 for (loop=0; loop<msg.mime.linecount;loop++)
  143.                 {
  144.                     msg.nexttext()
  145.                     
  146.                     if (base64)
  147.                     {
  148.                         output.writemime(msg.text)
  149.                     }
  150.                     else
  151.                     {
  152.                         writeline(msg.text,encoding,html,true)
  153.                     }
  154.                 }
  155.  
  156.                 break
  157.             }
  158.         }
  159.  
  160.       loop=msg.mime.next()
  161.   }
  162.  
  163.   if (!loop)
  164.     outputembedded(id, filename)
  165. }
  166.  
  167. function outputmime(s)
  168. {
  169.     var index
  170.     var domain
  171.     var mailbox
  172.     var id
  173.     var filename=""
  174.     var start=21
  175.  
  176.     s=string(s)
  177.     index=s.indexOf("/",start)
  178.     if (index<0)
  179.         output.write("Attachment not found.")
  180.     else
  181.     {
  182.         domain = s.slice(start,index)
  183.         start=index+1
  184.         index=s.indexOf("/",start)
  185.  
  186.         if (index<0)
  187.             output.write("Attachment not found.")
  188.         else
  189.         {
  190.             mailbox=s.slice(start,index)
  191.             start=index+1
  192.             index=s.indexOf("/",start)
  193.  
  194.             if (index<0)
  195.                 output.write("Attachment not found.")
  196.             else
  197.             {
  198.                 id=s.slice(start,index)
  199.                 filename=s.slice(index+1, s.length)
  200.  
  201.                 if (filename!="")
  202.           outputimage(id, filename)
  203.              }
  204.         }
  205.     }
  206. }
  207.  
  208. var ok=false
  209. d.domainname=session.webmail.domain
  210.  
  211. if ((d.domainname=="")||(d.domainname==null))
  212.     output.write("Invalid Domain")
  213. else
  214. {
  215.     m=new d.mailbox
  216.     m.name=session.webmail.mailbox
  217.     if ((m.name=="")||(m.name==null))
  218.         output.write("Invalid Mailbox")
  219.     else
  220.     {
  221.         //if (m.verifypassword(session.webmail.password))
  222.         //{
  223.         //  output.write("invalid password")
  224.         //}
  225.         //else
  226.         //{
  227.             ok=true
  228.     }
  229. }
  230.  
  231. if (ok)
  232. {
  233.     var s=Request.http_script_name
  234.  
  235.     if (s.slice(0,13)!="/attachments/")
  236.     {
  237.         output.write("Attachment not found")
  238.     }
  239.     else
  240.         outputmime(s)
  241. }
  242. %>
  243.