void
GMMIMEParser::ParseContentParameters
	(
	const JString&		text,
	JPtrArray<JString>*	strings
	)
{
	JString tmp = text;
	JString* str;
	JIndex findex;
	while (tmp.LocateSubstring("=", &findex) && findex > 1)
		{
		str = new JString(tmp.GetSubstring(1, findex - 1));
		assert(str != NULL);
		str->TrimWhitespace();
		str->ToLower();
		strings->Append(str);

		tmp.RemoveSubstring(1, findex);
		tmp.TrimWhitespace();

		// now we need to get the corresponding value.
		// we need to check for quotes first.
		JIndex index = 1;
		if (tmp.GetLength() > 1 && tmp.GetCharacter(1) == '\"')
			{
			FindStringEnd(tmp, &index);
			str = new JString(tmp.GetSubstring(2, index-1));
			assert(str != NULL);
			if (tmp.LocateSubstring(";", &findex))
				{
				tmp.RemoveSubstring(1, findex);
				}
			}
		else if (tmp.LocateSubstring(";", &index))
			{
			str = new JString();
			assert(str != NULL);
			if (index > 1)
				{
				*str = tmp.GetSubstring(1, index-1);
				}
			tmp.RemoveSubstring(1, index);
			}
		else
			{
			str = new JString(tmp);
			assert(str != NULL);
			}

		str->TrimWhitespace();
		strings->Append(str);

		tmp.TrimWhitespace();
		}
}
예제 #2
0
JString
JXFontManager::ConvertToXFontName
	(
	const JCharacter* name
	)
	const
{
	JString fontName = name;
	fontName.ToLower();
	return fontName;
}
void
CBFunctionMenu::SetEmptyMenuItems()
{
	JString name = CBCtagsUser::GetFunctionMenuTitle(itsFileType);
	name.ToLower();

	const JCharacter* map[] =
		{
		"name", name.GetCString()
		};
	const JString menuItems = JGetString(kEmptyMenuID, map, sizeof(map));
	SetMenuItems(menuItems);
}
void
GMMIMEParser::ParseContentType
	(
	const JString&	val,
	GMIMEHeader*	header
	)
{
	// we first need to determine the type. this will be found before the
	// first '/' which will be followed by the subtype.
	JString tVal	= val;
	tVal.TrimWhitespace();
	JSize length	= tVal.GetLength();

	JString type;
	JIndex findex;
	if (tVal.LocateSubstring("/", &findex) && (findex > 1))
		{
		type = tVal.GetSubstring(1, findex - 1);
		tVal.RemoveSubstring(1, findex);
		tVal.TrimWhitespace();
		type.ToLower();
		header->SetType(type);
		}
	else
		{
		return;
		}

	// now we need to determine the subtype
	JString subType;
	length			= tVal.GetLength();
	JBoolean found	= kJFalse;
	JIndex index;
	if (tVal.LocateSubstring(";", &index))
		{
		subType = tVal.GetSubstring(1, index - 1);
		tVal.RemoveSubstring(1, index);
		}
	else
		{
		subType = tVal;
		tVal.Clear();
		}

	tVal.TrimWhitespace();
	subType.TrimWhitespace();
	subType.ToLower();
	header->SetSubType(subType);

	if (tVal.IsEmpty())
		{
		return;
		}

	JPtrArray<JString> strings(JPtrArrayT::kDeleteAll);
	ParseContentParameters(tVal, &strings);
	JSize count = strings.GetElementCount();
	for (JIndex i = 1; i <= count; i += 2)
		{
		JString* str	= strings.NthElement(i);
		if (type == kTextType)
			{
			if (*str == "charset")
				{
				if (strings.IndexValid(i+1))
					{
					str	= strings.NthElement(i+1);
					header->SetCharSet(*str);
					}
				}
			}
		else if (type == kMultipartType)
			{
			if (*str == "boundary")
				{
				if (strings.IndexValid(i+1))
					{
					str	= strings.NthElement(i+1);
					header->SetBoundary(*str);
					}
				}
			}
		if ((type == kAppType) ||
			(type == kImageType) ||
			(type == kTextType))
			{
			if (*str == "name")
				{
				if (strings.IndexValid(i+1))
					{
					str	= strings.NthElement(i+1);
					if (str->LocateLastSubstring("/", &findex))
						{
						str->RemoveSubstring(1, findex);
						}
					if (str->LocateLastSubstring("\\", &findex))
						{
						str->RemoveSubstring(1, findex);
						}
					header->SetFileName(*str);
					}
				}
			}
		}
}
void
GMMIMEParser::ParseMIMEHeader
	(
	std::istream&		input,
	GMIMEHeader*	header,
	const JBoolean	display
	)
{
	JString data;
	JCharacter c	= input.peek();
	if (c == '\n')
		{
//		input.get(c);
		}
//	input >> std::ws;

	// first we need to search for the first empty line. This line is the
	// end of the header.

	JString line;
	while (1)
		{
		JBoolean found;
		line = JReadLine(input, &found);
		if (line.IsEmpty())
			{
			break;
			}
		if (isspace(line.GetFirstCharacter()))
			{
			line.TrimWhitespace();
			if (line.IsEmpty())
				{
				break;
				}
			data.AppendCharacter(' ');
			}
		else if (!data.IsEmpty())
			{
			data.AppendCharacter('\n');
			}
		data += line;
		}
	data.AppendCharacter('\n');

	// we now need to search through the header for parameter:value pairs
	// using the gmime_header_regex defined above.

	JArray<JIndexRange> ranges;
	gmime_header_regex.MatchAll(data, &ranges);

	JSize count = ranges.GetElementCount();
	for (JSize i = 1; i <= count; i++)
		{
		JIndexRange range = ranges.GetElement(i);
		JString parmValPair = data.GetSubstring(range);
		JString parm;
		JString val;
		if (parmValPair.BeginsWith("MIME") ||
			parmValPair.BeginsWith("Mime") ||
			parmValPair.BeginsWith("Content"))
			{
			CleanParmValPair(parmValPair, &parm, &val);
			parm.ToLower();
			if (parm == "mime-Version")
				{
				val.TrimWhitespace();
				header->SetVersion(val);
				}
			else if (parm == "content-type")
				{
				ParseContentType(val, header);
				}
			else if (parm == "content-transfer-encoding")
				{
				val.TrimWhitespace();
				val.ToLower();
				header->SetEncoding(val);
				}
			else if (parm == "content-disposition")
				{
				ParseContentDisposition(val, header);
				}
			}
		}

	// this is a nested message, so some of the headers need to be displayed
	if (display)
		{
		JString text = "---------\n";
		JIndex findex	= 1;
		if (data.BeginsWith("From: ") || data.LocateSubstring("\nFrom: ", &findex))
			{
			if (findex > 1)
				{
				findex ++;
				}
			JIndex eindex	= findex;
			if (data.LocateNextSubstring("\n", &eindex) && (eindex > findex + 1))
				{
				text += data.GetSubstring(findex, eindex - 1);
				text += "\n";
				}
			}
		findex	= 1;
		if (data.BeginsWith("Date: ") || data.LocateSubstring("\nDate: ", &findex))
			{
			if (findex > 1)
				{
				findex ++;
				}
			JIndex eindex	= findex;
			if (data.LocateNextSubstring("\n", &eindex) && (eindex > findex + 1))
				{
				text += data.GetSubstring(findex, eindex - 1);
				text += "\n";
				}
			}
		findex	= 1;
		const JCharacter* kSubjectStr	= "Subject: ";
		if (data.BeginsWith("Subject: ") || data.LocateSubstring("\nSubject: ", &findex))
			{
			if (findex > 1)
				{
				findex ++;
				}
			JIndex eindex	= findex;
			if (data.LocateNextSubstring("\n", &eindex) && (eindex > findex + 1))
				{
				text += data.GetSubstring(findex, eindex - 1);
				text += "\n";
				}
			}
		WriteTextString(&text, GMIMEHeader());
		}
}