Example #1
0
void CopyToHeader(char *srcstart,char *srcend,char **dest,int mode)
{
	char *dst;

	if(dest==NULL)
		return;
	if(srcstart>=srcend)
		return;

	if((mode==MIME_MAIL) && (((*srcstart=='"') && (*(srcend-1)=='"')) || ((*srcstart=='<') && (*(srcend-1)=='>'))))
	{
		srcstart++;
		srcend--;
	}

	if(srcstart>=srcend)
		return;

	if(NULL!=*dest)
		delete[] *dest;
	if(NULL==(*dest=new char[srcend-srcstart+1]))
		return;

	dst=*dest;

	for(;srcstart<srcend;dst++,srcstart++)
	{
		if(ENDLINE(srcstart))
		{
			while(ENDLINE(srcstart) || WS(srcstart)) srcstart++;
			*dst=' ';
			srcstart--;		//because at the end of "for loop" we increment srcstart
		}
		else
			*dst=*srcstart;
	}
	*dst=0;
}
Example #2
0
void ExtractAddressFromLine(char *finder,char **storeto,char **storetonick)
{
	if(finder==NULL)
	{
		*storeto=*storetonick=NULL;
		return;
	}
	while(WS(finder)) finder++;
	if((*finder)!='<')
	{
		char *finderend=finder+1;
		do
		{
			if(ENDLINEWS(finderend))						//after endline information continues
				finderend+=2;
			while(!ENDLINE(finderend) && !EOS(finderend)) finderend++;		//seek to the end of line or to the end of string
		}while(ENDLINEWS(finderend));
		finderend--;
		while(WS(finderend) || ENDLINE(finderend)) finderend--;				//find the end of text, no whitespace
		if(*finderend!='>')						//not '>' at the end of line
			CopyToHeader(finder,finderend+1,storeto,MIME_MAIL);
		else								//at the end of line, there's '>'
		{
			char *finder2=finderend;
			while((*finder2!='<') && (finder2>finder)) finder2--;		//go to matching '<' or to the start
			CopyToHeader(finder2,finderend+1,storeto,MIME_MAIL);
			if(*finder2=='<')						//if we found '<', the rest copy as from nick
			{
				finder2--;
				while(WS(finder2) || ENDLINE(finder2)) finder2--;		//parse whitespace
				CopyToHeader(finder,finder2+1,storetonick,MIME_MAIL);		//and store nickname
			}
		}
	}
	else
	{
		char *finderend=finder+1;
		do
		{
			if(ENDLINEWS(finderend))							//after endline information continues
				finderend+=2;
			while(!ENDLINE(finderend) && (*finderend!='>') && !EOS(finderend)) finderend++;		//seek to the matching < or to the end of line or to the end of string
		}while(ENDLINEWS(finderend));
		CopyToHeader(finder,finderend+1,storeto,MIME_MAIL);				//go to first '>' or to the end and copy
		finder=finderend+1;
		while(WS(finder)) finder++;								//parse whitespace
		if(!ENDLINE(finder) && !EOS(finder))					//if there are chars yet, it's nick
		{
			finderend=finder+1;
			while(!ENDLINE(finderend) && !EOS(finderend)) finderend++;	//seek to the end of line or to the end of string
			finderend--;
			while(WS(finderend)) finderend--;				//find the end of line, no whitespace
			CopyToHeader(finder,finderend+1,storetonick,MIME_MAIL);
		}
	}
}
Example #3
0
void ExtractStringFromLine(char *finder,char **storeto)
{
	if(finder==NULL)
	{
		*storeto=NULL;
		return;
	}
	while(WS(finder)) finder++;
	char *finderend=finder;

	do
	{
		if(ENDLINEWS(finderend)) finderend++;						//after endline information continues
		while(!ENDLINE(finderend) && !EOS(finderend)) finderend++;
	}while(ENDLINEWS(finderend));
	finderend--;
	while(WS(finderend)) finderend--;				//find the end of line, no whitespace
	CopyToHeader(finder,finderend+1,storeto,MIME_PLAIN);
}
Example #4
0
char *ExtractFromContentType(char *ContentType,char *value)
{
	char *lowered = _strdup(ContentType);
	ToLower(lowered);
	char *finder=strstr(lowered,value);
	if(finder==NULL){
		free (lowered);
		return NULL;
	}
	finder = finder-lowered+ContentType;
	free (lowered);

	char *temp,*copier;
	char *CopiedString;

	temp=finder-1;
	while((temp>ContentType) && WS(temp)) temp--;			//now we have to find, if the word "Charset=" is located after ';' like "; Charset="
	if(*temp!=';' && !ENDLINE(temp) && temp!=ContentType)
		return NULL;
	finder=finder+strlen(value);						//jump over value string

	while(WS(finder)) finder++;					//jump over whitespaces
	temp=finder;
	while(*temp!=0 && *temp!=';') temp++;				//jump to the end of setting (to the next ;)
	temp--;
	while(WS(temp))	temp--;						//remove whitespaces from the end
	if (*finder=='\"'){ //remove heading and tailing quotes
		finder++;
		if (*temp=='\"') temp--;
	}
	if(NULL==(CopiedString=new char[++temp-finder+1]))
		return NULL;
	for(copier=CopiedString;finder!=temp;*copier++=*finder++);			//copy string
	*copier=0;						//and end it with zero character

	return CopiedString;
}
Example #5
0
void WINAPI TranslateHeaderFcn(char *stream,int len,struct CMimeItem **head)
{
	try
	{
		char *finder=stream;
		char *prev1,*prev2,*prev3;
		struct CMimeItem *Item=NULL;

		while(finder<=(stream+len))
		{
			while(ENDLINEWS(finder)) finder++;

			//at the start of line
			if (DOTLINE(finder+1))					//at the end of stream
				break;

			prev1=finder;

			while(*finder != ':' && !EOS(finder)) finder++;
			if (!EOS(finder))
				prev2=finder++;
			else
				break;

			while(WS(finder) && !EOS(finder)) finder++;
			if (!EOS(finder))
				prev3=finder;
			else
				break;

			do
			{
				if (ENDLINEWS(finder)) finder+=2;						//after endline information continues
				while(!ENDLINE(finder) && !EOS(finder)) finder++;
			}while(ENDLINEWS(finder));

			if (Item != NULL)
			{
				if (NULL==(Item->Next=new struct CMimeItem))
					break;
				Item=Item->Next;
			}
			else
			{
				Item = new CMimeItem;
				*head = Item;
			}

			Item->Next=NULL;
			Item->name=new char [prev2-prev1+1];
			lstrcpynA(Item->name,prev1,prev2-prev1+1);
			Item->value=new char [finder-prev3+1];
			lstrcpynA(Item->value,prev3,finder-prev3+1);

			if (EOS(finder))
				break;
			finder++;
			if (ENDLINE(finder)) {
				finder++;
				if (ENDLINE(finder)) {
					// end of headers. message body begins
					finder++;
					if (ENDLINE(finder))finder++;
					prev1 = finder;
					while (!DOTLINE(finder+1))finder++;
					if (ENDLINE(finder))finder--;
					prev2 = finder;
					if (prev2>prev1) { // yes, we have body
						if (NULL==(Item->Next=new struct CMimeItem))	break; // Cant create new item?!
						Item=Item->Next;
						Item->Next=NULL;//just in case;
						Item->name=new char[5]; strncpy(Item->name,"Body",5);
						Item->value=new char [prev2-prev1];
						lstrcpynA(Item->value,prev1,prev2-prev1-1);
					}
					break; // there is nothing else
				}
			}
		}
	}
	catch(...)
	{
		MessageBoxA(NULL,"Translate header error","",0);
	}
}
Example #6
0
WCHAR *ParseMultipartBody(char *src, char *bond)
{
	char *srcback = _strdup(src);
	size_t sizebond = strlen(bond);
	int numparts = 1;
	int i;
	char *courbond = srcback;
	WCHAR *dest;
	for (;(courbond=strstr(courbond,bond));numparts++,courbond+=sizebond);
	APartDataType *partData = new APartDataType[numparts];
	memset(partData, 0, sizeof(APartDataType)*numparts);
	partData[0].Src = courbond = srcback;
	for (i=1;(courbond=strstr(courbond,bond));i++,courbond+=sizebond){
		*(courbond-2) = 0;
		partData[i].Src = courbond+sizebond;
		while (ENDLINE(partData[i].Src)) partData[i].Src++;
	}
	size_t resultSize=0;
	for (i=0;i<numparts;i++){
		ParseAPart(&partData[i]);
		if (partData[i].body){
			if (partData[i].TransEnc){
				if (!_stricmp(partData[i].TransEnc,"base64")) partData[i].TransEncType=TE_BASE64;
				else if (!_stricmp(partData[i].TransEnc,"quoted-printable"))partData[i].TransEncType=TE_QUOTEDPRINTABLE;
			}
			if (partData[i].ContType){
				char *CharSetStr;
				if(NULL!=(CharSetStr=ExtractFromContentType(partData[i].ContType,"charset=")))
				{
					partData[i].CodePage=GetCharsetFromString(CharSetStr,strlen(CharSetStr));
					delete[] CharSetStr;
				}
			}
			if (partData[i].ContType && !_strnicmp(partData[i].ContType,"text",4)) {
				char *localBody=0;
				switch (partData[i].TransEncType){
					case TE_BASE64:
					{
						int size =partData[i].bodyLen*3/4+5;
						localBody = new char[size+1];
						DecodeBase64(partData[i].body,localBody,size); 
					}break;
					case TE_QUOTEDPRINTABLE:
					{
						int size = partData[i].bodyLen+2;
						localBody = new char[size+1];
						DecodeQuotedPrintable(partData[i].body,localBody,size,FALSE); 
					}break;
				}
				ConvertStringToUnicode(localBody?localBody:partData[i].body,partData[i].CodePage,&partData[i].wBody);
				if (localBody) delete[] localBody;
			} else if(partData[i].ContType && !_strnicmp(partData[i].ContType,"multipart/",10)){
				//Multipart in mulitipart recursive? should be SPAM. Ah well
				char *bondary=NULL;
				if(NULL!=(bondary=ExtractFromContentType(partData[i].ContType,"boundary=")))
				{
					partData[i].wBody = ParseMultipartBody(partData[i].body,bondary);
					delete[] bondary;
				} else goto FailBackRaw; //multipart with no boundary? badly formatted messages.
			} else {
FailBackRaw:
				ConvertStringToUnicode(partData[i].body,partData[i].CodePage,&partData[i].wBody);
			}
			resultSize += wcslen(partData[i].wBody);
		}// if (partData[i].body)
		resultSize += 100+4+3; //cr+nl+100+ 3*bullet
	}
	dest = new WCHAR[resultSize+1];
	size_t destpos = 0;
	for (i=0;i<numparts;i++){
		if (i){ // part before first boudary should not have headers
			char infoline[104]; size_t linesize = 0;
			_snprintf(infoline,100,"%s %d",Translate("Part"),i);
			linesize = strlen(infoline);
			if (partData[i].TransEnc){
				_snprintf(infoline+linesize,100-linesize,"; %s",partData[i].TransEnc);
				linesize = strlen(infoline);
			}
			if (partData[i].ContType){
				char *CharSetStr=strchr(partData[i].ContType,';');
				if (CharSetStr){
					CharSetStr[0]=0;
					_snprintf(infoline+linesize,100-linesize,"; %s",partData[i].ContType);
					linesize = strlen(infoline);
					partData[i].ContType=CharSetStr+1;
					if(NULL!=(CharSetStr=ExtractFromContentType(partData[i].ContType,"charset=")))
					{
						_snprintf(infoline+linesize,100-linesize,"; %s",CharSetStr);
						linesize = strlen(infoline);
						delete[] CharSetStr;
					}
					if(NULL!=(CharSetStr=ExtractFromContentType(partData[i].ContType,"name=")))
					{
						_snprintf(infoline+linesize,100-linesize,"; \"%s\"",CharSetStr);
						linesize = strlen(infoline);
						delete[] CharSetStr;
					}
				} else {
					_snprintf(infoline+linesize,100-linesize,"; %s",partData[i].ContType);
					linesize = strlen(infoline);
				}
			}
			sprintf(infoline+linesize,".\r\n");
			{WCHAR *temp=0;
				dest[destpos] = dest[destpos+1] = dest[destpos+2] = 0x2022; // bullet;
				destpos+=3;
				ConvertStringToUnicode(infoline,CP_ACP,&temp);
				size_t wsize = wcslen(temp);
				wcscpy(&dest[destpos],temp);
				destpos += wsize;
				delete[] temp;
			}
		} // if (i)
		if (partData[i].wBody){
			size_t wsize = wcslen(partData[i].wBody);
			wcscpy(&dest[destpos],partData[i].wBody);
			destpos += wsize;
			delete[] partData[i].wBody;
		}
	}

	free (srcback);
	delete[] partData;
	dest[resultSize] = 0;//just in case
	return dest;
}
Example #7
0
void ParseAPart(APartDataType *data)
{
	size_t len = strlen(data->Src);
	try
	{
		char *finder=data->Src;
		char *prev1,*prev2,*prev3;

		while(finder<=(data->Src+len))
		{
			while(ENDLINEWS(finder)) finder++;

			//at the start of line
			if (finder>data->Src){
				if (*(finder-2)=='\r' || *(finder-2)=='\n') 
					*(finder-2)=0;
				if (*(finder-1)=='\r' || *(finder-1)=='\n') 
					*(finder-1)=0;
			}
			prev1=finder;

			while(*finder!=':' && !EOS(finder) && !ENDLINE(finder)) finder++;
			if (ENDLINE(finder)||EOS(finder)){
				// no ":" in the line? here the body begins;
				data->body = prev1;
				break;
			}
			prev2=finder++;

			while(WS(finder) && !EOS(finder)) finder++;
			if(!EOS(finder))
				prev3=finder;
			else
				break;

			do
			{
				if(ENDLINEWS(finder)) finder+=2;						//after endline information continues
				while(!ENDLINE(finder) && !EOS(finder)) finder++;
			}while(ENDLINEWS(finder));

			if (!_strnicmp(prev1,"Content-type",prev2-prev1)){
				data->ContType = prev3;
			} else if (!_strnicmp(prev1,"Content-Transfer-Encoding",prev2-prev1)){
				data->TransEnc = prev3;
			}

			if(EOS(finder))
				break;
			finder++;
			if(ENDLINE(finder)) {
				finder++;
				if(ENDLINE(finder)) {
					// end of headers. message body begins
					if (finder>data->Src){
						if (*(finder-2)=='\r' || *(finder-2)=='\n') 
							*(finder-2)=0;
						if (*(finder-1)=='\r' || *(finder-1)=='\n') 
							*(finder-1)=0;
					}
					finder++;
					if(ENDLINE(finder))finder++;
					prev1 = finder;
					while (!EOS(finder+1))finder++;
					if (ENDLINE(finder))finder--;
					prev2 = finder;
					if (prev2>prev1){ // yes, we have body
						data->body = prev1;
					}
					break; // there is nothing else
				}
			}
		}
	}
	catch(...)
	{
		MessageBox(NULL,_T("Translate header error"),_T(""),0);
	}
	if (data->body) data->bodyLen = (int)strlen(data->body);
}
Example #8
0
BOOL
FASTCALL
IntEngGradientFillTriangle(
    IN SURFOBJ  *psoDest,
    IN CLIPOBJ  *pco,
    IN XLATEOBJ  *pxlo,
    IN TRIVERTEX  *pVertex,
    IN ULONG  nVertex,
    IN PGRADIENT_TRIANGLE gTriangle,
    IN RECTL  *prclExtents,
    IN POINTL  *pptlDitherOrg)
{
    SURFOBJ *psoOutput;
    PTRIVERTEX v1, v2, v3;
    RECT_ENUM RectEnum;
    BOOL EnumMore;
    ULONG i;
    POINTL Translate;
    INTENG_ENTER_LEAVE EnterLeave;
    RECTL FillRect = { 0, 0, 0, 0 };
    ULONG Color;

    BOOL sx[NLINES];
    LONG x[NLINES], dx[NLINES], dy[NLINES], incx[NLINES], ex[NLINES], destx[NLINES];
    LONG c[NLINES][3], dc[NLINES][3], ec[NLINES][3], ic[NLINES][3]; /* colors on lines */
    LONG g, gx, gxi, gc[3], gd[3], ge[3], gi[3]; /* colors in triangle */
    LONG sy, y, bt;

    v1 = (pVertex + gTriangle->Vertex1);
    v2 = (pVertex + gTriangle->Vertex2);
    v3 = (pVertex + gTriangle->Vertex3);

    /* bubble sort */
    if (SMALLER(v2, v1))
    {
        TRIVERTEX *t;
        SWAP(v1, v2, t);
    }

    if (SMALLER(v3, v2))
    {
        TRIVERTEX *t;
        SWAP(v2, v3, t);
        if (SMALLER(v2, v1))
        {
            SWAP(v1, v2, t);
        }
    }

    DPRINT("Triangle: (%i,%i) (%i,%i) (%i,%i)\n", v1->x, v1->y, v2->x, v2->y, v3->x, v3->y);
    /* FIXME: commented out because of an endless loop - fix triangles first */
    DPRINT("FIXME: IntEngGradientFillTriangle is broken\n");

    if (!IntEngEnter(&EnterLeave, psoDest, &FillRect, FALSE, &Translate, &psoOutput))
    {
        return FALSE;
    }

    if (VCMPCLRS(v1, v2, v3))
    {
      CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, CD_RIGHTDOWN, 0);
      do
      {
        EnumMore = CLIPOBJ_bEnum(pco, (ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
        for (i = 0; i < RectEnum.c && RectEnum.arcl[i].top <= prclExtents->bottom; i++)
        {
          if (RECTL_bIntersectRect(&FillRect, &RectEnum.arcl[i], prclExtents))
          {
            BOOL InY;

            DOINIT(v1, v3, 0);
            DOINIT(v1, v2, 1);
            DOINIT(v2, v3, 2);

            y = v1->y;
            sy = v1->y + pptlDitherOrg->y;
            bt = min(v3->y + pptlDitherOrg->y, FillRect.bottom);

            while (sy < bt)
            {
              InY = !(sy < FillRect.top || sy >= FillRect.bottom);
              GOLINE(v1, v3, 0);
              DOLINE(v1, v3, 0);
              ENDLINE(v1, v3, 0);

              GOLINE(v1, v2, 1);
              DOLINE(v1, v2, 1);
              FILLLINE(0, 1);
              ENDLINE(v1, v2, 1);

              GOLINE(v2, v3, 2);
              DOLINE(v2, v3, 2);
              FILLLINE(0, 2);
              ENDLINE(23, v3, 2);

              y++;
              sy++;
            }
          }
        }
      } while (EnumMore);

      return IntEngLeave(&EnterLeave);
    }

    /* fill triangle with one solid color */

    Color = XLATEOBJ_iXlate(pxlo, RGB(v1->Red >> 8, v1->Green >> 8, v1->Blue >> 8));
    CLIPOBJ_cEnumStart(pco, FALSE, CT_RECTANGLES, CD_RIGHTDOWN, 0);
    do
    {
      EnumMore = CLIPOBJ_bEnum(pco, (ULONG) sizeof(RectEnum), (PVOID) &RectEnum);
      for (i = 0; i < RectEnum.c && RectEnum.arcl[i].top <= prclExtents->bottom; i++)
      {
        if (RECTL_bIntersectRect(&FillRect, &RectEnum.arcl[i], prclExtents))
        {
          S_INITLINE(v1, v3, 0);
          S_INITLINE(v1, v2, 1);
          S_INITLINE(v2, v3, 2);

          y = v1->y;
          sy = v1->y + pptlDitherOrg->y;
          bt = min(v3->y + pptlDitherOrg->y, FillRect.bottom);

          while (sy < bt)
          {
            S_GOLINE(v1, v3, 0);
            S_DOLINE(v1, v3, 0);
            S_ENDLINE(v1, v3, 0);

            S_GOLINE(v1, v2, 1);
            S_DOLINE(v1, v2, 1);
            S_FILLLINE(0, 1);
            S_ENDLINE(v1, v2, 1);

            S_GOLINE(v2, v3, 2);
            S_DOLINE(v2, v3, 2);
            S_FILLLINE(0, 2);
            S_ENDLINE(23, v3, 2);

            y++;
            sy++;
          }
        }
      }
    } while (EnumMore);

    return IntEngLeave(&EnterLeave);
}