;中国 COLD FUSION 用户组; WWW.CFWINDOW.COM 
您的位置 :首页 >> CF 技巧文章 >> 阅读文章内容 [ 关闭窗口 ]      

技巧文章内容 
    如何用cfloop作出带有多个附件的邮件(英文).
文章作者 : linkfoxo [ fengjf@novasprint.com ]          Web URL : http://www.cfwindow.com
上载日期 : 2000-12-14

原文作者是: Dain Anderson (danderson@cftipsplus.com)

Cycle through multiple attachments from CFPOP:

A while back a fellow co-worker of mine asked me a question:
How do I loop through multiple file attachments return from
CFPOP? He said visually there was a space between each
attachment name, but using CFLOOP with a space as a delimiter
didn't work. At that point I hadn't written an email client of
my own, so I was in unfamiliar territory.

The first thing I did was copy that character (control-c) and
pasted it into the following code:

    <CFOUTPUT>
        #ASC("  ")#
    </CFOUTPUT>

...where the " " (space) was between the double quotes.

Then I opened the page in a browser and the character "9"
appeared - this tells us what ASCII character that "space"
represented. In this case, it was a TAB character. The reason
he was tricked by this is because a web browser does not
distinguish any visual difference between a space character
and a TAB character - they look the same in a browser.

So, to loop through the CFPOP attachments, you could use
something like this:

(This example uses the FuseBox methodology, and some items
were cut out, but hopefully you get the point)

act_getMessage.cfm and dsp_showMessage.cfm:

<CFPOP
    SERVER="#Request.POP3_SERVER#"
    PORT="#Request.POP3_PORT#"
    USERNAME="#Request.POP3_UN#"
    PASSWORD="#Request.POP3_PW#"
    TIMEOUT="#Request.POP3_TIMEOUT#"
    MESSAGENUMBER="#Attributes.messagenumber#"
    ACTION="GetAll"
    NAME="ReadMessage"
    GENERATEUNIQUEFILENAMES="Yes"
    ATTACHMENTPATH="#ExpandPath('.')#\attachments\">

<CFSET Count = ListLen(ReadMessage.attachments, "#CHR(9)#")>

<CFIF Len(ReadMessage.attachments)>

    This message contains #Count# attachment
    <CFIF Count NEQ 1>s</CFIF>:<P>

    <CFLOOP FROM="1" TO="#ListLen(ReadMessage.Attachments,
                                   chr(9))#" INDEX="i">

       <A HREF="index.cfm?fuseaction=getMailFile
                &file=#URLEncodedFormat(GetFileFromPath
                (ListGetAt(ReadMessage.attachmentfiles,
      i, chr(9))))#
                &name=#URLEncodedFormat(ListGetAt
                (ReadMessage.attachments, i, chr(9)))#">
                #ListGetAt(ReadMessage.attachments, i, chr(9))#
       </A><BR>
    </CFLOOP>

</CFIF>

(The lines forming the link above were chopped for readability)

Unlike queries, you cannot subindex file attachments as a
one-dimensional array.

Hopefully you noticed the "file" and "name" URL variables here
-- since we're using GENERATEUNIQUEFILENAMES="Yes",
we don't want the user's file to appear to be renamed by
ColdFusion. The "file" variable represents what ColdFusion
renamed the file to in order that duplicate files aren't
overwritten, and the "name" variable represents the original
file name. So, to fake the user into getting the original
filename when clicking on the attachment link, we use CFCONTENT
in the act_getMailFile.cfm page:

act_getMailFile.cfm:

<CFHEADER NAME="Content-Disposition" VALUE=";
filename=#URLDecode(attributes.name)#;">
<CFCONTENT
TYPE="application/unknown"
FILE="#ExpandPath('.')#\attachments\#URLDecode
                     (attributes.file)#" DELETEFILE="No">

This will get the renamed file and fake the browser into
thinking it's called something else (the real file name). If
you're not using FuseBox, the "attributes." scope would be
changed to the URL scope, "URL.". This example was tested in
CF 4.5.1 SP1 on Windows2000 Professional. On Windows 98, there
appear to be issues when looping through file attachments, so
this didn't work on Windows 98 (at least not on the system I
tested it on).








< 联系我们 --- 中国Cold Fusion用户组>

CFUG 国内(总部):Linkfoxo    上海:CFANS    北京:Cafe,Cyberkid,liwater    沈阳:Wangking
  
哈尔滨:Baiming    浙江:梅盛松    江西:陈末
  
CFUG (国际) Nagoya(名古屋):Codeguru    新加坡:YUZI    新西兰(Auckland):Richard CHEN
Copyright 2000-2001 www.cfwindow.com.All rights reserved

;中国 COLD FUSION 用户组; WWW.CFWINDOW.COM