{"action":"created","comment":{"url":"https://api.github.com/repos/sergi/mime-multipart/pulls/comments/28139069","id":28139069,"diff_hunk":"@@ -1,37 +1,74 @@\n var uuid = require('node-uuid');\n var CRLF = '\\r\\n';\n \n+function compact(array) {\n+  var results = [];\n+\n+  function truthy(element) {\n+    return typeof element !== 'undefined' && element !== null;\n+  }\n+\n+  array.forEach(function(element) {\n+    if (truthy(element)) {\n+      results.push(element);\n+    }\n+  });\n+  return results;\n+}\n+\n function generate(tuples, options) {\n+  if (tuples.length === 0) {\n+    // according to rfc1341 there should be at least one encapsulation\n+    return undefined;\n+  }\n+\n   options = options || {};\n+  var from = options.from;\n+  var preamble = options.preamble;\n+  var epilogue = options.epilogue;\n   var boundary = options.boundary || uuid();\n+\n+  if (boundary.length > 70) {\n+    // rfc defines boundary to be between 1 and 70 characters long.\n+    return undefined;\n+  }\n+\n   var headers = [\n-    'From: ' + (options.from || ('nobody ' + Date())),\n+    'From: ' + (from || ('nobody ' + Date())),\n     'MIME-Version: 1.0',\n-    'Content-Type:multipart/mixed; boundary=' + boundary\n+    'Content-Type: multipart/mixed; boundary=\"' + boundary + '\"',\n   ];\n \n-  var delimiter = '--' + boundary;\n+  var delimiter = CRLF + '--' + boundary;\n   var closeDelimiter = delimiter + '--';\n \n-  var parts = tuples.map(function(tuple, i) {\n+  var encapsulations = tuples.map(function(tuple, i) {\n     var mimetype = tuple.mime || 'text/plain';\n-    var encoding = tuple.encoding || 'utf8';\n+    var encoding = tuple.encoding || 'utf-8';\n     var filename = tuple.filename || ('file' + i);\n-    var fileHeaders = [\n+\n+    var headers = [\n       'MIME-Version: 1.0',\n       'Content-Type: ' + mimetype + '; charset=\"' + encoding + '\"',\n       'Content-Transfer-Encoding: 7bit',\n       'Content-Disposition: attachment; filename=\"' + filename + '\"',\n-    ].join(CRLF) + CRLF;\n+    ];\n \n-    return [delimiter, fileHeaders, tuple.content].join(CRLF);\n+    var bodyPart = headers.join(CRLF) + CRLF + CRLF + tuple.content;\n+\n+    var encapsulation = delimiter + CRLF + bodyPart;\n+\n+    return encapsulation;","path":"index.js","position":69,"original_position":69,"commit_id":"31399c64cba90f903ff6457e81ae3052ebee2a18","original_commit_id":"31399c64cba90f903ff6457e81ae3052ebee2a18","user":{"login":"sergi","id":30396,"avatar_url":"https://avatars.githubusercontent.com/u/30396?v=3","gravatar_id":"","url":"https://api.github.com/users/sergi","html_url":"https://github.com/sergi","followers_url":"https://api.github.com/users/sergi/followers","following_url":"https://api.github.com/users/sergi/following{/other_user}","gists_url":"https://api.github.com/users/sergi/gists{/gist_id}","starred_url":"https://api.github.com/users/sergi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergi/subscriptions","organizations_url":"https://api.github.com/users/sergi/orgs","repos_url":"https://api.github.com/users/sergi/repos","events_url":"https://api.github.com/users/sergi/events{/privacy}","received_events_url":"https://api.github.com/users/sergi/received_events","type":"User","site_admin":false},"body":"Let's just return `delimiter + CRLF + bodyPart`. No need for `encapsulation variable.","created_at":"2015-04-10T12:00:44Z","updated_at":"2015-04-10T12:00:44Z","html_url":"https://github.com/sergi/mime-multipart/pull/6#discussion_r28139069","pull_request_url":"https://api.github.com/repos/sergi/mime-multipart/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/sergi/mime-multipart/pulls/comments/28139069"},"html":{"href":"https://github.com/sergi/mime-multipart/pull/6#discussion_r28139069"},"pull_request":{"href":"https://api.github.com/repos/sergi/mime-multipart/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/sergi/mime-multipart/pulls/6","id":33036259,"html_url":"https://github.com/sergi/mime-multipart/pull/6","diff_url":"https://github.com/sergi/mime-multipart/pull/6.diff","patch_url":"https://github.com/sergi/mime-multipart/pull/6.patch","issue_url":"https://api.github.com/repos/sergi/mime-multipart/issues/6","number":6,"state":"open","locked":false,"title":"Brownbag","user":{"login":"shadone","id":25523,"avatar_url":"https://avatars.githubusercontent.com/u/25523?v=3","gravatar_id":"","url":"https://api.github.com/users/shadone","html_url":"https://github.com/shadone","followers_url":"https://api.github.com/users/shadone/followers","following_url":"https://api.github.com/users/shadone/following{/other_user}","gists_url":"https://api.github.com/users/shadone/gists{/gist_id}","starred_url":"https://api.github.com/users/shadone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shadone/subscriptions","organizations_url":"https://api.github.com/users/shadone/orgs","repos_url":"https://api.github.com/users/shadone/repos","events_url":"https://api.github.com/users/shadone/events{/privacy}","received_events_url":"https://api.github.com/users/shadone/received_events","type":"User","site_admin":false},"body":"Commit of shame. Previous pull requests were not entirely correct, I believe this is a more conformant version","created_at":"2015-04-10T10:47:17Z","updated_at":"2015-04-10T12:00:44Z","closed_at":null,"merged_at":null,"merge_commit_sha":"287a42c3c5ea9f8bb1e9e92a0cdc4bf55e53e1b7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sergi/mime-multipart/pulls/6/commits","review_comments_url":"https://api.github.com/repos/sergi/mime-multipart/pulls/6/comments","review_comment_url":"https://api.github.com/repos/sergi/mime-multipart/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sergi/mime-multipart/issues/6/comments","statuses_url":"https://api.github.com/repos/sergi/mime-multipart/statuses/31399c64cba90f903ff6457e81ae3052ebee2a18","head":{"label":"shadone:brownbag","ref":"brownbag","sha":"31399c64cba90f903ff6457e81ae3052ebee2a18","user":{"login":"shadone","id":25523,"avatar_url":"https://avatars.githubusercontent.com/u/25523?v=3","gravatar_id":"","url":"https://api.github.com/users/shadone","html_url":"https://github.com/shadone","followers_url":"https://api.github.com/users/shadone/followers","following_url":"https://api.github.com/users/shadone/following{/other_user}","gists_url":"https://api.github.com/users/shadone/gists{/gist_id}","starred_url":"https://api.github.com/users/shadone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shadone/subscriptions","organizations_url":"https://api.github.com/users/shadone/orgs","repos_url":"https://api.github.com/users/shadone/repos","events_url":"https://api.github.com/users/shadone/events{/privacy}","received_events_url":"https://api.github.com/users/shadone/received_events","type":"User","site_admin":false},"repo":{"id":33688672,"name":"mime-multipart","full_name":"shadone/mime-multipart","owner":{"login":"shadone","id":25523,"avatar_url":"https://avatars.githubusercontent.com/u/25523?v=3","gravatar_id":"","url":"https://api.github.com/users/shadone","html_url":"https://github.com/shadone","followers_url":"https://api.github.com/users/shadone/followers","following_url":"https://api.github.com/users/shadone/following{/other_user}","gists_url":"https://api.github.com/users/shadone/gists{/gist_id}","starred_url":"https://api.github.com/users/shadone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shadone/subscriptions","organizations_url":"https://api.github.com/users/shadone/orgs","repos_url":"https://api.github.com/users/shadone/repos","events_url":"https://api.github.com/users/shadone/events{/privacy}","received_events_url":"https://api.github.com/users/shadone/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shadone/mime-multipart","description":"Library to help creating Mime Multi Part Archives","fork":true,"url":"https://api.github.com/repos/shadone/mime-multipart","forks_url":"https://api.github.com/repos/shadone/mime-multipart/forks","keys_url":"https://api.github.com/repos/shadone/mime-multipart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shadone/mime-multipart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shadone/mime-multipart/teams","hooks_url":"https://api.github.com/repos/shadone/mime-multipart/hooks","issue_events_url":"https://api.github.com/repos/shadone/mime-multipart/issues/events{/number}","events_url":"https://api.github.com/repos/shadone/mime-multipart/events","assignees_url":"https://api.github.com/repos/shadone/mime-multipart/assignees{/user}","branches_url":"https://api.github.com/repos/shadone/mime-multipart/branches{/branch}","tags_url":"https://api.github.com/repos/shadone/mime-multipart/tags","blobs_url":"https://api.github.com/repos/shadone/mime-multipart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shadone/mime-multipart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shadone/mime-multipart/git/refs{/sha}","trees_url":"https://api.github.com/repos/shadone/mime-multipart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shadone/mime-multipart/statuses/{sha}","languages_url":"https://api.github.com/repos/shadone/mime-multipart/languages","stargazers_url":"https://api.github.com/repos/shadone/mime-multipart/stargazers","contributors_url":"https://api.github.com/repos/shadone/mime-multipart/contributors","subscribers_url":"https://api.github.com/repos/shadone/mime-multipart/subscribers","subscription_url":"https://api.github.com/repos/shadone/mime-multipart/subscription","commits_url":"https://api.github.com/repos/shadone/mime-multipart/commits{/sha}","git_commits_url":"https://api.github.com/repos/shadone/mime-multipart/git/commits{/sha}","comments_url":"https://api.github.com/repos/shadone/mime-multipart/comments{/number}","issue_comment_url":"https://api.github.com/repos/shadone/mime-multipart/issues/comments{/number}","contents_url":"https://api.github.com/repos/shadone/mime-multipart/contents/{+path}","compare_url":"https://api.github.com/repos/shadone/mime-multipart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shadone/mime-multipart/merges","archive_url":"https://api.github.com/repos/shadone/mime-multipart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shadone/mime-multipart/downloads","issues_url":"https://api.github.com/repos/shadone/mime-multipart/issues{/number}","pulls_url":"https://api.github.com/repos/shadone/mime-multipart/pulls{/number}","milestones_url":"https://api.github.com/repos/shadone/mime-multipart/milestones{/number}","notifications_url":"https://api.github.com/repos/shadone/mime-multipart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shadone/mime-multipart/labels{/name}","releases_url":"https://api.github.com/repos/shadone/mime-multipart/releases{/id}","created_at":"2015-04-09T19:37:45Z","updated_at":"2015-04-09T19:37:45Z","pushed_at":"2015-04-10T10:45:06Z","git_url":"git://github.com/shadone/mime-multipart.git","ssh_url":"git@github.com:shadone/mime-multipart.git","clone_url":"https://github.com/shadone/mime-multipart.git","svn_url":"https://github.com/shadone/mime-multipart","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"sergi:master","ref":"master","sha":"b82dcd0e625b044b62aae7bca1960b9d4cca2f31","user":{"login":"sergi","id":30396,"avatar_url":"https://avatars.githubusercontent.com/u/30396?v=3","gravatar_id":"","url":"https://api.github.com/users/sergi","html_url":"https://github.com/sergi","followers_url":"https://api.github.com/users/sergi/followers","following_url":"https://api.github.com/users/sergi/following{/other_user}","gists_url":"https://api.github.com/users/sergi/gists{/gist_id}","starred_url":"https://api.github.com/users/sergi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergi/subscriptions","organizations_url":"https://api.github.com/users/sergi/orgs","repos_url":"https://api.github.com/users/sergi/repos","events_url":"https://api.github.com/users/sergi/events{/privacy}","received_events_url":"https://api.github.com/users/sergi/received_events","type":"User","site_admin":false},"repo":{"id":33668564,"name":"mime-multipart","full_name":"sergi/mime-multipart","owner":{"login":"sergi","id":30396,"avatar_url":"https://avatars.githubusercontent.com/u/30396?v=3","gravatar_id":"","url":"https://api.github.com/users/sergi","html_url":"https://github.com/sergi","followers_url":"https://api.github.com/users/sergi/followers","following_url":"https://api.github.com/users/sergi/following{/other_user}","gists_url":"https://api.github.com/users/sergi/gists{/gist_id}","starred_url":"https://api.github.com/users/sergi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergi/subscriptions","organizations_url":"https://api.github.com/users/sergi/orgs","repos_url":"https://api.github.com/users/sergi/repos","events_url":"https://api.github.com/users/sergi/events{/privacy}","received_events_url":"https://api.github.com/users/sergi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sergi/mime-multipart","description":"Library to help creating Mime Multi Part Archives","fork":false,"url":"https://api.github.com/repos/sergi/mime-multipart","forks_url":"https://api.github.com/repos/sergi/mime-multipart/forks","keys_url":"https://api.github.com/repos/sergi/mime-multipart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sergi/mime-multipart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sergi/mime-multipart/teams","hooks_url":"https://api.github.com/repos/sergi/mime-multipart/hooks","issue_events_url":"https://api.github.com/repos/sergi/mime-multipart/issues/events{/number}","events_url":"https://api.github.com/repos/sergi/mime-multipart/events","assignees_url":"https://api.github.com/repos/sergi/mime-multipart/assignees{/user}","branches_url":"https://api.github.com/repos/sergi/mime-multipart/branches{/branch}","tags_url":"https://api.github.com/repos/sergi/mime-multipart/tags","blobs_url":"https://api.github.com/repos/sergi/mime-multipart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sergi/mime-multipart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sergi/mime-multipart/git/refs{/sha}","trees_url":"https://api.github.com/repos/sergi/mime-multipart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sergi/mime-multipart/statuses/{sha}","languages_url":"https://api.github.com/repos/sergi/mime-multipart/languages","stargazers_url":"https://api.github.com/repos/sergi/mime-multipart/stargazers","contributors_url":"https://api.github.com/repos/sergi/mime-multipart/contributors","subscribers_url":"https://api.github.com/repos/sergi/mime-multipart/subscribers","subscription_url":"https://api.github.com/repos/sergi/mime-multipart/subscription","commits_url":"https://api.github.com/repos/sergi/mime-multipart/commits{/sha}","git_commits_url":"https://api.github.com/repos/sergi/mime-multipart/git/commits{/sha}","comments_url":"https://api.github.com/repos/sergi/mime-multipart/comments{/number}","issue_comment_url":"https://api.github.com/repos/sergi/mime-multipart/issues/comments{/number}","contents_url":"https://api.github.com/repos/sergi/mime-multipart/contents/{+path}","compare_url":"https://api.github.com/repos/sergi/mime-multipart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sergi/mime-multipart/merges","archive_url":"https://api.github.com/repos/sergi/mime-multipart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sergi/mime-multipart/downloads","issues_url":"https://api.github.com/repos/sergi/mime-multipart/issues{/number}","pulls_url":"https://api.github.com/repos/sergi/mime-multipart/pulls{/number}","milestones_url":"https://api.github.com/repos/sergi/mime-multipart/milestones{/number}","notifications_url":"https://api.github.com/repos/sergi/mime-multipart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sergi/mime-multipart/labels{/name}","releases_url":"https://api.github.com/repos/sergi/mime-multipart/releases{/id}","created_at":"2015-04-09T12:51:37Z","updated_at":"2015-04-09T21:35:07Z","pushed_at":"2015-04-10T10:47:17Z","git_url":"git://github.com/sergi/mime-multipart.git","ssh_url":"git@github.com:sergi/mime-multipart.git","clone_url":"https://github.com/sergi/mime-multipart.git","svn_url":"https://github.com/sergi/mime-multipart","homepage":null,"size":0,"stargazers_count":1,"watchers_count":1,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/sergi/mime-multipart/pulls/6"},"html":{"href":"https://github.com/sergi/mime-multipart/pull/6"},"issue":{"href":"https://api.github.com/repos/sergi/mime-multipart/issues/6"},"comments":{"href":"https://api.github.com/repos/sergi/mime-multipart/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/sergi/mime-multipart/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/sergi/mime-multipart/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sergi/mime-multipart/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/sergi/mime-multipart/statuses/31399c64cba90f903ff6457e81ae3052ebee2a18"}}}}