Beispiel #1
0
   // set 'boundary' parameter (for multipart) of Content-Type field
   void MimeHeader::SetBoundary(const char* pszBoundary/*=NULL*/)
   {
      static int s_nPartNumber = 0;
      char buf[80];
      if (!pszBoundary)				// generate a new boundary delimeter
      {
         ::srand(((unsigned)::time(NULL)) ^ (unsigned)this);
         ::sprintf(buf, "__=_Part_Boundary_%03d_%06d.%06d", ++s_nPartNumber, rand(), rand());
         if (s_nPartNumber >= 9)
            s_nPartNumber = 0;
         pszBoundary = buf;
      }

      MimeField *pfd = GetField(CMimeConst::ContentType());
      if (!pfd)
      {
         MimeField fd;
         fd.SetName(CMimeConst::ContentType());
         fd.SetValue("multipart/mixed");
         fd.SetParameter(CMimeConst::Boundary(), pszBoundary);
         m_listFields.push_back(fd);
      }
      else
      {
         if (::_memicmp(pfd->GetValue(), "multipart", 9) != 0)
            pfd->SetValue("multipart/mixed");
         pfd->SetParameter(CMimeConst::Boundary(), pszBoundary);
      }
   }
Beispiel #2
0
 // set the 'charset' parameter (for text) of Content-Type field
 void MimeHeader::SetCharset(const char* pszCharset)
 {
    MimeField *pfd = GetField(CMimeConst::ContentType());
    if (!pfd)
    {
       MimeField fd;
       fd.SetName(CMimeConst::ContentType());
       fd.SetValue("text/plain");
       fd.SetParameter(CMimeConst::Charset(), pszCharset);
       m_listFields.push_back(fd);
    }
    else
       pfd->SetParameter(CMimeConst::Charset(), pszCharset);
 }
Beispiel #3
0
   // set the 'name' parameter (for attachment) of Content-Type field
   void MimeHeader::SetName(const char* pszName)
   {
      MimeField *pfd = GetField(CMimeConst::ContentType());
      if (!pfd)
      {
         // get the appropriate media-type/subtype according to file extension
         ASSERT(pszName != NULL);
         string strType;
         const char* pszType = "application/octet-stream";
         const char* pszFileExt = ::strrchr(pszName, '.');
         if (pszFileExt != NULL)
         {
            pszFileExt++;
            int nIndex = 0;
            while (m_TypeCvtTable[nIndex].nMediaType != MEDIA_UNKNOWN)
            {
               if (!::_stricmp(pszFileExt, m_TypeCvtTable[nIndex].pszFileExt))
               {
                  strType = m_TypeTable[m_TypeCvtTable[nIndex].nMediaType];
                  strType += '/';
                  strType += m_TypeCvtTable[nIndex].pszSubType;
                  pszType = strType.c_str();
                  break;
               }
               nIndex++;
            }
         }

         MimeField fd;
         fd.SetName(CMimeConst::ContentType());
         fd.SetValue(pszType);
         fd.SetParameter(CMimeConst::Name(), pszName);
         m_listFields.push_back(fd);
      }
      else
         pfd->SetParameter(CMimeConst::Name(), pszName);
   }