mime type of the attachment part
420736
def get_content_type(self):
        """"""
        ctype = self.part.get_content_type()
        # replace underspecified mime description by a better guess
        if ctype in ['octet/stream', 'application/octet-stream',
                     'application/octetstream']:
            ctype = guess_mimetype(self.get_data())
        return ctype
370316
def register_mime_type(mime_type, extensions: [], charset: nil)
      extnames = Array(extensions)

      charset ||= :default if mime_type.start_with?('text/')
      charset = EncodingUtils::CHARSET_DETECT[charset] if charset.is_a?(Symbol)

      self.config = hash_reassoc(config, :mime_exts) do |mime_exts|
        extnames.each do |extname|
          mime_exts[extname] = mime_type
        end
        mime_exts
      end

      self.config = hash_reassoc(config, :mime_types) do |mime_types|
        type = { extensions: extnames }
        type[:charset] = charset if charset
        mime_types.merge(mime_type => type)
      end
    end
1346073
def mime_type(self, type_: Optional[MimeType] = None) -> str:
        
        key = self._validate_enum(item=type_, enum=MimeType)
        types = MIME_TYPES[key]
        return self.random.choice(types)
465110
def to_email_attachment(self, filename, filedata, **kw):
        
        maintype = "application"
        subtype = "octet-stream"

        mime_type = mimetypes.guess_type(filename)[0]
        if mime_type is not None:
            maintype, subtype = mime_type.split("/")

        attachment = MIMEBase(maintype, subtype, **kw)
        attachment.set_payload(filedata)
        encoders.encode_base64(attachment)
        attachment.add_header("Content-Disposition",
                              "attachment; filename=%s" % filename)
        return attachment
387295
def guess_type_tag(self, input_bytes, filename):
        
        mime_to_type = {'application/jar': 'jar',
                        'application/java-archive': 'jar',
                        'application/octet-stream': 'data',
                        'application/pdf': 'pdf',
                        'application/vnd.ms-cab-compressed': 'cab',
                        'application/vnd.ms-fontobject': 'ms_font',
                        'application/vnd.tcpdump.pcap': 'pcap',
                        'application/x-dosexec': 'exe',
                        'application/x-empty': 'empty',
                        'application/x-shockwave-flash': 'swf',
                        'application/xml': 'xml',
                        'application/zip': 'zip',
                        'image/gif': 'gif',
                        'text/html': 'html',
                        'image/jpeg': 'jpg',
                        'image/png': 'png',
                        'image/x-icon': 'icon',
                        'text/plain': 'txt'
                        }

        # See what filemagic can determine
        with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as mag:
            mime_type = mag.id_buffer(input_bytes[:1024])
            if mime_type in mime_to_type:
                type_tag = mime_to_type[mime_type]

                # If we get 'data' back look at the filename
                if type_tag == 'data':
                    print 'Info: File -- Trying to Determine Type from filename...'
                    ext = os.path.splitext(filename)[1][1:]
                    if ext in ['mem','vmem']:
                        type_tag = 'mem'
                    else:
                        print 'Alert: Failed to Determine Type for %s' % filename
                        exit(1) # Temp
                return type_tag
            else:
                print 'Alert: Sample Type could not be Determined'
                return 'unknown'
1036875
private function attachFiles(){
        if (count($this->attachments) === 0) {
            return;
        }
        // Get old message parts
        $mimeMessage = $this->message->getBody();
        if (is_string($mimeMessage)) {
            $originalBodyPart = new Mime\Part($mimeMessage);
            $originalBodyPart->type = $mimeMessage != strip_tags($mimeMessage)
                ? Mime\Mime::TYPE_HTML
                : Mime\Mime::TYPE_TEXT;
            // A Mime\Part body will be wraped into a Mime\Message, ensuring we handle a Mime\Message after this point
            $this->setBody($originalBodyPart);
            $mimeMessage = $this->message->getBody();;
        }
        $oldParts = $mimeMessage->getParts();
        // Generate a new Mime\Part for each attachment
        $attachmentParts    = [];
        $info               = new \finfo(FILEINFO_MIME_TYPE);
        foreach ($this->attachments as $key => $attachment) {
            if (! is_file($attachment)) {
                continue; // If checked file is not valid, continue to the next
            }
            // If the key is a string, use it as the attachment name
            $basename = is_string($key) ? $key : basename($attachment);
            $part               = new Mime\Part(fopen($attachment, 'r'));
            $part->id           = $basename;
            $part->filename     = $basename;
            $part->type         = $info->file($attachment);
            $part->encoding     = Mime\Mime::ENCODING_BASE64;
            $part->disposition  = Mime\Mime::DISPOSITION_ATTACHMENT;
            $attachmentParts[]  = $part;
        }
        $body = new Mime\Message();
        $body->setParts(array_merge($oldParts, $attachmentParts));
        $this->message->setBody($body);
    }
203833
public function assembleAttachmentBody()
    {
        $body = array();
        $body[] = "This is a multi-part message in MIME format.";
        $body[] = "--{$this->_uid}";
        $body[] = "Content-Type: text/html; charset=\"utf-8\"";
        $body[] = "Content-Transfer-Encoding: quoted-printable";
        $body[] = "";
        $body[] = quoted_printable_encode($this->_message);
        $body[] = "";
        $body[] = "--{$this->_uid}";

        foreach ($this->_attachments as $attachment) {
            $body[] = $this->getAttachmentMimeTemplate($attachment);
        }

        return implode(PHP_EOL, $body) . '--';
    }
1228285
function findAttachmentParts(struct, attachments) {
        attachments = attachments || [];
        for (let i = 0, len = struct.length, r; i < len; ++i) {
            if (Array.isArray(struct[i])) {
                findAttachmentParts(struct[i], attachments);
            } else {
                if (struct[i].disposition && ['INLINE', 'ATTACHMENT'].indexOf(toUpper(struct[i].disposition.type)) > -1) {
                    attachments.push(struct[i]);
                }
            }
        }
        return attachments;
    }
235872
def mime_type(self, category=None):
        
        category = category if category else self.random_element(
            list(self.mime_types.keys()))
        return self.random_element(self.mime_types[category])
954412
def build_attachment(self, text, target, attachment, thread):
        '''
        '''

        attachment = {
            'as_user': True,
            'text': text,
            'channel': target,
            'attachments': [
                {
                    'fallback': text,
                    'image_url': attachment
                }
            ]
        }
        if thread:
            attachment['thread_ts'] = thread
        return attachment
1010454
function MIME() {

  var self = this;

  this.types = Object.create( null );
  this.extensions = Object.create( null );

  for ( var type in typesData ) {
    var exts = typesData[ type ];
    self.extensions[ type ] = exts;
    exts.forEach( function( ext ) {
        self.types[ ext ] = type;
    });
  }

  this.default = this.types[ 'bin' ];

}
599215
def content_type(self, mime_type: Optional[MimeType] = None) -> str:
        
        fmt = self.__file.mime_type(type_=mime_type)
        return 'Content-Type: {}'.format(fmt)
629170
private String getMIMEType(String path) {
        String extension = getFileExtension(path);

        if (extension == null) {
            return FILE_TRANSFER_BINARY_MIME;
        }

        if ("zip".equals(extension) || "ear".equals(extension) || "war".equals(extension) || "jar".equals(extension) || "eba".equals(extension)) {
            return FILE_TRANSFER_ZIP_MIME;

        } else if ("pax".equals(extension)) {
            return FILE_TRANSFER_PAX_MIME;

        } else if ("gz".equals(extension) || "gzip".equals(extension)) {

            return FILE_TRANSFER_GZIP_MIME;

        } else if ("tar".equals(extension)) {
            return FILE_TRANSFER_TAR_MIME;

        } else if ("txt".equals(extension) || "log".equals(extension) || "trace".equals(extension) || "properties".equals(extension)) {
            return FILE_TRANSFER_TEXT_MIME;

        } else if ("xml".equals(extension) || "xslt".equals(extension) || "xsl".equals(extension)) {
            return FILE_TRANSFER_XML_MIME;

        } else if ("html".equals(extension) || "htm".equals(extension)) {
            return FILE_TRANSFER_HTML_MIME;

        } else {
            return FILE_TRANSFER_BINARY_MIME;
        }
    }
1360454
function(f) {
		var isObj = typeof(f) == 'object' ? true : false,
			mime  = isObj ? f.mime : f,
			kind;
		

		if (isObj && f.alias && mime != 'symlink-broken') {
			kind = 'Alias';
		} else if (this.kinds[mime]) {
			if (isObj && mime === 'directory' && (! f.phash || f.isroot)) {
				kind = 'Root';
			} else {
				kind = this.kinds[mime];
			}
		}
		if (! kind) {
			if (mime.indexOf('text') === 0) {
				kind = 'Text';
			} else if (mime.indexOf('image') === 0) {
				kind = 'Image';
			} else if (mime.indexOf('audio') === 0) {
				kind = 'Audio';
			} else if (mime.indexOf('video') === 0) {
				kind = 'Video';
			} else if (mime.indexOf('application') === 0) {
				kind = 'App';
			} else {
				kind = mime;
			}
		}
		
		return this.messages['kind'+kind] ? this.i18n('kind'+kind) : mime;
	}
1240231
protected static function attachment_mime($file)
	{
		static $mimes = false;

		if ( ! $mimes)
		{
			$mimes = \Config::load('mimes');
		}

		$ext = pathinfo($file, PATHINFO_EXTENSION);

		$mime = \Arr::get($mimes, $ext, 'application/octet-stream');
		is_array($mime) and $mime = reset($mime);

		return $mime;
	}
1117819
function tnef_decode(&$part)
    {
        // @TODO: attachment may be huge, handle body via file
        $body     = $this->get_part_body($part->mime_id);
        $tnef     = new rcube_tnef_decoder;
        $tnef_arr = $tnef->decompress($body);
        $parts    = array();

        unset($body);

        foreach ($tnef_arr as $pid => $winatt) {
            $tpart = new rcube_message_part;

            $tpart->filename        = $this->fix_attachment_name(trim($winatt['name']), $part);
            $tpart->encoding        = 'stream';
            $tpart->ctype_primary   = trim(strtolower($winatt['type']));
            $tpart->ctype_secondary = trim(strtolower($winatt['subtype']));
            $tpart->mimetype        = $tpart->ctype_primary . '/' . $tpart->ctype_secondary;
            $tpart->mime_id         = 'winmail.' . $part->mime_id . '.' . $pid;
            $tpart->size            = $winatt['size'];
            $tpart->body            = $winatt['stream'];

            $parts[] = $tpart;
            unset($tnef_arr[$pid]);
        }

        return $parts;
    }
940549
def _encode_multipart_formdata(self):
        
        def get_content_type(filename):
            "Helper to get MIME type."
            return mimetypes.guess_type(filename)[0] or 'application/octet-stream'

        boundary = '----------ThIs_Is_tHe_b0uNdaRY_%d$' % (time.time())
        logical_lines = []
        for name, value in self.fields:
            if value is None:
                continue
            logical_lines.append('--' + boundary)
            if hasattr(value, "read"):
                filename = getattr(value, "name", str(id(value))+".dat")
                logical_lines.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (
                    name,
                    os.path.basename(filename).replace("'", '_').replace('"', '_')
                ))
                logical_lines.append('Content-Type: %s' % get_content_type(filename))
                logical_lines.append('Content-Transfer-Encoding: binary')
                value = value.read()
            else:
                logical_lines.append('Content-Disposition: form-data; name="%s"' % name)
                logical_lines.append('Content-Type: text/plain; charset="UTF-8"')
                value = fmt.to_utf8(value)
            #logical_lines.append('Content-Length: %d' % len(value))
            logical_lines.append('')
            logical_lines.append(value)
        logical_lines.append('--' + boundary + '--')
        logical_lines.append('')

        body = '\r\n'.join(logical_lines)
        content_type = 'multipart/form-data; boundary=%s' % boundary
        return content_type, body