示例#1
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);
            }
        }
示例#2
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 + "\"");
            }
        }
示例#3
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 + "\"");
            }
        }
示例#4
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);
            }
        }
示例#5
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);
			}
		}
示例#6
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);
			}
		}
示例#7
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+"\"");
			}
		}
示例#8
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+"\"");
			}
		}