//load a head content from a string buffer public void LoadHead(string strData) { if(strData == null) throw new ArgumentNullException(); string field=""; string line; StringReader sr = new StringReader(strData); try { line = sr.ReadLine(); field = line + "\r\n"; while(! string.IsNullOrEmpty(line)) { line = sr.ReadLine(); if(! string.IsNullOrEmpty(line) && (line[0] == ' ' || line[0] == '\t')) { field += line + "\r\n"; } else { MimeField aMimeField = new MimeField(); aMimeField.LoadField(field); m_listFields.Add(aMimeField); field = line + "\r\n"; } } } finally { sr.Close(); sr = null; } }
public void SetFieldValue(string pszFieldName, string pszFieldValue, string pszFieldCharset) { MimeField aMimeField = GetField(pszFieldName); if (aMimeField != null) { aMimeField.SetValue(pszFieldValue); if (pszFieldCharset != null) { aMimeField.SetCharset(pszFieldCharset); } } else { aMimeField = new MimeField(); aMimeField.SetName(pszFieldName); aMimeField.SetValue(pszFieldValue); if (pszFieldCharset != null) { aMimeField.SetCharset(pszFieldCharset); } m_listFields.Add(aMimeField); } }
public MimeField GetField(string pszFieldName) { MimeField aMimeField = FindField(pszFieldName); return(aMimeField != null?aMimeField:null); }
public string GetFieldCharset(string pszFieldName) { MimeField aMimeField = GetField(pszFieldName); return(aMimeField != null?aMimeField.GetCharset() : null); }
public string GetParameter(string pszFieldName, string pszAttr) { MimeField aMimeField = GetField(pszFieldName); return(aMimeField != null?aMimeField.GetParameter(pszAttr) : null); }
public string GetFieldValue(string pszFieldName) { MimeField aMimeField = GetField(pszFieldName); return(aMimeField != null?aMimeField.GetValue() : null); }
public void SetFieldValue(string pszFieldName, string pszFieldValue, string pszFieldCharset) { MimeField aMimeField = GetField(pszFieldName); if(aMimeField != null) { aMimeField.SetValue(pszFieldValue); if(pszFieldCharset != null) aMimeField.SetCharset(pszFieldCharset); } else { aMimeField = new MimeField(); aMimeField.SetName(pszFieldName); aMimeField.SetValue(pszFieldValue); if(pszFieldCharset != null) aMimeField.SetCharset(pszFieldCharset); m_listFields.Add(aMimeField); } }
// Content-Type: multipart/...; boundary=... public void SetBoundary(string pszBoundary) { if(pszBoundary == null) { Random randObj = new Random((int)DateTime.Now.Ticks); pszBoundary = "__=_Part_Boundary_"+randObj.Next().ToString()+"_"+randObj.Next().ToString(); } MimeField aMimeField = GetField(MimeConst.ContentType); if(aMimeField != null) { if(aMimeField.GetValue().IndexOf("multipart", 0, 9) == -1) aMimeField.SetValue("multipart/mixed"); aMimeField.SetParameter(MimeConst.Boundary, "\""+pszBoundary+"\""); } else { aMimeField = new MimeField(); aMimeField.SetName(MimeConst.ContentType); aMimeField.SetValue("multipart/mixed"); aMimeField.SetParameter(MimeConst.Boundary, "\""+pszBoundary+"\""); m_listFields.Add(aMimeField); } }
// Content-Type: image/...; name=... public void SetName(string pszName) { MimeField aMimeField = GetField(MimeConst.ContentType); if(aMimeField == null) { aMimeField = new MimeField(); int lastindex = pszName.LastIndexOf('.'); string strType = "application/octet-stream"; string ext = pszName.Substring(lastindex + 1, pszName.Length - lastindex - 1); int nIndex = 0; while(MimeType.TypeCvtTable[nIndex].nMediaType != MimeType.MediaType.MEDIA_UNKNOWN) { if(MimeType.TypeCvtTable[nIndex].pszFileExt == ext) { strType = MimeType.TypeTable[(int)MimeType.TypeCvtTable[nIndex].nMediaType]; strType += '/'; strType += MimeType.TypeCvtTable[nIndex].pszSubType; break; } nIndex++; } aMimeField.SetName(MimeConst.ContentType); aMimeField.SetValue(strType); aMimeField.SetParameter(MimeConst.Name, "\""+pszName+"\""); m_listFields.Add(aMimeField); } else { aMimeField.SetParameter(MimeConst.Name, "\""+pszName+"\""); } }
// Content-Type: text/...; charset=... public void SetCharset(string pszCharset) { MimeField aMimeField = GetField(MimeConst.ContentType); if(aMimeField == null) { aMimeField = new MimeField(); aMimeField.SetName(MimeConst.ContentType); aMimeField.SetValue("text/plain"); aMimeField.SetParameter(MimeConst.Charset, "\""+pszCharset+"\""); m_listFields.Add(aMimeField); } else { aMimeField.SetParameter(MimeConst.Charset, "\""+pszCharset+"\""); } }