public static EmailMessage Create(BodyFormat bodyFormat, bool createAlternative, string charsetName) { if (bodyFormat != BodyFormat.Text && bodyFormat != BodyFormat.Html) { throw new ArgumentException(EmailMessageStrings.CannotCreateSpecifiedBodyFormat(bodyFormat.ToString())); } if (bodyFormat == BodyFormat.Text && createAlternative) { throw new ArgumentException(EmailMessageStrings.CannotCreateAlternativeBody); } Charset.GetCharset(charsetName); MimeTnefMessage mimeTnefMessage = new MimeTnefMessage(bodyFormat, createAlternative, charsetName); return(new EmailMessage(mimeTnefMessage)); }
private void LoadProperty(TnefPropertyReader propertyReader, DataStorage tnefStorage, long tnefStart, long tnefEnd, TnefAttributeLevel level, int embeddingDepth, Charset binaryCharset) { TnefPropertyTag propertyTag = propertyReader.PropertyTag; if (propertyTag.IsMultiValued) { return; } if (TnefPropertyType.Null == propertyTag.ValueTnefType) { return; } if (propertyReader.IsNamedProperty) { TnefNameId propertyNameId = propertyReader.PropertyNameId; TnefNameTag key = new TnefNameTag(propertyNameId, propertyTag.ValueTnefType); if (this.supportedNamedProperties.ContainsKey(key)) { if (propertyReader.IsLargeValue) { return; } this[this.GetIndex(propertyNameId)] = propertyReader.ReadValue(); } return; } if (!this.supportedProperties.ContainsKey(propertyTag)) { return; } TnefPropertyId id = propertyTag.Id; int index = this.GetIndex(id); if (TnefPropertyId.Body == id || TnefPropertyId.RtfCompressed == id || TnefPropertyId.BodyHtml == id) { tnefStart += (long)propertyReader.RawValueStreamOffset; tnefEnd = tnefStart + (long)propertyReader.RawValueLength; this[index] = new StoragePropertyValue(propertyTag, tnefStorage, tnefStart, tnefEnd); return; } if (TnefPropertyId.AttachData == id) { tnefStart += (long)propertyReader.RawValueStreamOffset; tnefEnd = tnefStart + (long)propertyReader.RawValueLength; this[index] = new StoragePropertyValue(propertyTag, tnefStorage, tnefStart, tnefEnd); if (!propertyReader.IsEmbeddedMessage) { return; } if (++embeddingDepth > 100) { throw new MimeException(EmailMessageStrings.NestingTooDeep(embeddingDepth, 100)); } using (TnefReader embeddedMessageReader = propertyReader.GetEmbeddedMessageReader()) { PureTnefMessage pureTnefMessage = new PureTnefMessage(this.attachmentData, tnefStorage, tnefStart, tnefEnd); pureTnefMessage.Load(embeddedMessageReader, embeddingDepth, binaryCharset); EmailMessage embeddedMessage = new EmailMessage(pureTnefMessage); this.attachmentData.EmbeddedMessage = embeddedMessage; return; } } if (propertyReader.IsLargeValue) { return; } if (TnefPropertyId.InternetCPID == id) { if (TnefPropertyType.Long == propertyTag.TnefType) { int num = propertyReader.ReadValueAsInt32(); this[index] = num; return; } } else { this[index] = propertyReader.ReadValue(); } }
private static void Transcode(Stream applefileStream, Stream dataForkStream, Stream outAttachMacInfo, Stream outMacBinStream, ref Stream outDataForkStream, out string fileName, out byte[] additionalInfo) { if (applefileStream.Length < 26L) { throw new MimeException(EmailMessageStrings.UnexpectedEndOfStream); } int num = MimeAppleTranscoder.ReadUIntFromStream(applefileStream); if (num != 333319 && num != 333312) { if (dataForkStream != null) { throw new MimeException(EmailMessageStrings.WrongAppleMagicNumber); } applefileStream.Position = 0L; MimeAppleTranscoder.MacBinToApplefile(applefileStream, outAttachMacInfo, out fileName, out additionalInfo); applefileStream.Position = 0L; if (outMacBinStream == null) { return; } MimeAppleTranscoder.CopyStreamData(applefileStream, outMacBinStream); return; } else { fileName = null; byte[] array = new byte[128]; array[0] = 0; int num2 = 0; if (dataForkStream != null) { num2 = 83; MimeAppleTranscoder.WriteIntData((int)dataForkStream.Length, array, ref num2); } byte[] bytes = MimeAppleTranscoder.macEncoding.GetBytes("mBIN"); for (int i = 0; i < 4; i++) { array[102 + i] = bytes[i]; } array[122] = 130; array[123] = 129; int inputOffset = 0; MimeAppleTranscoder.EntryDescriptor entryDescriptor = null; int inputOffset2 = 0; List <MimeAppleTranscoder.EntryDescriptor> list = MimeAppleTranscoder.ReadAppleFileHeaderEntries(applefileStream); foreach (MimeAppleTranscoder.EntryDescriptor entryDescriptor2 in list) { switch (entryDescriptor2.EntryId) { case 1: entryDescriptor = entryDescriptor2; num2 = 83; MimeAppleTranscoder.WriteIntData(entryDescriptor2.EntryLength, array, ref num2); break; case 2: inputOffset = entryDescriptor2.EntryOffset; num2 = 87; MimeAppleTranscoder.WriteIntData(entryDescriptor2.EntryLength, array, ref num2); break; case 4: inputOffset2 = entryDescriptor2.EntryOffset; num2 = 99; MimeAppleTranscoder.WriteShortData(entryDescriptor2.EntryLength, array, ref num2); break; } } if (entryDescriptor != null) { list.Remove(entryDescriptor); } if (outAttachMacInfo != null) { MimeAppleTranscoder.WriteApplefileHeader(list, true, outAttachMacInfo); } int num3 = (int)applefileStream.Position; foreach (MimeAppleTranscoder.EntryDescriptor entryDescriptor3 in list) { if (entryDescriptor3.EntryOffset < num3) { throw new MimeException(EmailMessageStrings.WrongOffsetsInApplefile); } if (entryDescriptor3.EntryOffset > num3) { if (applefileStream.Length < (long)entryDescriptor3.EntryOffset) { throw new MimeException(EmailMessageStrings.WrongOffsetsInApplefile); } applefileStream.Position = (long)entryDescriptor3.EntryOffset; } if (entryDescriptor3.EntryLength < 0) { throw new MimeException(EmailMessageStrings.EntryLengthTooBigInApplefile((long)((ulong)entryDescriptor3.EntryLength))); } int num4 = 0; byte[] array2 = null; int entryId = entryDescriptor3.EntryId; if (entryId != 3) { switch (entryId) { case 8: num4 = Math.Min(8, entryDescriptor3.EntryLength); array2 = new byte[num4]; MimeAppleTranscoder.ReadFixed(applefileStream, array2, 0, num4); for (int j = 0; j < num4; j++) { array[91 + j] = array2[j]; } break; case 9: num4 = Math.Min(28, entryDescriptor3.EntryLength); array2 = new byte[num4]; MimeAppleTranscoder.ReadFixed(applefileStream, array2, 0, num4); if (num4 >= 16) { for (int k = 0; k < 16; k++) { array[65 + k] = array2[k]; } array[101] = array[73]; array[73] = array[74]; array[74] = 0; if (num4 >= 22) { array[106] = array2[20]; array[107] = array2[21]; } } break; case 10: num4 = Math.Min(4, entryDescriptor3.EntryLength); array2 = new byte[num4]; MimeAppleTranscoder.ReadFixed(applefileStream, array2, 0, num4); if (num4 == 4) { array[81] = (byte)((array2[3] & 2) >> 1); } break; } } else { num4 = Math.Min(63, entryDescriptor3.EntryLength); array2 = new byte[num4]; MimeAppleTranscoder.ReadFixed(applefileStream, array2, 0, num4); fileName = MimeAppleTranscoder.macEncoding.GetString(array2, 0, num4); array[1] = (byte)num4; for (int l = 0; l < num4; l++) { array[2 + l] = array2[l]; } } if (outAttachMacInfo != null) { if (array2 != null) { outAttachMacInfo.Write(array2, 0, num4); } if (num4 != entryDescriptor3.EntryLength) { MimeAppleTranscoder.CopyStreamData(applefileStream, outAttachMacInfo, new int?(entryDescriptor3.EntryLength - num4)); } } num3 = (int)applefileStream.Position; } num2 = 124; MimeAppleTranscoder.WriteUShortData((int)MimeAppleTranscoder.CalcCRC16(array, 126), array, ref num2); MacBinaryHeader macBinaryHeader = new MacBinaryHeader(array); if (outMacBinStream == null) { additionalInfo = null; if (outDataForkStream != null) { ReadableDataStorageOnStream readableDataStorageOnStream = new ReadableDataStorageOnStream(applefileStream, false); if (entryDescriptor != null) { outDataForkStream = readableDataStorageOnStream.OpenReadStream((long)entryDescriptor.EntryOffset, (long)(entryDescriptor.EntryOffset + (int)macBinaryHeader.DataForkLength)); return; } outDataForkStream = readableDataStorageOnStream.OpenReadStream(0L, 0L); } return; } additionalInfo = MimeAppleTranscoder.EncodeAdditionalInfo(macBinaryHeader.FileCreator, macBinaryHeader.FileType); outMacBinStream.Write(array, 0, array.Length); if (macBinaryHeader.DataForkLength > 0L) { if (dataForkStream != null) { MimeAppleTranscoder.CopyStreamData(dataForkStream, outMacBinStream); MimeAppleTranscoder.WriteMacBinPadding(outMacBinStream, (int)macBinaryHeader.DataForkLength); } else if (entryDescriptor != null) { MimeAppleTranscoder.CopyDataWithPadding(applefileStream, outMacBinStream, entryDescriptor.EntryOffset, (int)macBinaryHeader.DataForkLength); } } if (macBinaryHeader.ResourceForkLength > 0L) { MimeAppleTranscoder.CopyDataWithPadding(applefileStream, outMacBinStream, inputOffset, (int)macBinaryHeader.ResourceForkLength); } if (macBinaryHeader.GetInfoLength > 0) { MimeAppleTranscoder.CopyDataWithPadding(applefileStream, outMacBinStream, inputOffset2, macBinaryHeader.GetInfoLength); } return; } }