working on it ...

Filters

Explore Public Snippets

Sort by

Found 348 snippets matching: mime

    public by cghersi modified Jan 31, 2014  4283  1  6  0

    C#: Convert Extensions to MIME types

    This is a large set of extensions that can be converted in vlid MIME Types
    public static string ConvertExtensionToMimeType(string extension)
    {
        string ext = extension.ToLower().Trim(new char[] { ' ', '.' });
        switch (ext)
        {
            case "ai": return "application/postscript";
            case "aif": return "audio/x-aiff";
            case "aifc": return "audio/x-aiff";
            case "aiff": return "audio/x-aiff";
            case "asc": return "text/plain";
            case "asf": return "video/x-ms-asf";
            case "au": return "audio/basic";
            case "avi": return "video/x-msvideo";
            case "bcpio": return "application/x-bcpio";
            case "bin": return "application/octet-stream";
            case "c": return "text/plain";
            case "cc": return "text/plain";
            case "ccad": return "application/clariscad";
            case "cdf": return "application/x-netcdf";
            case "class": return "application/octet-stream";
            case "cpio": return "application/x-cpio";
            case "cpp": return "text/plain";
            case "cpt": return "application/mac-compactpro";
            case "cs": return "text/plain";
            case "csh": return "application/x-csh";
            case "css": return "text/css";
            case "dcr": return "application/x-director";
            case "dir": return "application/x-director";
            case "dms": return "application/octet-stream";
            case "doc": return "application/msword";
            case "drw": return "application/drafting";
            case "dvi": return "application/x-dvi";
            case "dwg": return "application/acad";
            case "dxf": return "application/dxf";
            case "dxr": return "application/x-director";
            case "eps": return "application/postscript";
            case "etx": return "text/x-setext";
            case "exe": return "application/octet-stream";
            case "ez": return "application/andrew-inset";
            case "f": return "text/plain";
            case "f90": return "text/plain";
            case "fli": return "video/x-fli";
            case "flv": return "video/x-flv";
            case "gif": return "image/gif";
            case "gtar": return "application/x-gtar";
            case "gz": return "application/x-gzip";
            case "h": return "text/plain";
            case "hdf": return "application/x-hdf";
            case "hh": return "text/plain";
            case "hqx": return "application/mac-binhex40";
            case "htm": return "text/html";
            case "html": return "text/html";
            case "ice": return "x-conference/x-cooltalk";
            case "ief": return "image/ief";
            case "iges": return "model/iges";
            case "igs": return "model/iges";
            case "ips": return "application/x-ipscript";
            case "ipx": return "application/x-ipix";
            case "jpe": return "image/jpeg";
            case "jpeg": return "image/jpeg";
            case "jpg": return "image/jpeg";
            case "js": return "application/x-javascript";
            case "kar": return "audio/midi";
            case "latex": return "application/x-latex";
            case "lha": return "application/octet-stream";
            case "lsp": return "application/x-lisp";
            case "lzh": return "application/octet-stream";
            case "m": return "text/plain";
            case "man": return "application/x-troff-man";
            case "me": return "application/x-troff-me";
            case "mesh": return "model/mesh";
            case "mid": return "audio/midi";
            case "midi": return "audio/midi";
            case "mime": return "www/mime";
            case "mov": return "video/quicktime";
            case "movie": return "video/x-sgi-movie";
            case "mp2": return "audio/mpeg";
            case "mp3": return "audio/mpeg";
            case "mpe": return "video/mpeg";
            case "mpeg": return "video/mpeg";
            case "mpg": return "video/mpeg";
            case "mpga": return "audio/mpeg";
            case "ms": return "application/x-troff-ms";
            case "msh": return "model/mesh";
            case "nc": return "application/x-netcdf";
            case "oda": return "application/oda";
            case "pbm": return "image/x-portable-bitmap";
            case "pdb": return "chemical/x-pdb";
            case "pdf": return "application/pdf";
            case "pgm": return "image/x-portable-graymap";
            case "pgn": return "application/x-chess-pgn";
            case "png": return "image/png";
            case "pnm": return "image/x-portable-anymap";
            case "pot": return "application/mspowerpoint";
            case "ppm": return "image/x-portable-pixmap";
            case "pps": return "application/mspowerpoint";
            case "ppt": return "application/mspowerpoint";
            case "ppz": return "application/mspowerpoint";
            case "pre": return "application/x-freelance";
            case "prt": return "application/pro_eng";
            case "ps": return "application/postscript";
            case "qt": return "video/quicktime";
            case "ra": return "audio/x-realaudio";
            case "ram": return "audio/x-pn-realaudio";
            case "ras": return "image/cmu-raster";
            case "rgb": return "image/x-rgb";
            case "rm": return "audio/x-pn-realaudio";
            case "roff": return "application/x-troff";
            case "rpm": return "audio/x-pn-realaudio-plugin";
            case "rtf": return "text/rtf";
            case "rtx": return "text/richtext";
            case "scm": return "application/x-lotusscreencam";
            case "set": return "application/set";
            case "sgm": return "text/sgml";
            case "sgml": return "text/sgml";
            case "sh": return "application/x-sh";
            case "shar": return "application/x-shar";
            case "silo": return "model/mesh";
            case "sit": return "application/x-stuffit";
            case "skd": return "application/x-koan";
            case "skm": return "application/x-koan";
            case "skp": return "application/x-koan";
            case "skt": return "application/x-koan";
            case "smi": return "application/smil";
            case "smil": return "application/smil";
            case "snd": return "audio/basic";
            case "sol": return "application/solids";
            case "spl": return "application/x-futuresplash";
            case "src": return "application/x-wais-source";
            case "step": return "application/STEP";
            case "stl": return "application/SLA";
            case "stp": return "application/STEP";
            case "sv4cpio": return "application/x-sv4cpio";
            case "sv4crc": return "application/x-sv4crc";
            case "swf": return "application/x-shockwave-flash";
            case "t": return "application/x-troff";
            case "tar": return "application/x-tar";
            case "tcl": return "application/x-tcl";
            case "tex": return "application/x-tex";
            case "tif": return "image/tiff";
            case "tiff": return "image/tiff";
            case "tr": return "application/x-troff";
            case "tsi": return "audio/TSP-audio";
            case "tsp": return "application/dsptype";
            case "tsv": return "text/tab-separated-values";
            case "txt": return "text/plain";
            case "unv": return "application/i-deas";
            case "ustar": return "application/x-ustar";
            case "vcd": return "application/x-cdlink";
            case "vda": return "application/vda";
            case "vrml": return "model/vrml";
            case "wav": return "audio/x-wav";
            case "wm": return "video/x-ms-wm";
            case "wma": return "audio/x-ms-wma";
            case "wmv": return "video/x-ms-wmv";
            case "wrl": return "model/vrml";
            case "xbm": return "image/x-xbitmap";
            case "xlc": return "application/vnd.ms-excel";
            case "xll": return "application/vnd.ms-excel";
            case "xlm": return "application/vnd.ms-excel";
            case "xls": return "application/vnd.ms-excel";
            case "xlw": return "application/vnd.ms-excel";
            case "xml": return "text/xml";
            case "xpm": return "image/x-xpixmap";
            case "xwd": return "image/x-xwindowdump";
            case "xyz": return "chemical/x-pdb";
            case "zip": return "application/zip";
            case "docm": return "application/vnd.ms-word.document.macroEnabled.12";
            case "docx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
            case "dotm": return "application/vnd.ms-word.template.macroEnabled.12";
            case "dotx": return "application/vnd.openxmlformats-officedocument.wordprocessingml.template";
            case "potm": return "application/vnd.ms-powerpoint.template.macroEnabled.12";
            case "potx": return "application/vnd.openxmlformats-officedocument.presentationml.template";
            case "ppam": return "application/vnd.ms-powerpoint.addin.macroEnabled.12";
            case "ppsm": return "application/vnd.ms-powerpoint.slideshow.macroEnabled.12";
            case "ppsx": return "application/vnd.openxmlformats-officedocument.presentationml.slideshow";
            case "pptm": return "application/vnd.ms-powerpoint.presentation.macroEnabled.12";
            case "pptx": return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
            case "xlam": return "application/vnd.ms-excel.addin.macroEnabled.12";
            case "xlsb": return "application/vnd.ms-excel.sheet.binary.macroEnabled.12";
            case "xlsm": return "application/vnd.ms-excel.sheet.macroEnabled.12";
            case "xlsx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
            case "xltm": return "application/vnd.ms-excel.template.macroEnabled.12";
            case "xltx": return "application/vnd.openxmlformats-officedocument.spreadsheetml.template";
            default: return "text/plain";
        }
    }
    

    public by afelicioni modified Mar 2, 2016  3626  0  3  0

    IIS woff2 mime fix

    IIS woff2 mime fix: web.config
    <staticContent>
    <remove fileExtension=".woff" />
    <remove fileExtension=".woff2" />
    <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
    <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
    </staticContent>
    
    

    public by SpeedOfSpin modified Jul 10, 2017  1066  2  4  0

    Mime Types

    nix
    <system.webServer>
    <staticContent>
        <mimeMap fileExtension=".mp4" mimeType="video/mp4" />
        <mimeMap fileExtension=".m4v" mimeType="video/m4v" />
        <mimeMap fileExtension=".ogg" mimeType="video/ogg" />
        <mimeMap fileExtension=".ogv" mimeType="video/ogg" />
        <mimeMap fileExtension=".webm" mimeType="video/webm" />
    
        <mimeMap fileExtension=".oga" mimeType="audio/ogg" />
        <mimeMap fileExtension=".spx" mimeType="audio/ogg" />
    
        <mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
        <mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
    
        <remove fileExtension=".eot" />
        <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
        <mimeMap fileExtension=".otf" mimeType="font/otf" />
        <mimeMap fileExtension=".woff" mimeType="font/x-woff" />
    </staticContent>
    </system.webServer>

    public by zonaro modified Oct 30, 2015  9192  285  7  0

    Convert a Image Type HttpPostedFile to Base64 String or DataURL

    Allow you to convert Images (jpg, png or gif images) in HttpPostedFile to a Base64 String or a full DataURL with MIME Type Detection
    public static string ToBase64(this HttpPostedFile PostedFile, bool DataUrl = false)
            {
    
                if (PostedFile.ContentType.ToLower() == "image/jpg" || PostedFile.ContentType.ToLower() == "image/jpeg" || PostedFile.ContentType.ToLower() == "image/pjpeg" || PostedFile.ContentType.ToLower() == "image/gif" || PostedFile.ContentType.ToLower() == "image/x-png" || PostedFile.ContentType.ToLower() == "image/png")
                {
    
                    using (MemoryStream ms = new MemoryStream())
                    {
                        PostedFile.InputStream.CopyTo(ms);
                        byte[] fileBytes = ms.ToArray();
                        return (DataUrl ? "data:" + PostedFile.ContentType + ";base64," + Convert.ToBase64String(fileBytes, 0, (int)ms.Length) : Convert.ToBase64String(fileBytes, 0, (int)ms.Length));
                    }
                }
    
                else
                {
                    return "";
                }
            }

    public by lbottaro modified Jan 23, 2013  5388  30  8  1

    Send Email in python

    This method sends an email to a recipients list. The method can generate a message both as HMTL and simple TXT and attach also some file to email. Note the use of MIME values to define which format being used.
    #!/usr/bin/python
    import os
    import sys
    
    #Imports for HTML email format
    import smtplib
    from email.mime.multipart import MIMEMultipart
    from email.mime.text import MIMEText
    from email import Encoders
    from email.MIMEBase import MIMEBase
    from subprocess import Popen, PIPE, STDOUT
    
    use_email_format_html = False
    # This function sends an email with the specified arguments
    def sendmail(recipients, subject, text, attachedFiles=[]):
        emailFrom = "userSender"
        emailTo = recipients
        msg = MIMEMultipart('alternative')
        msg['Subject'] = subject
        msg['From'] = emailFrom
        msg['To'] = emailTo
        if use_email_format_html: 
            msg.attach(MIMEText(text, 'html'))
        else:
            msg.attach(MIMEText(text, 'plain'))
        if attachedFiles:
            print 'Attached files...'
            # attach a file
            for file in attachedFiles:
                part = MIMEBase('application', "octet-stream")
                print file
                part.set_payload( open(file,"rb").read() )
        	      Encoders.encode_base64(part)
                part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file))
                msg.attach(part)
    
        # Send the message via local SMTP server.
        s = smtplib.SMTP('localhost')
        # sendmail function takes 3 arguments: sender's address, recipient's address
        s.sendmail(emailFrom, emailTo.split(","), msg.as_string())
        s.quit()
    
    ######
    # MAIN - USAGE
    ######
    recipients = "email01@email.com, email02@email.com"
    subject = "Python email"
    text='<font color="red"><b>' + "BLA BLA BLA" + "</b></font>"
    attachedFiles = list()
    attachedFiles.append("/path/my/file2")
    attachedFiles.append("/path/my/file2")
    sendmail(recipients, subject, text, attachedFiles)        
    use_email_format_html = True
    sendmail(recipients, subject, text, attachedFiles)        

    public by msdn modified Jan 12, 2015  161828  1  6  0

    DecodeBase64: Decode a string encoded using BCrypt's Base64 scheme to a byte array. Note that this is _not_ compatible with the standard MIME-Base64 encoding.

    Decode a string encoded using BCrypt's Base64 scheme to a byte array. Note that this is _not_ compatible with the standard MIME-Base64 encoding. The string to decode The maximum number of bytes to decode An array containing the decoded bytes
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Security.Cryptography;
    using System.Text;
    
    /// <summary>Decode a string encoded using BCrypt's Base64 scheme to a
    /// byte array. Note that this is _not_ compatible with the standard
    /// MIME-Base64 encoding.</summary>
    /// <param name="s">The string to decode</param>
    /// <param name="maximumLength">The maximum number of bytes to decode</param>
    /// <returns>An array containing the decoded bytes</returns>
    private static byte[] DecodeBase64(string s, int maximumLength)
    {
    
        List<byte> bytes = new List<byte>(Math.Min(maximumLength, s.Length));
    
        if (maximumLength <= 0)
        {
            throw new ArgumentOutOfRangeException("maximumLength", maximumLength, null);
        }
    
        for (int offset = 0, slen = s.Length, length = 0; offset < slen - 1 && length < maximumLength; )
        {
            int c1 = Char64(s[offset++]);
            int c2 = Char64(s[offset++]);
            if (c1 == -1 || c2 == -1)
            {
                break;
            }
    
            bytes.Add((byte)((c1 << 2) | ((c2 & 0x30) >> 4)));
            if (++length >= maximumLength || offset >= s.Length)
            {
                break;
            }
    
            int c3 = Char64(s[offset++]);
            if (c3 == -1)
            {
                break;
            }
    
            bytes.Add((byte)(((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2)));
            if (++length >= maximumLength || offset >= s.Length)
            {
                break;
            }
    
            int c4 = Char64(s[offset++]);
            bytes.Add((byte)(((c3 & 0x03) << 6) | c4));
    
            ++length;
        }
    
        return bytes.ToArray();
    }

    public by msdn modified Jan 12, 2015  120560  0  6  0

    EncodeBase64: Encode a byte array using bcrypt's slightly-modified Base64 encoding scheme. Note that this is _not_ compatible with the standard MIME-Base64 encoding.

    Encode a byte array using bcrypt's slightly-modified Base64 encoding scheme. Note that this is _not_ compatible with the standard MIME-Base64 encoding. The byte array to encode The number of bytes to encode A Base64-encoded string
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Security.Cryptography;
    using System.Text;
    
    // Table for Base64 encoding.
    private static readonly char[] base64_code = {
            '.', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
            'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
            'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
            'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
            '6', '7', '8', '9'
        };
    
    /// <summary>Encode a byte array using bcrypt's slightly-modified
    /// Base64 encoding scheme. Note that this is _not_ compatible
    /// with the standard MIME-Base64 encoding.</summary>
    /// <param name="d">The byte array to encode</param>
    /// <param name="length">The number of bytes to encode</param>
    /// <returns>A Base64-encoded string</returns>
    private static string EncodeBase64(byte[] d, int length)
    {
    
        if (length <= 0 || length > d.Length)
        {
            throw new ArgumentOutOfRangeException("length", length, null);
        }
    
        StringBuilder rs = new StringBuilder(length * 2);
    
        for (int offset = 0, c1, c2; offset < length; )
        {
            c1 = d[offset++] & 0xff;
            rs.Append(base64_code[(c1 >> 2) & 0x3f]);
            c1 = (c1 & 0x03) << 4;
            if (offset >= length)
            {
                rs.Append(base64_code[c1 & 0x3f]);
                break;
            }
            c2 = d[offset++] & 0xff;
            c1 |= (c2 >> 4) & 0x0f;
            rs.Append(base64_code[c1 & 0x3f]);
            c1 = (c2 & 0x0f) << 2;
            if (offset >= length)
            {
                rs.Append(base64_code[c1 & 0x3f]);
                break;
            }
            c2 = d[offset++] & 0xff;
            c1 |= (c2 >> 6) & 0x03;
            rs.Append(base64_code[c1 & 0x3f]);
            rs.Append(base64_code[c2 & 0x3f]);
        }
    
        return rs.ToString();
    }

    public by msdn modified Jan 12, 2015  1110  0  7  0

    MakeSingleBranch: Removes all the branches that do not support/hold this part. The result is a mime tree that only contains the branch that owns this specified MimePart.

    Removes all the branches that do not support/hold this part. The result is a mime tree that only contains the branch that owns this specified MimePart. Mimepart used to determine branch to keep.
    using Microsoft.Exchange.Data.Mime;
    using Microsoft.Exchange.Data.TextConverters;
    using Microsoft.Exchange.Data.Transport.Email;
    using StripLink.LinkProcessors;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Text;
    using StripLink.Utilities;
    
    /// <summary>
    /// Removes all the branches that do not support/hold this part. The result is a mime tree that only
    /// contains the branch that owns this specified MimePart.
    /// </summary>
    /// <param name="mimePart">Mimepart used to determine branch to keep.</param>
    public static void MakeSingleBranch(MimePart mimePart)
    {
        // First determine if we are the root part already..
        // If we are then we have traverse the whole tree/branch.
        if (mimePart.Parent == null)
        {
            return;
        }
    
        // Easiest way is to remove all the children and then add the
        // relevant part back.
        // TODO: Check if performance is an issue. I beleive this is all reference based 
        // on the MimeDoc so no actual changes until committed.
        MimePart mimenodeParent = (MimePart)mimePart.Parent;
        mimenodeParent.RemoveAll();
        mimenodeParent.AppendChild(mimePart);
                
        MakeSingleBranch(mimenodeParent);
    }

    public by msdn modified Jan 12, 2015  873  0  6  0

    RemoveAllExceptBody: Removes all other mime parts except the body part provided by EmailMessage.

    Removes all other mime parts except the body part provided by EmailMessage.
    using Microsoft.Exchange.Data.Mime;
    using Microsoft.Exchange.Data.TextConverters;
    using Microsoft.Exchange.Data.Transport.Email;
    using StripLink.LinkProcessors;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Text;
    using StripLink.Utilities;
    
    /// <summary>
    /// Removes all other mime parts except the body part provided by EmailMessage.
    /// </summary>
    /// <param name="message"></param>
    public static void RemoveAllExceptBody(EmailMessage message)
    {
        // Get the body part..
        Body body = message.Body;
    
        if (body == null || body.MimePart == null)
            throw new InvalidOperationException("No body specified");
    
        MakeSingleBranch(body.MimePart);
    }

    public by msdn modified Jan 12, 2015  944  0  6  0

    GetLowerFidelityBodyPart: Finds the lowest fidelity MimePart associated to a Body, normally Text/Plain.

    Finds the lowest fidelity MimePart associated to a Body, normally Text/Plain. The body part that we want to find the lowest fidelity MimePart for.
    using Microsoft.Exchange.Data.Mime;
    using Microsoft.Exchange.Data.TextConverters;
    using Microsoft.Exchange.Data.Transport.Email;
    using StripLink.LinkProcessors;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Text;
    using StripLink.Utilities;
    
    public const string s_TextPlainContentType = "text/plain";
    
    /// <summary>
    /// Finds the lowest fidelity MimePart associated to a Body, normally Text/Plain.
    /// </summary>
    /// <param name="body">The body part that we want to find the lowest fidelity MimePart for.</param>
    /// <returns></returns>
    public static MimePart GetLowerFidelityBodyPart(Body body)
    {
        // Nothing to work with if they are null...
        // Divided here for logging purposes..
        if (body == null)
        {
            return null;
        }
        else if (body.MimePart == null)
        {
    
            return null;
    
        }
        MimePart bodyPart = body.MimePart; ;
    
        // If it is text already, then that's the lowest fidelity..
        if (body.BodyFormat == BodyFormat.Text)
            return body.MimePart;
    
        // Need to find lower fidelity body type at the same level.
        // If no parent, there are no children, so this would be the only
        // part at this level.
        // If it has a parent but the parent is not multipart then this will also
        // be the only child. so:
        //      if (bodyPart.Parent == null || !bodyPart.Parent.IsMultipart)
        // The other option is to simply check that we have no siblings..
        if (bodyPart.PreviousSibling == null && bodyPart.NextSibling == null)
        {
            return bodyPart;
        }
    
        // If we are here then we must have a parent and siblings. Get the parent, find the lowest fidelity..
        IEnumerator<MimeNode> enumer = bodyPart.Parent.GetEnumerator();
        MimePart currentPart;
    
        while (enumer.MoveNext())
        {
            currentPart = (MimePart) enumer.Current;
    
            if (currentPart.ContentType.Equals(s_TextPlainContentType, StringComparison.OrdinalIgnoreCase))
            {
                return currentPart;
            }
        }
    
        return bodyPart;
    }
    • Public Snippets
    • Channels Snippets