{"action":"created","comment":{"url":"https://api.github.com/repos/google/end-to-end/pulls/comments/33983361","id":33983361,"diff_hunk":"@@ -0,0 +1,198 @@\n+/**\n+ * @license\n+ * Copyright 2015 Google Inc. All rights reserved.\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+/**\n+ * @fileoverview main module for the safe mail app.\n+ * @author yzhu@yahoo-inc.com (Yan Zhu)\n+ */\n+\n+goog.provide('e2e.openpgp.pgpmime.MimeNode');\n+\n+goog.require('e2e.openpgp.pgpmime.Constants');\n+goog.require('e2e.openpgp.pgpmime.Utils');\n+goog.require('goog.array');\n+goog.require('goog.asserts');\n+goog.require('goog.crypt.base64');\n+goog.require('goog.object');\n+goog.require('goog.string');\n+\n+goog.scope(function() {\n+var pgpmime = e2e.openpgp.pgpmime;\n+var constants = pgpmime.Constants;\n+\n+\n+\n+/**\n+ * Constructor for a MIME tree node.\n+ * @param {{\n+ *   multipart: boolean,\n+ *   optionalHeaders: (Array<{name: string, value: string}>|undefined)\n+ * }} options Options to initialize for the node.\n+ * @param {e2e.openpgp.pgpmime.MimeNode=} opt_parent The parent node.\n+ * @param {string=} opt_filename Name of the file, if the node is an attachment\n+ * @constructor\n+ */\n+e2e.openpgp.pgpmime.MimeNode = function(options, opt_parent, opt_filename) {\n+  this.parent = opt_parent || this;\n+  this.filename = opt_filename;\n+  this.multipart_ = options.multipart;\n+\n+  this.children_ = [];\n+  this.header_ = /** @type {e2e.openpgp.pgpmime.types.Header} */ ({});\n+  this.content_ = null;\n+  this.boundary_ = '';\n+\n+  // set optional headers\n+  if (goog.isDefAndNotNull(options.optionalHeaders)) {\n+    goog.array.forEach(options.optionalHeaders, goog.bind(function(header) {\n+      if (goog.isDefAndNotNull(header.name) &&\n+          goog.isDefAndNotNull(header.value)) {\n+        if (goog.isDefAndNotNull(header.params)) {\n+          this.setHeader_(header.name, header.value, header.params);\n+        } else {\n+          this.setHeader_(header.name, header.value);\n+        }\n+      }\n+    }, this));\n+  }\n+\n+  this.setBoundary_();\n+};\n+\n+\n+/**\n+ * Sets the MIME message boundary for a node.\n+ * @private\n+ */\n+e2e.openpgp.pgpmime.MimeNode.prototype.setBoundary_ = function() {\n+  // TODO: Strictly ensure that the boundary value doesn't coincide with\n+  //   any string in the email content and headers.\n+  this.boundary_ = '---' + goog.string.getRandomString() +\n+      Math.floor(Date.now() / 1000).toString();\n+};\n+\n+\n+/**\n+ * Adds a child to a MIME node.\n+ * @param {{\n+ *   multipart: boolean,\n+ *   optionalHeaders: (Array<{name: string, value: string}>|undefined)\n+ * }} options Options to initialize for the node.\n+ * @param {string=} opt_filename Name of the file, if one exists.\n+ * @return {e2e.openpgp.pgpmime.MimeNode}\n+ */\n+e2e.openpgp.pgpmime.MimeNode.prototype.addChild =\n+    function(options, opt_filename) {\n+  var node = new e2e.openpgp.pgpmime.MimeNode(options, this, opt_filename);\n+  this.children_.push(node);\n+  return node;\n+};\n+\n+\n+/**\n+ * Sets a MIME header.\n+ * @param {string} key Name of the header.\n+ * @param {string} value Value of the header, possibly including parameters.\n+ * @param {Object.<string, string>=} opt_params Optional dict of additional\n+ *   parameters\n+ * @private\n+ */\n+e2e.openpgp.pgpmime.MimeNode.prototype.setHeader_ =\n+    function(key, value, opt_params) {\n+  var headerValue = e2e.openpgp.pgpmime.Utils.parseHeaderValue(value);\n+  if (opt_params) {\n+    headerValue.params = headerValue.params || {};\n+    goog.object.extend(headerValue.params, opt_params);\n+  }\n+  goog.object.set(this.header_, key, headerValue);\n+};\n+\n+\n+/**\n+ * Sets the content.\n+ * @param {(string|!e2e.ByteArray)} content The content to set\n+ */\n+e2e.openpgp.pgpmime.MimeNode.prototype.setContent = function(content) {\n+  this.content_ = content;\n+};\n+\n+\n+/**\n+ * Builds an RFC 2822 message from the node and its children.\n+ * @return {string}\n+ */\n+e2e.openpgp.pgpmime.MimeNode.prototype.buildMessage = function() {\n+  var lines = [];\n+  var transferEncoding = this.header_[constants.Mime.CONTENT_TRANSFER_ENCODING];\n+  var contentType = this.header_[constants.Mime.CONTENT_TYPE];\n+\n+  // Set required header fields\n+  if (this.filename && !this.header_[constants.Mime.CONTENT_DISPOSITION]) {\n+    // Set the correct content disposition header for attachments.\n+    this.setHeader_(constants.Mime.CONTENT_DISPOSITION,\n+        constants.Mime.ATTACHMENT, {filename: this.filename});\n+  } else if (this.content_ && goog.typeOf(this.content_) === 'string') {\n+    // sets the charset to utf-8 if the charset hasn't already been specified\n+    contentType.params.charset =\n+        contentType.params.charset || constants.Mime.UTF8;\n+  }\n+  if (this.multipart_) {\n+    // Multipart messages need to specify a boundary\n+    contentType.params.boundary = this.boundary_;\n+  }\n+\n+  // TODO: Wrap header lines at 76 chars\n+  // adds all the headers after serialization (transforming object to string)\n+  // to the lines array\n+  lines = lines.concat(e2e.openpgp.pgpmime.Utils.serializeHeader(this.header_));\n+\n+  // add a newline after the headers (the empty string cell will eventually be\n+  // turned into a newline)\n+  lines.push('');\n+\n+  if (this.content_) {\n+    if (transferEncoding.value === constants.Mime.BASE64 ||\n+        goog.typeOf(this.content_) !== 'string') {\n+      // TODO: Wrap lines at 76 chars","path":"src/javascript/crypto/e2e/openpgp/pgpmime/mimenode.js","position":169,"original_position":169,"commit_id":"ba05751dc4e521d337573424b52794b20b7edb9d","original_commit_id":"ba05751dc4e521d337573424b52794b20b7edb9d","user":{"login":"diracdeltas","id":549654,"avatar_url":"https://avatars.githubusercontent.com/u/549654?v=3","gravatar_id":"","url":"https://api.github.com/users/diracdeltas","html_url":"https://github.com/diracdeltas","followers_url":"https://api.github.com/users/diracdeltas/followers","following_url":"https://api.github.com/users/diracdeltas/following{/other_user}","gists_url":"https://api.github.com/users/diracdeltas/gists{/gist_id}","starred_url":"https://api.github.com/users/diracdeltas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diracdeltas/subscriptions","organizations_url":"https://api.github.com/users/diracdeltas/orgs","repos_url":"https://api.github.com/users/diracdeltas/repos","events_url":"https://api.github.com/users/diracdeltas/events{/privacy}","received_events_url":"https://api.github.com/users/diracdeltas/received_events","type":"User","site_admin":false},"body":"Might as well wrap here too. https://tools.ietf.org/html/rfc2822#section-2.1.1","created_at":"2015-07-06T21:16:09Z","updated_at":"2015-07-06T21:16:09Z","html_url":"https://github.com/google/end-to-end/pull/321#discussion_r33983361","pull_request_url":"https://api.github.com/repos/google/end-to-end/pulls/321","_links":{"self":{"href":"https://api.github.com/repos/google/end-to-end/pulls/comments/33983361"},"html":{"href":"https://github.com/google/end-to-end/pull/321#discussion_r33983361"},"pull_request":{"href":"https://api.github.com/repos/google/end-to-end/pulls/321"}}},"pull_request":{"url":"https://api.github.com/repos/google/end-to-end/pulls/321","id":39306979,"html_url":"https://github.com/google/end-to-end/pull/321","diff_url":"https://github.com/google/end-to-end/pull/321.diff","patch_url":"https://github.com/google/end-to-end/pull/321.patch","issue_url":"https://api.github.com/repos/google/end-to-end/issues/321","number":321,"state":"open","locked":false,"title":"I added a new library to e2e that builds and parses PGP/MIME messages.","user":{"login":"yonigoogle","id":13053383,"avatar_url":"https://avatars.githubusercontent.com/u/13053383?v=3","gravatar_id":"","url":"https://api.github.com/users/yonigoogle","html_url":"https://github.com/yonigoogle","followers_url":"https://api.github.com/users/yonigoogle/followers","following_url":"https://api.github.com/users/yonigoogle/following{/other_user}","gists_url":"https://api.github.com/users/yonigoogle/gists{/gist_id}","starred_url":"https://api.github.com/users/yonigoogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yonigoogle/subscriptions","organizations_url":"https://api.github.com/users/yonigoogle/orgs","repos_url":"https://api.github.com/users/yonigoogle/repos","events_url":"https://api.github.com/users/yonigoogle/events{/privacy}","received_events_url":"https://api.github.com/users/yonigoogle/received_events","type":"User","site_admin":false},"body":"The original library was built by Yan Zhu from yahoo.\r\nI've ported the library to e2e and made a number of changes to the original code.\r\n\r\nThe library will require some more work before it's finished, but I'd appreciate any advice/feedback at this point.\r\nAs of now, the library only supports the building of an outgoing PGP/MIME message.\r\nNext week I'll add the parsing of incoming messages.","created_at":"2015-07-06T20:25:38Z","updated_at":"2015-07-06T21:16:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"db3e8f403522fcf27e0aeab48787d7925abf1360","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/google/end-to-end/pulls/321/commits","review_comments_url":"https://api.github.com/repos/google/end-to-end/pulls/321/comments","review_comment_url":"https://api.github.com/repos/google/end-to-end/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/end-to-end/issues/321/comments","statuses_url":"https://api.github.com/repos/google/end-to-end/statuses/ba05751dc4e521d337573424b52794b20b7edb9d","head":{"label":"yonigoogle:master","ref":"master","sha":"ba05751dc4e521d337573424b52794b20b7edb9d","user":{"login":"yonigoogle","id":13053383,"avatar_url":"https://avatars.githubusercontent.com/u/13053383?v=3","gravatar_id":"","url":"https://api.github.com/users/yonigoogle","html_url":"https://github.com/yonigoogle","followers_url":"https://api.github.com/users/yonigoogle/followers","following_url":"https://api.github.com/users/yonigoogle/following{/other_user}","gists_url":"https://api.github.com/users/yonigoogle/gists{/gist_id}","starred_url":"https://api.github.com/users/yonigoogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yonigoogle/subscriptions","organizations_url":"https://api.github.com/users/yonigoogle/orgs","repos_url":"https://api.github.com/users/yonigoogle/repos","events_url":"https://api.github.com/users/yonigoogle/events{/privacy}","received_events_url":"https://api.github.com/users/yonigoogle/received_events","type":"User","site_admin":false},"repo":{"id":38064938,"name":"end-to-end","full_name":"yonigoogle/end-to-end","owner":{"login":"yonigoogle","id":13053383,"avatar_url":"https://avatars.githubusercontent.com/u/13053383?v=3","gravatar_id":"","url":"https://api.github.com/users/yonigoogle","html_url":"https://github.com/yonigoogle","followers_url":"https://api.github.com/users/yonigoogle/followers","following_url":"https://api.github.com/users/yonigoogle/following{/other_user}","gists_url":"https://api.github.com/users/yonigoogle/gists{/gist_id}","starred_url":"https://api.github.com/users/yonigoogle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yonigoogle/subscriptions","organizations_url":"https://api.github.com/users/yonigoogle/orgs","repos_url":"https://api.github.com/users/yonigoogle/repos","events_url":"https://api.github.com/users/yonigoogle/events{/privacy}","received_events_url":"https://api.github.com/users/yonigoogle/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/yonigoogle/end-to-end","description":"End-To-End is a Chrome extension that helps you encrypt, decrypt, digital sign, and verify signed messages within the browser using OpenPGP.","fork":true,"url":"https://api.github.com/repos/yonigoogle/end-to-end","forks_url":"https://api.github.com/repos/yonigoogle/end-to-end/forks","keys_url":"https://api.github.com/repos/yonigoogle/end-to-end/keys{/key_id}","collaborators_url":"https://api.github.com/repos/yonigoogle/end-to-end/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/yonigoogle/end-to-end/teams","hooks_url":"https://api.github.com/repos/yonigoogle/end-to-end/hooks","issue_events_url":"https://api.github.com/repos/yonigoogle/end-to-end/issues/events{/number}","events_url":"https://api.github.com/repos/yonigoogle/end-to-end/events","assignees_url":"https://api.github.com/repos/yonigoogle/end-to-end/assignees{/user}","branches_url":"https://api.github.com/repos/yonigoogle/end-to-end/branches{/branch}","tags_url":"https://api.github.com/repos/yonigoogle/end-to-end/tags","blobs_url":"https://api.github.com/repos/yonigoogle/end-to-end/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/yonigoogle/end-to-end/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/yonigoogle/end-to-end/git/refs{/sha}","trees_url":"https://api.github.com/repos/yonigoogle/end-to-end/git/trees{/sha}","statuses_url":"https://api.github.com/repos/yonigoogle/end-to-end/statuses/{sha}","languages_url":"https://api.github.com/repos/yonigoogle/end-to-end/languages","stargazers_url":"https://api.github.com/repos/yonigoogle/end-to-end/stargazers","contributors_url":"https://api.github.com/repos/yonigoogle/end-to-end/contributors","subscribers_url":"https://api.github.com/repos/yonigoogle/end-to-end/subscribers","subscription_url":"https://api.github.com/repos/yonigoogle/end-to-end/subscription","commits_url":"https://api.github.com/repos/yonigoogle/end-to-end/commits{/sha}","git_commits_url":"https://api.github.com/repos/yonigoogle/end-to-end/git/commits{/sha}","comments_url":"https://api.github.com/repos/yonigoogle/end-to-end/comments{/number}","issue_comment_url":"https://api.github.com/repos/yonigoogle/end-to-end/issues/comments{/number}","contents_url":"https://api.github.com/repos/yonigoogle/end-to-end/contents/{+path}","compare_url":"https://api.github.com/repos/yonigoogle/end-to-end/compare/{base}...{head}","merges_url":"https://api.github.com/repos/yonigoogle/end-to-end/merges","archive_url":"https://api.github.com/repos/yonigoogle/end-to-end/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/yonigoogle/end-to-end/downloads","issues_url":"https://api.github.com/repos/yonigoogle/end-to-end/issues{/number}","pulls_url":"https://api.github.com/repos/yonigoogle/end-to-end/pulls{/number}","milestones_url":"https://api.github.com/repos/yonigoogle/end-to-end/milestones{/number}","notifications_url":"https://api.github.com/repos/yonigoogle/end-to-end/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/yonigoogle/end-to-end/labels{/name}","releases_url":"https://api.github.com/repos/yonigoogle/end-to-end/releases{/id}","created_at":"2015-06-25T17:54:51Z","updated_at":"2015-06-25T17:54:53Z","pushed_at":"2015-07-06T20:21:15Z","git_url":"git://github.com/yonigoogle/end-to-end.git","ssh_url":"git@github.com:yonigoogle/end-to-end.git","clone_url":"https://github.com/yonigoogle/end-to-end.git","svn_url":"https://github.com/yonigoogle/end-to-end","homepage":"","size":6098,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"3288abc94b3c7b9adc1258a427f779dd584ff50e","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":24910542,"name":"end-to-end","full_name":"google/end-to-end","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/end-to-end","description":"End-To-End is a Chrome extension that helps you encrypt, decrypt, digital sign, and verify signed messages within the browser using OpenPGP.","fork":false,"url":"https://api.github.com/repos/google/end-to-end","forks_url":"https://api.github.com/repos/google/end-to-end/forks","keys_url":"https://api.github.com/repos/google/end-to-end/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/end-to-end/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/end-to-end/teams","hooks_url":"https://api.github.com/repos/google/end-to-end/hooks","issue_events_url":"https://api.github.com/repos/google/end-to-end/issues/events{/number}","events_url":"https://api.github.com/repos/google/end-to-end/events","assignees_url":"https://api.github.com/repos/google/end-to-end/assignees{/user}","branches_url":"https://api.github.com/repos/google/end-to-end/branches{/branch}","tags_url":"https://api.github.com/repos/google/end-to-end/tags","blobs_url":"https://api.github.com/repos/google/end-to-end/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/end-to-end/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/end-to-end/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/end-to-end/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/end-to-end/statuses/{sha}","languages_url":"https://api.github.com/repos/google/end-to-end/languages","stargazers_url":"https://api.github.com/repos/google/end-to-end/stargazers","contributors_url":"https://api.github.com/repos/google/end-to-end/contributors","subscribers_url":"https://api.github.com/repos/google/end-to-end/subscribers","subscription_url":"https://api.github.com/repos/google/end-to-end/subscription","commits_url":"https://api.github.com/repos/google/end-to-end/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/end-to-end/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/end-to-end/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/end-to-end/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/end-to-end/contents/{+path}","compare_url":"https://api.github.com/repos/google/end-to-end/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/end-to-end/merges","archive_url":"https://api.github.com/repos/google/end-to-end/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/end-to-end/downloads","issues_url":"https://api.github.com/repos/google/end-to-end/issues{/number}","pulls_url":"https://api.github.com/repos/google/end-to-end/pulls{/number}","milestones_url":"https://api.github.com/repos/google/end-to-end/milestones{/number}","notifications_url":"https://api.github.com/repos/google/end-to-end/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/end-to-end/labels{/name}","releases_url":"https://api.github.com/repos/google/end-to-end/releases{/id}","created_at":"2014-10-07T20:39:09Z","updated_at":"2015-07-06T01:54:35Z","pushed_at":"2015-07-06T20:25:38Z","git_url":"git://github.com/google/end-to-end.git","ssh_url":"git@github.com:google/end-to-end.git","clone_url":"https://github.com/google/end-to-end.git","svn_url":"https://github.com/google/end-to-end","homepage":"","size":7228,"stargazers_count":2121,"watchers_count":2121,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":161,"mirror_url":null,"open_issues_count":48,"forks":161,"open_issues":48,"watchers":2121,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/end-to-end/pulls/321"},"html":{"href":"https://github.com/google/end-to-end/pull/321"},"issue":{"href":"https://api.github.com/repos/google/end-to-end/issues/321"},"comments":{"href":"https://api.github.com/repos/google/end-to-end/issues/321/comments"},"review_comments":{"href":"https://api.github.com/repos/google/end-to-end/pulls/321/comments"},"review_comment":{"href":"https://api.github.com/repos/google/end-to-end/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/end-to-end/pulls/321/commits"},"statuses":{"href":"https://api.github.com/repos/google/end-to-end/statuses/ba05751dc4e521d337573424b52794b20b7edb9d"}}}}