home *** CD-ROM | disk | FTP | other *** search
/ Internet Magazine 2002 August / INTERNET94.ISO / pc / software / windows / mail / ft_gate_office / ftgateoffice105.exe / Main / mime.fts < prev    next >
Encoding:
Text File  |  2002-03-08  |  2.6 KB  |  150 lines

  1. <%
  2. const ENCODING_PLAIN = 0
  3. const ENCODING_QUOTED = 1
  4. const ENCODING_BASE64 = 2
  5.  
  6. function isDigit(char)
  7. {
  8.   var i=number(char)
  9.  
  10.   if ((i>0)||(char=="0"))
  11.     return true
  12.   else
  13.     return false
  14. }
  15.  
  16. var wlStr=""
  17. function writeline(line, encoding, html, raw)
  18. {
  19.     var wm = new server.webmail
  20.   line = string(line)
  21.     wlStr=wlStr+line.slice(0, line.length-1)
  22.  
  23.     if ((wlStr.length>=2)&&(encoding==ENCODING_QUOTED))
  24.     {
  25.         // is last character '='
  26.         if ((wlStr.slice(wlStr.length-1, wlStr.length)!="=")&&(wlStr.slice(wlStr.length-2, wlStr.length)!="= "))
  27.         {
  28.             var index=wlStr.length-1
  29.  
  30.             var char=wlStr.slice(index, index+1)
  31.             while ((index>=0)&&(isDigit(char))&&(char!="="))
  32.             {
  33.                 index=index-1
  34.                 if (index>=0)
  35.                     char=wlStr.slice(index, index+1)
  36.             }
  37.  
  38.             if (char=="=")
  39.                 wlStr=wlStr.slice(0, index)
  40.  
  41. //            if (html)
  42. //                wlStr=wm.escape(wlStr)
  43.  
  44.             wlStr=wm.decode(1, wlStr)
  45.  
  46.             output.write(wlStr+"\r\n")
  47.             wlStr=""
  48.         }
  49.         else
  50.         {
  51.             if (wlStr.slice(wlStr.length-1, wlStr.length)=="=")
  52.                 wlStr=wlStr.slice(0, wlStr.length-1)
  53.             else
  54.                 wlStr=wlStr.slice(0, wlStr.length-2)
  55.         }
  56.     }
  57.     else
  58.     {
  59.         if (encoding==ENCODING_BASE64)
  60.             wlStr=wlStr.base64decode()
  61.  
  62.         wlStr=wm.decode(1, wlStr)
  63.  
  64. //        if (html)
  65. //            wlStr=wm.escape(wlStr)
  66.  
  67.         if (encoding==ENCODING_BASE64)
  68.             output.write(wlStr)
  69.         else
  70.             output.write(wlStr+"\r\n")
  71.  
  72.         wlStr=""
  73.     }
  74. }
  75.  
  76. function writeflush(encoding)
  77. {
  78.     if (wlStr!="")
  79.     {
  80.         if (encoding==ENCODING_BASE64)
  81.             output.write(wlStr)
  82.         else
  83.             output.write(wlStr+"\r\n")
  84.     }
  85. }
  86.  
  87. function writemimetext(msg, encoding)
  88. {
  89.     msg.nexttext()
  90.  
  91.     var str=""
  92.  
  93.     var wm=new server.webmail
  94.  
  95.     var i
  96.     for (i=0; i< msg.mime.linecount; i++)
  97.     {
  98.         var line=msg.text
  99.  
  100.         str=str+line.slice(0, line.length-1)
  101.         if ((str.length>=2)&&(encoding==ENCODING_QUOTED))
  102.         {
  103.             // is last character '='
  104.             if (str.slice(str.length-1, str.length)!="=")
  105.             {
  106.                 var index=str.length-1
  107.  
  108.                 var char=str.slice(index, index+1)
  109.                 while ((index>=0)&&(isDigit(char))&&(char!="="))
  110.                 {
  111.                     index=index-1
  112.                     if (index>=0)
  113.                         char=str.slice(index, index+1)
  114.                 }
  115.  
  116.                 if (char=="=")
  117.                     str=str.slice(0, index)
  118.  
  119.                 str=wm.escape(str)+"<BR>"
  120.                 str=wm.decode(1, str)
  121.                 output.write(str+"\r\n")
  122.                 str=""
  123.             }
  124.             else
  125.             {
  126.                 str=str.slice(0, str.length-1)
  127.             }
  128.         }
  129.         else
  130.         {
  131.             if (encoding==ENCODING_BASE64)
  132.                 str=str.base64decode()
  133.  
  134.             str=wm.escape(str)
  135.  
  136.             if (encoding==ENCODING_BASE64)
  137.             {
  138.                 str=str.replace(str, "\r", "<BR>")
  139.                 output.write(str)
  140.             }
  141.             else
  142.                 output.writeln(str+"<BR>")
  143.  
  144.             str=""
  145.         }
  146.  
  147.         msg.nexttext()
  148.     }
  149. }
  150. %>