1 //Written in the D programming language 2 /* 3 * MIME Content-Disposition header. 4 * 5 * Copyright: Copyright (C) 2013 Jaypha 6 * 7 * Distributed under the Boost Software License, Version 1.0. 8 * (See http://www.boost.org/LICENSE_1_0.txt) 9 * 10 * Authors: Jason den Dulk 11 */ 12 13 /* 14 * RFCs: 2183 15 */ 16 17 module jaypha.inet.mime.contentdisposition; 18 19 import jaypha.inet.mime.reading; 20 import jaypha.inet.imf.writing; 21 22 import std.array; 23 24 //----------------------------------------------------------------------------- 25 26 27 struct MimeContentDisposition 28 { 29 enum headerName = "Content-Disposition"; 30 31 string type = "inline"; 32 string[string] parameters; 33 } 34 35 //----------------------------------------------------------------------------- 36 // extracts the content of a Content-Disposition MIME header. 37 38 MimeContentDisposition extractMimeContentDisposition(string fieldBody) 39 { 40 MimeContentDisposition cd; 41 42 skipSpaceComment(fieldBody); 43 cd.type = extractToken(fieldBody); 44 skipSpaceComment(fieldBody); 45 extractMimeParams(fieldBody,cd.parameters); 46 return cd; 47 } 48 49 MimeHeader toMimeHeader(ref MimeContentDisposition contentDisp, bool asImf = false) 50 { 51 auto a = appender!string; 52 a.put(contentDisp.type); 53 foreach (i,v;contentDisp.parameters) 54 a.put("; "~i~"=\""~v~"\""); 55 56 if (asImf) 57 return unstructuredHeader(MimeContentDisposition.headerName,a.data); 58 else 59 return MimeHeader(MimeContentDisposition.headerName,a.data); 60 }