mime-js

Create MIME message from browser, fork of https://github.com/ikr0m/mime-js
git clone git://git.defalsify.org/mime-js.git
Log | Files | Refs | LICENSE

commit 2c19a10b4299605b333b14b2d280cc1b828db8e3
parent 942245e45bd45bf48ae401089dbe8ffb74d039ac
Author: Ikrom <ikromur@gmail.com>
Date:   Sat,  9 May 2015 18:03:59 +0500

Removed scala play.

Diffstat:
M.gitignore | 3+--
Dapp/controllers/Application.scala | 13-------------
Dapp/views/index.scala.html | 32--------------------------------
Dbuild.sbt | 8--------
Dconf/application.conf | 59-----------------------------------------------------------
Dconf/routes | 12------------
Ademo/index..html | 28++++++++++++++++++++++++++++
Dproject/build.properties | 2--
Dproject/plugins.sbt | 6------
Dpublic/images/favicon.png | 0
Dpublic/javascripts/mime-js.js | 115-------------------------------------------------------------------------------
Dpublic/stylesheets/main.css | 0
Rpublic/javascripts/base64.js -> src/base64.js | 0
Rapp/assets/javascripts/mime-js.coffee -> src/mime-js.coffee | 0
14 files changed, 29 insertions(+), 249 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -4,6 +4,7 @@ project/target target tmp .history +.directory dist /.idea /*.iml @@ -14,4 +15,3 @@ dist /RUNNING_PID /.settings - -\ No newline at end of file diff --git a/app/controllers/Application.scala b/app/controllers/Application.scala @@ -1,12 +0,0 @@ -package controllers - -import play.api._ -import play.api.mvc._ - -object Application extends Controller { - - def index = Action { - Ok(views.html.index()) - } - -} -\ No newline at end of file diff --git a/app/views/index.scala.html b/app/views/index.scala.html @@ -1,32 +0,0 @@ -<!DOCTYPE html> - -<html> -<head> - <title>MIME JS</title> - <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")"> - <link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")"> - <script src="@routes.Assets.at("javascripts/base64.js")" type="text/javascript"></script> - <script src="@routes.Assets.at("javascripts/mime-js.js")" type="text/javascript"></script> - -</head> -<body> - <b>Mail obj:</b><div id="mail"></div> - <hr> - <div id="mime"></div> - - <script type="application/javascript"> - // To escape `at` symbol in play framework, we use double `at` in email - var mail = { - "to": "email1@@example.com", - "subject": "Today is rainy", - "fromName": "John Smith", - "from": "john.smith@@mail.com", - "body": "Sample body text", - "cids": [], - "attaches" : [] - } - document.getElementById("mail" ).innerText = JSON.stringify(mail); - document.getElementById("mime" ).innerText = createMimeMessage(mail); - </script> -</body> -</html> diff --git a/build.sbt b/build.sbt @@ -1,7 +0,0 @@ -import play.Project._ - -name := "Mime-JS" - -version := "1.0" - -playScalaSettings -\ No newline at end of file diff --git a/conf/application.conf b/conf/application.conf @@ -1,59 +0,0 @@ -# This is the main configuration file for the application. -# ~~~~~ - -# Secret key -# ~~~~~ -# The secret key is used to secure cryptographics functions. -# If you deploy your application to several instances be sure to use the same key! -application.secret="%APPLICATION_SECRET%" - -# The application languages -# ~~~~~ -application.langs="en" - -# Global object class -# ~~~~~ -# Define the Global object class for this application. -# Default to Global in the root package. -# application.global=Global - -# Router -# ~~~~~ -# Define the Router object to use for this application. -# This router will be looked up first when the application is starting up, -# so make sure this is the entry point. -# Furthermore, it's assumed your route file is named properly. -# So for an application router like `my.application.Router`, -# you may need to define a router file `conf/my.application.routes`. -# Default to Routes in the root package (and conf/routes) -# application.router=my.application.Routes - -# Database configuration -# ~~~~~ -# You can declare as many datasources as you want. -# By convention, the default datasource is named `default` -# -# db.default.driver=org.h2.Driver -# db.default.url="jdbc:h2:mem:play" -# db.default.user=sa -# db.default.password="" - -# Evolutions -# ~~~~~ -# You can disable evolutions if needed -# evolutionplugin=disabled - -# Logger -# ~~~~~ -# You can also configure logback (http://logback.qos.ch/), -# by providing an application-logger.xml file in the conf directory. - -# Root logger: -logger.root=ERROR - -# Logger used by the framework: -logger.play=INFO - -# Logger provided to your application: -logger.application=DEBUG - diff --git a/conf/routes b/conf/routes @@ -1,11 +0,0 @@ -# Routes -# This file defines all application routes (Higher priority routes first) -# ~~~~ - -# Home page -GET / controllers.Application.index - -# Map static resources from the /public folder to the /assets URL path -GET /assets/*file controllers.Assets.at(path="/public", file) - - -\ No newline at end of file diff --git a/demo/index..html b/demo/index..html @@ -0,0 +1,28 @@ +<!DOCTYPE html> + +<html> +<head> + <title>MIME JS</title> + <script src="../dist/base64.js" type="text/javascript"></script> + <script src="../dist/mime-js.js" type="text/javascript"></script> +</head> +<body> + <b>Mail obj:</b><div id="mail"></div> + <hr> + <div id="mime"></div> + + <script type="application/javascript"> + var mail = { + "to": "email1@example.com", + "subject": "Today is rainy", + "fromName": "John Smith", + "from": "john.smith@mail.com", + "body": "Sample body text", + "cids": [], + "attaches" : [] + }; + document.getElementById("mail" ).innerText = JSON.stringify(mail); + document.getElementById("mime" ).innerText = createMimeMessage(mail); + </script> +</body> +</html> diff --git a/project/build.properties b/project/build.properties @@ -1 +0,0 @@ -sbt.version=0.13.0 -\ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt @@ -1,5 +0,0 @@ -logLevel := Level.Warn - -resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" - -addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.2.1") -\ No newline at end of file diff --git a/public/images/favicon.png b/public/images/favicon.png Binary files differ. diff --git a/public/javascripts/mime-js.js b/public/javascripts/mime-js.js @@ -1,115 +0,0 @@ - -/* - mime-js.js 0.1 - 2014-10-18 - - By Ikrom, https://github.com/ikr0m - License: X11/MIT -*/ - - -(function() { - - window.createMimeMessage = function(mail) { - var alternative, attaches, cids, createAlternative, createAttaches, createCids, createHtml, createMixed, createPlain, createRelated, getBoundary, htm, plain, related; - getBoundary = function() { - return Math.random().toString(36).slice(2) + Math.random().toString(36).slice(2); - }; - createPlain = function(textContent) { - if (textContent == null) { - textContent = ''; - } - return '\nContent-Type: text/plain; charset=UTF-8' + '\nContent-Transfer-Encoding: base64' + '\n\n' + (Base64.encode(textContent, true)).replace(/.{76}/g, "$&\n"); - }; - createHtml = function(msg) { - var htmlContent; - htmlContent = msg.body || ""; - htmlContent = htmlContent.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/, '&gt;').replace(/\n/g, '\n<br/>'); - htmlContent = '<div>' + htmlContent + '</div>'; - return '\nContent-Type: text/html; charset=UTF-8' + '\nContent-Transfer-Encoding: base64' + '\n\n' + (Base64.encode(htmlContent, true)).replace(/.{76}/g, "$&\n"); - }; - createAlternative = function(text, html) { - var boundary; - boundary = getBoundary(); - return '\nContent-Type: multipart/alternative; boundary=' + boundary + '\n\n--' + boundary + text + '\n\n--' + boundary + html + '\n\n--' + boundary + '--'; - }; - createCids = function(cids) { - var base64, cid, cidArr, id, name, type, _i, _len; - if (!cids) { - return; - } - cidArr = []; - for (_i = 0, _len = cids.length; _i < _len; _i++) { - cid = cids[_i]; - type = cid.type; - name = cid.name; - base64 = cid.base64; - id = getBoundary(); - cidArr.push('\nContent-Type: ' + type + '; name=\"' + name + '\"' + '\nContent-Transfer-Encoding: base64' + '\nContent-ID: <' + id + '>' + '\nX-Attachment-Id: ' + id + '\n\n' + base64); - } - return cidArr; - }; - createRelated = function(alternative, cids) { - var boundary, cid, relatedStr, _i, _len; - if (cids == null) { - cids = []; - } - boundary = getBoundary(); - relatedStr = '\nContent-Type: multipart/related; boundary=' + boundary + '\n\n--' + boundary + alternative; - for (_i = 0, _len = cids.length; _i < _len; _i++) { - cid = cids[_i]; - relatedStr += '\n--' + boundary + cid; - } - return relatedStr + '\n--' + boundary + '--'; - }; - createAttaches = function(attaches) { - var attach, base64, id, name, result, type, _i, _len; - if (!attaches) { - return; - } - result = []; - for (_i = 0, _len = attaches.length; _i < _len; _i++) { - attach = attaches[_i]; - type = attach.type; - name = attach.name; - base64 = attach.base64; - id = getBoundary(); - result.push('\nContent-Type: ' + type + '; name=\"' + name + '\"' + '\nContent-Disposition: attachment; filename=\"' + name + '\"' + '\nContent-Transfer-Encoding: base64' + '\nX-Attachment-Id: ' + id + '\n\n' + base64); - } - return result; - }; - createMixed = function(related, attaches) { - var attach, boundary, date, mailFromName, mimeStr, subject, _i, _len; - if (attaches == null) { - attaches = []; - } - boundary = getBoundary(); - if (mail.subject) { - subject = '=?UTF-8?B?' + Base64.encode(mail.subject, true) + '?='; - } - if (subject == null) { - subject = ''; - } - mailFromName = '=?UTF-8?B?' + Base64.encode(mail.fromName || "", true) + '?='; - date = (new Date().toGMTString()).replace(/GMT|UTC/gi, '+0000'); - mimeStr = 'MIME-Version: 1.0' + '\nDate: ' + date + '\nDelivered-To: ' + mail.to + '\nMessage-ID: <' + getBoundary() + '@mail.your-domain.com>' + '\nSubject: ' + subject + '\nFrom: ' + mailFromName + ' <' + mail.from + '>' + '\nTo: ' + mail.to + '\nContent-Type: multipart/mixed; boundary=' + boundary + '\n\n--' + boundary + related; - for (_i = 0, _len = attaches.length; _i < _len; _i++) { - attach = attaches[_i]; - mimeStr += '\n--' + boundary + attach; - } - return (mimeStr + '\n--' + boundary + '--').replace(/\n/g, '\r\n'); - }; - try { - plain = createPlain(mail.body); - htm = createHtml(mail); - alternative = createAlternative(plain, htm); - cids = createCids(mail.cids); - related = createRelated(alternative, cids); - attaches = createAttaches(mail.attaches); - return createMixed(related, attaches); - } catch (err) { - throw new Error(err); - } - }; - -}).call(this); diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css diff --git a/public/javascripts/base64.js b/src/base64.js diff --git a/app/assets/javascripts/mime-js.coffee b/src/mime-js.coffee