Ejemplo n.º 1
0
void MailMessage::makeMultipart()
{
	if (!isMultipart())
	{
		MediaType mediaType("multipart", "mixed");
		setContentType(mediaType);	
	}
}
Ejemplo n.º 2
0
const MimeBodyPart* HttpBody::getMultipart(int index) const
{
    const MimeBodyPart* bodyPart = NULL;

    if(index >= 0 && isMultipart())
    {
        bodyPart = dynamic_cast<MimeBodyPart*>(mBodyParts.at(index));
    }
    return(bodyPart);
}
Ejemplo n.º 3
0
void MailMessage::read(std::istream& istr, PartHandler& handler)
{
	readHeader(istr);
	if (isMultipart())
	{
		readMultipart(istr, handler);
	}
	else
	{
		StringPartHandler handler(_content);
		readPart(istr, *this, handler);
	}
}
Ejemplo n.º 4
0
/*!
    Returns the set of OR'd flags that are true
    for the file engine's file, and that are in the \a type's OR'd
    members.
*/
QAbstractFileEngine::FileFlags BSciDrmFileEngine::fileFlags( FileFlags type ) const
{
    FileFlags flags = QFSFileEngine::fileFlags( type );

    if( type & DirectoryType && isMultipart() )
    {
        flags |= DirectoryType;
        flags &= ~FileType;
    }

    if( type & LinkType && isLink() )
        flags |= LinkType;

    return flags;
}
Ejemplo n.º 5
0
void MailMessage::write(std::ostream& ostr) const
{
	MessageHeader header(*this);
	setRecipientHeaders(header);
	if (isMultipart())
	{
		writeMultipart(header, ostr);
	}
	else
	{
		writeHeader(header, ostr);
		std::istringstream istr(_content);
		writeEncoded(istr, ostr, _encoding);
	}
}
Ejemplo n.º 6
0
/*!
    Requests that a list of all the files matching the \a filters
    list based on the \a filterNames in the file engine's directory
    are returned.

    Returns an empty list if the file engine refers to a file
    rather than a directory, or if the directory is unreadable or does
    not exist or if nothing matches the specifications.
*/
QStringList BSciDrmFileEngine::entryList( QDir::Filters filters, const QStringList &filterNames ) const
{
    QStringList entries = QFSFileEngine::entryList( filters, filterNames );

    if( filters & QDir::Files && isMultipart() )
    {
        QStringList locations = contentIds();

        foreach( QString filter, filterNames )
            locations = locations.filter( QRegExp( filter, Qt::CaseSensitive, QRegExp::Wildcard ) );

        entries += locations;
    }

    return entries;
}
Ejemplo n.º 7
0
// Constructor
HttpBody::HttpBody(const char* bytes, ssize_t length, const char* contentType) :
   bodyLength(0),
   mBodyPartCount(0)
{
   if (contentType)
   {
      append(contentType);
      NameValueTokenizer::frontBackTrim(this, " \t");
      //osPrintf("Content type: \"%s\"\n", mBodyContentType.data());
      ssize_t boundaryIndex = index(MULTIPART_BOUNDARY_PARAMETER,
                                0, UtlString::ignoreCase);

      if(boundaryIndex >=0 &&
         index(CONTENT_TYPE_MULTIPART,
               0, UtlString::ignoreCase) == 0)
      {
         boundaryIndex += strlen(MULTIPART_BOUNDARY_PARAMETER);
         //osPrintf("Boundary start:=>%s\n",
         //    (mBodyContentType.data())[boundaryIndex]);

         // Allow white space before =
         ssize_t fieldLength = this->length();
         while(boundaryIndex < fieldLength &&
               (data()[boundaryIndex] == ' ' ||
                data()[boundaryIndex] == '\t'))
            boundaryIndex++;

         if(data()[boundaryIndex] == '=')
         {
            mMultipartBoundary.append(&data()[boundaryIndex + 1]);
            NameValueTokenizer::frontTrim(&mMultipartBoundary, " \t");
            ssize_t whiteSpaceIndex = mMultipartBoundary.first(' ');
            if(whiteSpaceIndex > 0) mMultipartBoundary.remove(whiteSpaceIndex);
            whiteSpaceIndex = mMultipartBoundary.first('\t');
            if(whiteSpaceIndex > 0) mMultipartBoundary.remove(whiteSpaceIndex);
            //osPrintf("HttpBody: boundary=\"%s\"\n", mMultipartBoundary.data());
	    mMultipartBoundary.strip(both, '"');
         }
      }
   }

   if(bytes && length < 0) length = strlen(bytes);
   if(bytes && length > 0)
   {
      if (mBody.append(bytes, length).length() > 0) //append was successful
      {
         bodyLength = length;

         if(isMultipart())
         {
            for(unsigned int partIndex = 0;; partIndex++)
            {
               UtlString contentType;
               UtlString name;
               UtlString value;
               const char* partBytes;
               const char* parentBodyBytes;
               ssize_t partLength;
               ssize_t parentBodyLength;
               getBytes(&parentBodyBytes, &parentBodyLength);
               getMultipartBytes(partIndex, &partBytes, &partLength);
               //osPrintf("Body part 1 length: %d\n", firstPart.length());
               //osPrintf("++++ Multipart Body #1 ++++\n%s\n++++ End Multipart #1 ++++\n",
               //    firstPart.data());
               if(partLength <= 0) break;

               // Parse throught the header to the MIME part
               // The first blank line is the begining of the part body
               NameValueTokenizer parser(partBytes, partLength);
                 do
                 {
                     parser.getNextPair(HTTP_NAME_VALUE_DELIMITER,
                     &name, & value);
                     name.toUpper();
                     if(name.compareTo(HTTP_CONTENT_TYPE_FIELD) == 0)
                     {
                         contentType = value;
                     }
                 }
                 while(!name.isNull());

               // This is a bit of a temporary kludge
               //Prepend a HTTP header to make it look like a HTTP message
               //partBytes.insert(0, "GET / HTTP/1.0\n");
               //HttpMessage firstPartMessage(partBytes.data(), partBytes.length());
               //const HttpBody* partFileBody = firstPartMessage.getBody();
               //ssize_t bytesLeft = parser.getProcessedIndex() - partLength;

               if (partLength > 0)
               {
                  mBodyParts.append(new MimeBodyPart(this, partBytes, partBytes - parentBodyBytes,
                                                            partLength,contentType.data()));
                  // Save the number of body parts.
                  mBodyPartCount = partIndex + 1;
               }
            }
         }
      }
   }
}
Ejemplo n.º 8
0
// Append a multipart body part to an existing multiparty body.
void HttpBody::appendBodyPart(const HttpBody& body,
                              const UtlDList& parameters)
{
   assert(isMultipart());

   // Construct a new MimeBodyPart for the new body part.
   MimeBodyPart* part = new MimeBodyPart(body, parameters);

   // Insert it as the last body part.
   mBodyParts.append(part);
   mBodyPartCount++;

   // Turn the final boundary into an intermediate boundary.
   mBody.remove(mBody.length() - 4);
   mBody.append("\r\n");

   // Insert the headers.
   ssize_t rawPartStart = mBody.length();
   UtlDListIterator iterator(*part->getParameters());
   NameValuePair* nvp;
   while ((nvp = (NameValuePair*) iterator()))
   {
      mBody.append(nvp->data());
      mBody.append(": ");
      mBody.append(nvp->getValue());
      mBody.append("\r\n");
   }
   mBody.append("\r\n");

   // Insert the body.
   ssize_t partStart = mBody.length();
   const char* bytes;
   ssize_t length;
   body.getBytes(&bytes, &length);
   mBody.append(bytes, length);
   ssize_t partEnd = mBody.length();

   // Update bodyLength.
   bodyLength = mBody.length();

   // Determine if we have to change the boundary string.
   bool change_boundary_string =
      mBody.index(mMultipartBoundary, partStart) != UTL_NOT_FOUND;

   // Add the final boundary.
   mBody.append("\r\n--");
   mBody.append(mMultipartBoundary);
   mBody.append("--\r\n");

   // Update the MimeBodyPart to know where it is contained in the HttpBody.
   part->attach(this,
                rawPartStart, partEnd - rawPartStart,
                partStart, partEnd - partStart);

   // If we have to change the boundary string.
   if (change_boundary_string)
   {
      // Find a new boundary string that isn't in the body.
      do {
         nextBoundary(mMultipartBoundary);
      } while (mBody.index(mMultipartBoundary) != UTL_NOT_FOUND);

      // Replace the old boundary string.
      UtlSListIterator iterator(mBodyParts);
      MimeBodyPart* part;
      while ((part = dynamic_cast<MimeBodyPart*>(iterator())))
      {
            // Replace the boundary string just before this part.
            mBody.replace(part->getRawStart() - (2 + BOUNDARY_STRING_LENGTH),
                          BOUNDARY_STRING_LENGTH,
                          mMultipartBoundary.data(),
                          BOUNDARY_STRING_LENGTH);
      }

      // Replace the boundary string in the final boundary.
      mBody.replace(mBody.length() - (4 + BOUNDARY_STRING_LENGTH),
                    BOUNDARY_STRING_LENGTH,
                    mMultipartBoundary.data(),
                    BOUNDARY_STRING_LENGTH);

      // Replace the boundary string in the Content-Type.
      ssize_t loc = this->index(";" MULTIPART_BOUNDARY_PARAMETER "=\"");
      this->replace(loc + sizeof (";" MULTIPART_BOUNDARY_PARAMETER "=\"") - 1,
                    BOUNDARY_STRING_LENGTH,
                    mMultipartBoundary.data(),
                    BOUNDARY_STRING_LENGTH);
   }
}