Search code examples
coldfusion

How to Open Email in a Folder on Chrome


There is a shared public folder that users use to upload shared documents. Among the shared resources, some users have uploaded outlook email shortcuts to share amongst themselves.

I am attempting to have this email to open in Outlook when user is trying to open the resource on chrome, IE, etc.

Is this achievable?

Here is an example of an email that is saved in the share folder:

Example of an email.

The following code is what I am currently doing to have users the ability to view folders on their browsers and open and save documents:

<!--- The following if statement checks if the url wants to be downloaded. If it does, it creates a downloadable link. --->
<cfif structKeyExists(URL, 'method') and URL.method eq 'download'>
    <cfset file_name = URL.name />
    <cfset path = URL.path />   
    
    <!--- The following if statements determine file type. ---> 
    <cfif findNoCase('.doc', file_name) or findNoCase('.odt', file_name) or findNoCase('.rtf', file_name) >
        <cfset file_type = 'application/msword' >
    <cfelseif findNoCase('.pdf', file_name) >
        <cfset file_type = 'application/pdf' >
    <cfelseif findNoCase('.xls', file_name) or findNoCase('.xlt', file_name) or findNoCase('.csv', file_name)>
        <cfset file_type = 'application/vnd.ms-excel' >
    <cfelseif findNoCase('.tif', file_name) >
        <cfset file_type = 'image' >
    <cfelseif findNoCase('.jpg', file_name) >
        <cfset file_type = 'image/jpeg' >
    <cfelseif findNoCase('.url', file_name) or findNoCase('.lnk', file_name) >
        <cfset file_type = 'text/uri-list' >    
    <cfelseif findNoCase('.msg', file_name) >
        <cfset file_type = 'text/uri-list' >
    </cfif>

    <!--- The following statements creates a downloadable link of the file. This is done by using cfheader and cfcontent --->   
    <cfheader name="Content-Disposition" value="inline; filename=#file_name#">
    <!---Check if file type is available. If available, show type. --->
    <cfif isDefined("file_type") >
        <cfcontent type="#file_type#" file="#path#\#file_name#">
    <!--- If file type is not found, display file anyways. --->
    <cfelse>
        <cfcontent file="#path#\#file_name#">
    </cfif>
    <cfabort>
</cfif>

Solution

  • This document describing the <cfcontent> tag states, "The following tag can force most browsers to display a dialog box that asks users whether they want to save the contents of the file specified by the cfcontent tag using the filename specified by the filename value. If the user selects to open the file, most browsers open the file in the related application, not the browser window.

    <cfheader name="Content-Disposition" value="attachment; filename=filename.ext">
    

    Some file types, such as PDF documents, do not use executable code and can display directly in most browsers. To request the browser to display the file directly, use a cfheader tag similar to the following:

    <cfheader name="Content-Disposition" value="inline; filename=name.ext">"
    

    The code in your question has this:

    <cfheader name="Content-Disposition" value="inline; filename=#file_name#">
    

    The key attribute is the value. You have "inline" which asks the browser to display the file directly. A value of "attachment" would allow the user to open the file with the default application for that type of file on their local machine.