Esempio n. 1
0
        public static MIME_Entity CreateImage(this Mail_Message xml, string file)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }
            string ext = Path.GetExtension(file);
            string media_type = null;
            if (".gif".Equals(ext, StringComparison.CurrentCultureIgnoreCase))
                media_type = MIME_MediaTypes.Image.gif;
            else if (".jpg".Equals(ext, StringComparison.CurrentCultureIgnoreCase) || ".jpeg".Equals(ext, StringComparison.CurrentCultureIgnoreCase))
                media_type = MIME_MediaTypes.Image.jpeg;
            else if (".tiff".Equals(ext, StringComparison.CurrentCultureIgnoreCase))
                media_type = MIME_MediaTypes.Image.tiff;
            else
                throw new Exception("file extension is error");

            MIME_Entity retVal = new MIME_Entity();
            MIME_b_Image body = new MIME_b_Image(media_type);
            retVal.Body = body;
            body.SetDataFromFile(file, MIME_TransferEncodings.Base64);
            retVal.ContentType.Param_Name = Path.GetFileName(file);

            FileInfo fileInfo = new FileInfo(file);
            MIME_h_ContentDisposition disposition = new MIME_h_ContentDisposition(MIME_DispositionTypes.Attachment);
            disposition.Param_FileName = Path.GetFileName(file);
            disposition.Param_Size = fileInfo.Length;
            disposition.Param_CreationDate = fileInfo.CreationTime;
            disposition.Param_ModificationDate = fileInfo.LastWriteTime;
            disposition.Param_ReadDate = fileInfo.LastAccessTime;
            retVal.ContentDisposition = disposition;

            return retVal;
        }
Esempio n. 2
0
        /// <summary>
        /// Parses body from the specified stream
        /// </summary>
        /// <param name="owner">Owner MIME entity.</param>
        /// <param name="defaultContentType">Default content-type for this body.</param>
        /// <param name="stream">Stream from where to read body.</param>
        /// <returns>Returns parsed body.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>stream</b>, <b>defaultContentType</b> or <b>stream</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when any parsing errors.</exception>
        protected static new MIME_b Parse(MIME_Entity owner,MIME_h_ContentType defaultContentType,SmartStream stream)
        {
            if(owner == null){
                throw new ArgumentNullException("owner");
            }
            if(defaultContentType == null){
                throw new ArgumentNullException("defaultContentType");
            }
            if(stream == null){
                throw new ArgumentNullException("stream");
            }

            MIME_b_Image retVal = null;
            if(owner.ContentType != null){
                retVal = new MIME_b_Image(owner.ContentType.TypeWithSubtype);
            }
            else{
                retVal = new MIME_b_Image(defaultContentType.TypeWithSubtype);
            }

            Net_Utils.StreamCopy(stream,retVal.EncodedStream,32000);

            return retVal;
        }