示例#1
0
utility::stream::size_type body::getGeneratedSize(const generationContext& ctx)
{
	// MIME-Multipart
	if (getPartCount() != 0)
	{
		utility::stream::size_type size = 0;

		// Size of parts and boundaries
		for (size_t p = 0 ; p < getPartCount() ; ++p)
		{
			size += 100;  // boundary, CRLF...
			size += getPartAt(p)->getGeneratedSize(ctx);
		}

		// Size of prolog/epilog text
		const text prologText = getActualPrologText(ctx);

		if (!prologText.isEmpty())
		{
			std::ostringstream oss;
			utility::outputStreamAdapter osa(oss);

			prologText.encodeAndFold(ctx, osa, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			size += oss.str().size();
		}

		const text epilogText = getActualEpilogText(ctx);

		if (!epilogText.isEmpty())
		{
			std::ostringstream oss;
			utility::outputStreamAdapter osa(oss);

			epilogText.encodeAndFold(ctx, osa, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			size += oss.str().size();
		}

		return size;
	}
	// Simple body
	else
	{
		ref <utility::encoder::encoder> srcEncoder = m_contents->getEncoding().getEncoder();
		ref <utility::encoder::encoder> dstEncoder = getEncoding().getEncoder();

		return dstEncoder->getEncodedSize(srcEncoder->getDecodedSize(m_contents->getLength()));
	}
}
示例#2
0
QString LHMail::getShowText(bool EMBEDDED, bool advancedLook)
{
	QString ret;

	if (!EMBEDDED)
	{
		ret+= "<HTML>\n";
	}

        if (advancedLook) {
	        ret+= "<h3>" + LHHtmlTools::full( subject() ) + "</h3>\n";
	        ret+= "From: " + LHMailAddr::convToHtmlMulti(from()) + "<br>\n";
	        ret+= "To: " + LHMailAddr::convToHtmlMulti(to()) + "<br>\n<p>\n";
        }

	if (isSinglePart())
	{
		if (/* advancedLook && */header().testData("Content-Type", "text/html"))
		{
			//QMimeSourceFactory::defaultFactory()->setText( "HTML_PART", messageBody() );
			//ret += "\n<br><A href=\"HTML_PART\">" + tr("HTML message") + "</A><br>\n";
			ret += "\n<br><A href=\"html://"+getAddress()+"\">" + tr("HTML message") + "</A><br>\n";
		}
		ret += LHHtmlTools::full(messageBody());
	}
	else
	{
		//ret+="<meta http-equiv=\"content-type\" content=\"text/html; charset=" + encoding() +"\" /> \n";
		uint pc = getPartCount();
		for (uint i=0; i<pc; i++)
		{
			LHMailBase* mp = getPart(i);
			ret+= mp->getShowText (false, advancedLook);
		}
	}
	if (!EMBEDDED)
	{
		ret+= "</HTML>\n";
	}
	
	return ret;
}
示例#3
0
QList<double> Skeleton::vectorization(int type) {
    QList<double> result;

    int count = getDim(type);
    int endCount = getEndCount(type);
    int junctionCount = getJunctionCount(type);
    int holeCount = getHoleCount(type);
    int massCenterCount = getMassCenterCount(type);
    int totalCount = getTotalCount(type);
    int partCount = getPartCount(type);

    int index = 0;

    for (int i = 0; i < count; i++){
        result.push_back(0.0001);
    }



    for (int i = 0; i < listLineEnds.size() && i < endCount; i++){
        result[index] = (listLineEnds[i].x);
        index++;

        result[index] = (listLineEnds[i].y);
        index++;
    }

    for (int i = 0; i < listJunctions.size() && i < junctionCount; i++){
        result[index] = (listJunctions[i].x);
        index++;

        result[index] = (listJunctions[i].y);
        index++;
    }

    for (int i = 0; i < listHoles.size() && i < holeCount; i++){
        result[index] = (listHoles[i].x);
        index++;

        result[index] = (listHoles[i].y);
        index++;
    }

    for (int i = 0; i < massCenterCount; i++){
        result[index] = (massCenter.x);
        index++;

        result[index] = (massCenter.y);
        index++;
    }



    for (int i = 0; i < totalCount; i++){
        result[index] = (total);
        index++;
    }

    for (int i = 0; i < partCount; i++){
        for (int x = 0; x < PART_X; x++){
            for (int y = 0; y < PART_Y; y++){
                result[index] = parts[x][y];
                index++;
            }
        }
    }

    return result;
}
示例#4
0
文件: body.cpp 项目: kreinloo/vmime
void body::generateImpl(utility::outputStream& os, const string::size_type maxLineLength,
                        const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
    // MIME-Multipart
    if (getPartCount() != 0)
    {
        string boundary;

        if (m_header.acquire() == NULL)
        {
            boundary = generateRandomBoundaryString();
        }
        else
        {
            try
            {
                ref <const contentTypeField> ctf =
                    m_header.acquire()->findField(fields::CONTENT_TYPE)
                    .dynamicCast <const contentTypeField>();

                boundary = ctf->getBoundary();
            }
            catch (exceptions::no_such_field&)
            {
                // Warning: no content-type and no boundary string specified!
                boundary = generateRandomBoundaryString();
            }
            catch (exceptions::no_such_parameter&)
            {
                // Warning: no boundary string specified!
                boundary = generateRandomBoundaryString();
            }
        }

        const string& prologText =
            m_prologText.empty()
            ? (isRootPart()
               ? options::getInstance()->multipart.getPrologText()
               : NULL_STRING
              )
            : m_prologText;

        const string& epilogText =
            m_epilogText.empty()
            ? (isRootPart()
               ? options::getInstance()->multipart.getEpilogText()
               : NULL_STRING
              )
            : m_epilogText;

        if (!prologText.empty())
        {
            text prolog(prologText, vmime::charset("us-ascii"));

            prolog.encodeAndFold(os, maxLineLength, 0,
                                 NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

            os << CRLF;
        }

        os << "--" << boundary;

        for (int p = 0 ; p < getPartCount() ; ++p)
        {
            os << CRLF;

            getPartAt(p)->generate(os, maxLineLength, 0);

            os << CRLF << "--" << boundary;
        }

        os << "--" << CRLF;

        if (!epilogText.empty())
        {
            text epilog(epilogText, vmime::charset("us-ascii"));

            epilog.encodeAndFold(os, maxLineLength, 0,
                                 NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

            os << CRLF;
        }

        if (newLinePos)
            *newLinePos = 0;
    }
    // Simple body
    else
    {
        // Generate the contents
        m_contents->generate(os, getEncoding(), maxLineLength);
    }
}
示例#5
0
LHMailBase* LHMail::attachSignature (LHMailSignature &signature)
{
        qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "12346789");

	LHMailPart* mp = new LHMailPart (this);

        if (getPartCount () > 1) {
                QString partsText = getSendData (DataToSign);
                QString newBoundary = LHMime::getBoundaryString ();
                QString oldBoundary = header ().getParameter ("Content-Type", "boundary");
                partsText.replace (oldBoundary, newBoundary);

#               if 1
                qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "***********************************************");
                qDebug()<<partsText;
                qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "***********************************************");
#               endif

                removePart (NULL);
		LHMailPart* mpb = new LHMailPart (this);
		addPart(mpb);

		mpb->header ().setData ("Content-Type", "Multipart/Mixed");
		mpb->header ().setParameter ("Content-Type", "boundary", newBoundary);
                mpb->setBodySendData (partsText);
		mpb->setEncoding (encoding());
                
        }

        /**
         *  Aply this LHMail object to the signature object. The body of mail
         *  is essntial when signing.
         */
         
	if (attachPart (mp))
	{

                // if (getPartCount () == 2 && body.isEmpty ())
                if (getPartCount () != 2) {
                        // qFatal ("*** %s,%d : %s", __FILE__, __LINE__, "!2");
                        return NULL;
                }

                QString body = getPart (0)->getSendData ();
        
                signature.setBody (body);
                signature.load ();

#               if 1
                qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "***********************************************");
                qDebug()<<body;
                qDebug ("*** %s,%d : %s", __FILE__, __LINE__, "***********************************************");
#               endif

		header ().setData ("Content-Type", "multipart/signed");
                header ().setParameter ("Content-Type", "micalg", "sha1");
                header ().setParameter ("Content-Type", "protocol", "application/x-pkcs7-signature");
                
	        mp->setSignature (signature.getData ());
                
		return mp;
	}
	
	//not here if success
	delete mp;
	return 0;
}
示例#6
0
void body::generateImpl
	(const generationContext& ctx, utility::outputStream& os,
	 const string::size_type /* curLinePos */, string::size_type* newLinePos) const
{
	// MIME-Multipart
	if (getPartCount() != 0)
	{
		string boundary;

		if (m_header.acquire() == NULL)
		{
			boundary = generateRandomBoundaryString();
		}
		else
		{
			try
			{
				ref <const contentTypeField> ctf =
					m_header.acquire()->findField(fields::CONTENT_TYPE)
						.dynamicCast <const contentTypeField>();

				boundary = ctf->getBoundary();
			}
			catch (exceptions::no_such_field&)
			{
				// Warning: no content-type and no boundary string specified!
				boundary = generateRandomBoundaryString();
			}
			catch (exceptions::no_such_parameter&)
			{
				// Warning: no boundary string specified!
				boundary = generateRandomBoundaryString();
			}
		}

		const text prologText = getActualPrologText(ctx);
		const text epilogText = getActualEpilogText(ctx);

		if (!prologText.isEmpty())
		{
			prologText.encodeAndFold(ctx, os, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			os << CRLF;
		}

		os << "--" << boundary;

		for (size_t p = 0 ; p < getPartCount() ; ++p)
		{
			os << CRLF;

			getPartAt(p)->generate(ctx, os, 0);

			os << CRLF << "--" << boundary;
		}

		os << "--" << CRLF;

		if (!epilogText.isEmpty())
		{
			epilogText.encodeAndFold(ctx, os, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			os << CRLF;
		}

		if (newLinePos)
			*newLinePos = 0;
	}
	// Simple body
	else
	{
		// Generate the contents
		ref <contentHandler> contents = m_contents->clone();
		contents->setContentTypeHint(getContentType());

		contents->generate(os, getEncoding(), ctx.getMaxLineLength());
	}
}
示例#7
0
/// Convert an EditTriMesh to a Model.  Note that this function may need
/// to make many logical changes to the mesh, such as number of actual
/// parts, ordering of vertices, materials, faces, etc.  Faces may need
/// to be detached across part boundaries.  Vertices may need to be duplicated
/// to place UV's at the vertex level.  However, the actual mesh geometry will
/// not be modified as far as number of faces, vertex positions,
/// vertex normals, etc.  The input mesh is not modified, except for possibly
/// the mark fields.
/// \param mesh Specifies the mesh to be converted.
void	Model::fromEditMesh(EditTriMesh &mesh) {
    int	i;

    // Free up anything already allocated

    freeMemory();

    // Make sure something exists in the destination mesh

    if (mesh.partCount() < 1) {
        return;
    }

    // Extract the part meshes

    EditTriMesh	*partMeshes = new EditTriMesh[mesh.partCount()];
    mesh.extractParts(partMeshes);

    // Figure out how many parts we'll need.  Remember,
    // each of our parts must have a single material,
    // so we must duplicate parts for multiple materials.

    int	numParts = 0;
    for (i = 0 ; i < mesh.partCount() ; ++i) {
        numParts += partMeshes[i].materialCount();
    }

    // Allocate

    allocateMemory(numParts);

    // Convert each part

    int	destPartIndex = 0;

    m_totalVertices = 0;
    m_totalTris = 0;

    for (i = 0 ; i < mesh.partCount() ; ++i) {
        EditTriMesh *srcMesh = &partMeshes[i];
        for (int j = 0 ; j < srcMesh->materialCount() ; ++j) {

            // Get a mesh consisting of the faces
            // in this part that use this material

            EditTriMesh	onePartOneMaterial;
            srcMesh->extractOnePartOneMaterial(0, j, &onePartOneMaterial);

            // Sanity check the output mesh

            assert(onePartOneMaterial.vertexCount() > 0);
            assert(onePartOneMaterial.triCount() > 0);
            assert(onePartOneMaterial.partCount() == 1);
            assert(onePartOneMaterial.materialCount() == 1);

            // Convert the mesh to a trimesh

            getPartMesh(destPartIndex)->fromEditMesh(onePartOneMaterial);

            // Convert the material

            setPartTextureName(destPartIndex, onePartOneMaterial.material(0).diffuseTextureName);

            m_totalVertices += onePartOneMaterial.vertexCount();
            m_totalTris += onePartOneMaterial.triCount();

            // !FIXME! Need to implement part names!

            // Next destination part, please

            ++destPartIndex;
        }
    }
    assert(destPartIndex == getPartCount());

    if(m_bufferUsage == StaticBuffers)
    {
        assert(m_vertexBuffer == NULL);
        assert(m_indexBuffer == NULL);

        int totalVc = 0;
        int totalTc = 0;
        for(i=0; i<m_partCount; i++)
        {
            totalVc += m_partMeshList[i].getVertexCount();
            totalTc += m_partMeshList[i].getTriCount();
        }

        m_vertexBuffer = new StandardVertexBuffer(totalVc);
        m_indexBuffer = new IndexBuffer(totalTc);

        int curVc = 0;
        int curTc = 0;

        m_vertexBuffer->lock();
        m_indexBuffer->lock();

        m_vertexOffsets.resize(m_partCount);
        m_indexOffsets.resize(m_partCount);

        for (i = 0 ; i < m_partCount ; ++i)
        {
            RenderVertex *srcV = m_partMeshList[i].getVertexList();
            RenderTri *srcT = m_partMeshList[i].getTriList();

            int vc = m_partMeshList[i].getVertexCount();
            int tc = m_partMeshList[i].getTriCount();

            for(int j=0; j<vc; j++)
            {
                (*m_vertexBuffer)[j+curVc].p = srcV[j].p;
                (*m_vertexBuffer)[j+curVc].n = srcV[j].n;
                (*m_vertexBuffer)[j+curVc].u = srcV[j].u;
                (*m_vertexBuffer)[j+curVc].v = srcV[j].v;
            }

            for(int j=0; j<tc; j++)
            {
                (*m_indexBuffer)[j+curTc].index[0] = srcT[j].index[0] + curVc;
                (*m_indexBuffer)[j+curTc].index[1] = srcT[j].index[1] + curVc;
                (*m_indexBuffer)[j+curTc].index[2] = srcT[j].index[2] + curVc;
            }

            m_vertexOffsets[i] = curVc;
            m_indexOffsets[i] = curTc;

            curVc += vc;
            curTc += tc;
        }

        m_vertexBuffer->unlock();
        m_indexBuffer->unlock();
    }
    else if(m_bufferUsage == StaticIndexBuffer)
    {
        assert(m_indexBuffer == NULL);

        m_indexBuffer = new IndexBuffer(m_totalTris);
    }


    // Free uindividual part meshes

    delete [] partMeshes;
}
示例#8
0
文件: body.cpp 项目: 8ackl0/vmime
void body::generateImpl
	(const generationContext& ctx, utility::outputStream& os,
	 const size_t /* curLinePos */, size_t* newLinePos) const
{
	// MIME-Multipart
	if (getPartCount() != 0)
	{
		string boundary;

		if (!m_part)
		{
			boundary = generateRandomBoundaryString();
		}
		else
		{
			// Use current boundary string, if specified. If no "Content-Type" field is
			// present, or the boundary is not specified, generate a random one
			shared_ptr <contentTypeField> ctf =
				m_part->getHeader()->findField <contentTypeField>(fields::CONTENT_TYPE);

			if (ctf)
			{
				if (ctf->hasBoundary())
				{
					boundary = ctf->getBoundary();
				}
				else
				{
					// No boundary string specified
					boundary = generateRandomBoundaryString();
				}
			}
			else
			{
				// No Content-Type (and no boundary string specified)
				boundary = generateRandomBoundaryString();
			}
		}

		const text prologText = getActualPrologText(ctx);
		const text epilogText = getActualEpilogText(ctx);

		if (!prologText.isEmpty())
		{
			prologText.encodeAndFold(ctx, os, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			os << CRLF;
		}

		os << "--" << boundary;

		for (size_t p = 0 ; p < getPartCount() ; ++p)
		{
			os << CRLF;

			getPartAt(p)->generate(ctx, os, 0);

			os << CRLF << "--" << boundary;
		}

		os << "--" << CRLF;

		if (!epilogText.isEmpty())
		{
			epilogText.encodeAndFold(ctx, os, 0,
				NULL, text::FORCE_NO_ENCODING | text::NO_NEW_LINE_SEQUENCE);

			os << CRLF;
		}

		if (newLinePos)
			*newLinePos = 0;
	}
	// Simple body
	else
	{
		// Generate the contents
		shared_ptr <contentHandler> contents = m_contents->clone();
		contents->setContentTypeHint(getContentType());

		contents->generate(os, getEncoding(), ctx.getMaxLineLength());
	}
}