Ejemplo n.º 1
0
		//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;
			}
		}
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        public MimeField GetField(string pszFieldName)
        {
            MimeField aMimeField = FindField(pszFieldName);

            return(aMimeField != null?aMimeField:null);
        }
Ejemplo n.º 4
0
        public string GetFieldCharset(string pszFieldName)
        {
            MimeField aMimeField = GetField(pszFieldName);

            return(aMimeField != null?aMimeField.GetCharset() : null);
        }
Ejemplo n.º 5
0
        public string GetParameter(string pszFieldName, string pszAttr)
        {
            MimeField aMimeField = GetField(pszFieldName);

            return(aMimeField != null?aMimeField.GetParameter(pszAttr) : null);
        }
Ejemplo n.º 6
0
        public string GetFieldValue(string pszFieldName)
        {
            MimeField aMimeField = GetField(pszFieldName);

            return(aMimeField != null?aMimeField.GetValue() : null);
        }
Ejemplo n.º 7
0
		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);
			}
		}
Ejemplo n.º 8
0
		// 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);
			}
		}
Ejemplo n.º 9
0
		// 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+"\"");
			}
		}
Ejemplo n.º 10
0
		// 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+"\"");
			}
		}