public static string MimeEncodingToString(MimeEncoding encoding) { switch (encoding) { case MimeEncoding.Text7bit: return("7bit"); case MimeEncoding.Text8bit: return("8bit"); case MimeEncoding.Binary: return("binary"); case MimeEncoding.QuotedPrintable: return("quoted-printable"); case MimeEncoding.Base64: return("base64"); case MimeEncoding.UUEncode: return("uuencode"); default: throw new ArgumentException("Invalid value for MimeEncoding"); } }
internal void WriteContent(byte[] content, int contentLength, MimeEncoding encoding) { switch (encoding) { case MimeEncoding.Text: case MimeEncoding.Text7bit: case MimeEncoding.Text8bit: _writeContent_Text(content, contentLength); break; case MimeEncoding.QuotedPrintable: _writeContent_QuotedPrintable(content, contentLength); break; case MimeEncoding.Base64: _writeContent_Base64(content, contentLength); break; default: throw new NotImplementedException("Not implemented WriteContent '" + encoding.ToString() + "' not implemented."); } }
public byte[] ReadData(MimeEncoding encoding, string boundary) { using (MemoryStream dataStream = new MemoryStream()) { while (true) { if (!ReadLine(false)) { return(dataStream.ToArray()); } if (isLineEmpty) { switch (encoding) { case MimeEncoding.Base64: case MimeEncoding.UUEncode: return(dataStream.ToArray()); } } if (boundary != null && TestBoundary(boundary) != 0) { return(dataStream.ToArray()); } switch (encoding) { case MimeEncoding.QuotedPrintable: _decodeQuotedPrintableTo(dataStream); break; case MimeEncoding.Base64: _decodeBase64To(dataStream); break; case MimeEncoding.UUEncode: _decodeUUEncodeTo(dataStream); break; default: _decodeTextTo(dataStream); break; } } } }
/// <summary> /// Prepare a collection of files for transmission. /// </summary> /// <param name="parts">The transmission parts.</param> /// <param name="transmissionFactory">Transmission factory that is needed but not used.</param> /// <param name="encodingfactory">The encodingfactory</param> /// <param name="transmissionLogger">The transmissionLogger</param> /// <returns>A collection of file transmission items in order of sending.</returns> /// <remarks> /// <para> /// Path variables supported : /// </para> /// <para> /// ${Root} = urlBase attribute of the FileTransmitterEncoder configuration. /// </para> /// <para> /// ${Guid} = A GUID directory. /// </para> /// <para> /// ${JobId} = A JobId directory. JobId used is from the first JDF found in the parts. /// </para> /// <para> /// ${JobKey} = A JobKey directory. JobKey used is from the first JDF found in the parts (tree.Key). /// </para> /// </remarks> public virtual List <FileTransmissionItem> PrepareTransmission(ITransmissionPartCollection parts, ITransmissionPartFactory transmissionFactory, IEncodingFactory encodingfactory, ITransmissionLogger transmissionLogger) { var items = new List <FileTransmissionItem>(); try { if (UseMime) { MimeEncoding encoding = new MimeEncoding(transmissionFactory); var encoded = encoding.Encode(parts); using (var mimeResult = encoded.Stream) { //TODO determine better way to provide the part. items.Add(new FileTransmissionItem(null, mimeResult, new Uri(Path.Combine(LocalPath, Guid.NewGuid().ToString() + ".mim")), encoded.ContentType, 0)); } } else { if (JmfFolderInfo == null && JdfFolderInfo == null && AttachmentFolderInfo == null) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaild, Id)); } if (JmfFolderInfo != null && (JdfFolderInfo == null || AttachmentFolderInfo == null)) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaildJMFNoJDF, Id)); } if (JdfFolderInfo != null && AttachmentFolderInfo == null) { throw new JdfException( string.Format(FluentJdf.Resources.Messages.TheConfigurationOfTheFileTransmissionEncoderId0IsInvaildJDFNoAttach, Id)); } Guid transmissionGuid = Guid.NewGuid(); string jobId = "JDF_JobIdUnknown"; string jobKey = "JDF_JobKeyUnknown"; var jdfTransmissionPart = parts.TicketPart; //pass over parts to get the job id and key if (jdfTransmissionPart != null) { //TODO is this the best way to obtain the ticket? We know it must exist since we are on the correct mime item. var ticket = parts.Ticket; if (ticket.Root.GetJobId().Length > 0) { jobId = "JDF_" + ticket.Root.GetJobId(); } if (ticket.Root.GetId().Length > 0) { jobKey = "JDF_" + ticket.Root.GetId(); } } var itemsToProcess = new List <KeyValuePair <ITransmissionPart, string> >(); //pass over parts to generate destination file names and mapping var urlMapping = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); foreach (ITransmissionPart part in parts) { FileTransmitterFolderInfo folder; string extension = null; if (part.MimeType == MimeTypeHelper.JdfMimeType) { folder = JdfFolderInfo; extension = ".jdf"; } else if (part.MimeType == MimeTypeHelper.JmfMimeType) { folder = JmfFolderInfo; extension = ".jmf"; } else { folder = AttachmentFolderInfo; extension = MimeTypeHelper.MimeTypeExtension(part.MimeType); } string fileName = part.Id.ToString() + extension; if (folder != null) { var newFileName = Path.Combine(ExpandFolder(folder.DestinationFolder, transmissionGuid, jobId, jobKey), fileName); string referencePath = Path.Combine(ExpandFolder(folder.ReferenceFolder, transmissionGuid, jobId, jobKey), fileName); urlMapping.Add("cid:" + part.Id.ToLower(), referencePath); itemsToProcess.Add(new KeyValuePair <ITransmissionPart, string>(part, newFileName)); } } //fixup urls and add to the collection of files to send foreach (var processPart in itemsToProcess) { FileTransmitterFolderInfo folder; var part = processPart.Key; var file = processPart.Value; if (part.MimeType == MimeTypeHelper.JdfMimeType) { folder = JdfFolderInfo; } else if (part.MimeType == MimeTypeHelper.JmfMimeType) { folder = JmfFolderInfo; } else { folder = AttachmentFolderInfo; } //TODO is this the best way to obtain the ticket? We know it must exist since we are on the correct mime item. if (part.MimeType == MimeTypeHelper.JdfMimeType) { FileSpecUrlMangler.MapFileSpecUrls(parts.Ticket, urlMapping, true); FileSpecUrlMangler.MapPreviewUrls(parts.Ticket, urlMapping, true); } //TODO is this the best way to obtain the message? We know it must exist since we are on the correct mime item. if (part.MimeType == MimeTypeHelper.JmfMimeType) { MapMessageUrls(parts.Message, urlMapping); } if (folder != null) { if (!folder.Suppress) { var encodingResult = encodingfactory.GetEncodingForMimeType(part.MimeType).Encode(part); encodingResult.Stream.Seek(0, SeekOrigin.Begin); transmissionLogger.Log(new TransmissionData(encodingResult.Stream, encodingResult.ContentType, "Request")); items.Add(new FileTransmissionItem(part, encodingResult.Stream, new Uri(file), part.MimeType, folder.Order)); } } } } } catch (Exception err) { throw new JdfException(string.Format(FluentJdf.Resources.Messages.ErrorOccuredWhileTryingToEncodeTransmissionMessageIs, err.Message), err); } return(items); }
/// <summary> /// Returns a RFC2045 content transfer encoding value for a /// given MimeEncoding. /// </summary> /// <returns></returns> protected string MimeEncodingToString(MimeEncoding encoding) { switch (encoding) { case MimeEncoding.Base64: return "base64"; case MimeEncoding.Binary: return "binary"; case MimeEncoding.E7Bit: return "7bit"; case MimeEncoding.E8Bit: return "8bit"; case MimeEncoding.QuotedPrintable: return "quoted-printable"; default: return "7bit"; } }