All Projects → miximka → MimeParser

miximka / MimeParser

Licence: MIT License
Mime parsing in Swift | Relevant RFCs: RFC 822, RFC 2045, RFC 2046

Programming Languages

swift
15916 projects
ruby
36898 projects - #4 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to MimeParser

Ohm-S
A Squeak/Smalltalk implementation of the metaprogramming framework Ohm.
Stars: ✭ 18 (+0%)
Mutual labels:  parsing
Jsonify
♨️A delightful JSON parsing framework.
Stars: ✭ 42 (+133.33%)
Mutual labels:  parsing
pdfmajor
A better PDF Extraction Tool using the latest and fastest python features
Stars: ✭ 19 (+5.56%)
Mutual labels:  parsing
php-binary
A PHP library for parsing structured binary streams.
Stars: ✭ 30 (+66.67%)
Mutual labels:  parsing
statham-schema
Statham is a Python Model Parsing Library for JSON Schema.
Stars: ✭ 21 (+16.67%)
Mutual labels:  parsing
YaccConstructor
Platform for parser generators and other grammarware research and development. GLL, RNGLR, graph parsing algorithms, and many others are included.
Stars: ✭ 36 (+100%)
Mutual labels:  parsing
php-mime-detector
Detect a file's mime type using magic numbers.
Stars: ✭ 20 (+11.11%)
Mutual labels:  mime
Miksilo
The fastest way to build a language
Stars: ✭ 27 (+50%)
Mutual labels:  parsing
CYK-Parser
A CYK parser written in Python 3.
Stars: ✭ 24 (+33.33%)
Mutual labels:  parsing
node-typescript-parser
Parser for typescript (and javascript) files, that compiles those files and generates a human understandable AST.
Stars: ✭ 121 (+572.22%)
Mutual labels:  parsing
loquat
Monadic parser combinators for JavaScript / TypeScript
Stars: ✭ 47 (+161.11%)
Mutual labels:  parsing
kolasu
Kotlin Language Support – AST Library
Stars: ✭ 45 (+150%)
Mutual labels:  parsing
structures
Declarative binary data builder and parser: simple, fast, extensible
Stars: ✭ 29 (+61.11%)
Mutual labels:  parsing
racket-bitsyntax
Erlang-style binaries/bitstrings for Racket
Stars: ✭ 29 (+61.11%)
Mutual labels:  parsing
humanparser
Parse a human name string into salutation, first name, middle name, last name, suffix.
Stars: ✭ 78 (+333.33%)
Mutual labels:  parsing
lua-luaepnf
Extended PEG Notation Format (easy grammars for LPeg)
Stars: ✭ 21 (+16.67%)
Mutual labels:  parsing
ruby-marshal
Haskell library to parse a subset of Ruby objects serialised with Marshal.dump
Stars: ✭ 30 (+66.67%)
Mutual labels:  parsing
json2object
Type safe Haxe/JSON (de)serializer
Stars: ✭ 54 (+200%)
Mutual labels:  parsing
dataconf
Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
Stars: ✭ 40 (+122.22%)
Mutual labels:  parsing
LR
explore different techniques to generate LR(k) parsing code
Stars: ✭ 13 (-27.78%)
Mutual labels:  parsing

Build Status

About

MimeParser is a simple MIME (Multipurpose Internet Mail Extensions) parsing library written in Swift (to learn more about mimes refer to RFC 822, RFC 2045, RFC 2046)

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate MimeParser into your Xcode project using CocoaPods, specify it in your Podfile:

project '<Your Project Name>.xcodeproj'
platform :osx, '10.12'

target 'Test' do
  use_frameworks!
  pod 'MimeParser', '~> 0.1'
end

Then, run the following command:

$ pod install

Usage

Import MimeParser before using it:

import MimeParser

Create parser object:

let parser = MimeParser()

Let this be a simplest mime to be parsed:

let str = """
	Content-Type: text/plain
	
	Test
	"""

You are ready to parse the mime:

let mime = try parser.parse(str)

Returned mime object is a root of the mime tree and provides access to its header fields and content:

public enum MimeContent {
    case body(MimeBody)
    case mixed([Mime])
    case alternative([Mime])
}

public struct MimeHeader {
    public let contentTransferEncoding: ContentTransferEncoding?
    public let contentType: ContentType?
    public let contentDisposition: ContentDisposition?
    public let other: [RFC822HeaderField]
}

if let contentTypeString = mime.header.contentType?.raw {
	print("\(contentTypeString)")
	// "text/plain"
}

if case .body(let body) = mime.content {
	print("\(body.raw)")
	// "Test"
}

Decoded mime's content is simply to retrieve:

let content = try mime.decodedContentData()
// "Test"

License

MimeParser is available under the MIT license. See the LICENSE file for more info.

Contribution

MimeParser is still very simple and incomplete, so pull requests welcome!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].