You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2015/12/23 03:05:58 UTC
[whimsy.git] [1/1] Commit 1f36969: recover from badly encoded email addrs and generic mime types
Commit 1f369695e4d5940106e8f166c5a44c18da765e3c:
recover from badly encoded email addrs and generic mime types
Branch: refs/heads/secmail
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@apache.org>
------------------------------------------------------------
www/secmail/models/mailbox.rb | +++++++++++ --
www/secmail/views/app.js.rb | +
www/secmail/views/parts.js.rb | ++++ ------
------------------------------------------------------------
46 changes: 31 additions, 15 deletions.
------------------------------------------------------------
diff --git a/www/secmail/models/mailbox.rb b/www/secmail/models/mailbox.rb
index 148cc1b..197c32e 100644
--- a/www/secmail/models/mailbox.rb
+++ b/www/secmail/models/mailbox.rb
@@ -204,9 +204,15 @@ def parse
end
# determine who should be copied on any responses
- cc = []
- cc = mail[:to].value.split(/,\s*/) if mail[:to]
- cc += mail[:cc].value.split(/,\s*/) if mail[:cc]
+ begin
+ cc = []
+ cc = mail[:to].to_s.split(/,\s*/) if mail[:to]
+ cc += mail[:cc].to_s.split(/,\s*/) if mail[:cc]
+ rescue
+ cc = []
+ cc = mail[:to].value.split(/,\s*/) if mail[:to]
+ cc += mail[:cc].value.split(/,\s*/) if mail[:cc]
+ end
# remove secretary and anybody on the to field from the cc list
cc.reject! do |email|
@@ -232,11 +238,23 @@ def parse
# add in attachments
if mail.attachments.length > 0
+
attachments = mail.attachments.map do |attach|
+ # replace generic octet-stream with a more specific one
+ mime = attach.mime_type
+ if mime == 'application/octet-stream'
+ filename = attach.filename.downcase
+ mime = 'application/pdf' if filename.end_with? '.pdf'
+ mime = 'application/png' if filename.end_with? '.png'
+ mime = 'application/gif' if filename.end_with? '.gif'
+ mime = 'application/jpeg' if filename.end_with? '.jpg'
+ mime = 'application/jpeg' if filename.end_with? '.jpeg'
+ end
+
description = {
name: attach.filename,
length: attach.body.to_s.length,
- mime: attach.mime_type
+ mime: mime
}
if description[:name].empty? and attach['Content-ID']
diff --git a/www/secmail/views/app.js.rb b/www/secmail/views/app.js.rb
index 17bf47e..2d7fb10 100644
--- a/www/secmail/views/app.js.rb
+++ b/www/secmail/views/app.js.rb
@@ -3,3 +3,4 @@
require_relative 'index'
require_relative 'parts'
+require_relative 'context-menu'
diff --git a/www/secmail/views/parts.js.rb b/www/secmail/views/parts.js.rb
index 3eaa5a9..21fa5ad 100644
--- a/www/secmail/views/parts.js.rb
+++ b/www/secmail/views/parts.js.rb
@@ -34,11 +34,7 @@ def render
end
end
- _ul.contextMenu ref: 'menu' do
- _li 'burst'
- _li 'file'
- _li 'delete'
- end
+ _ContextMenu
_img.spinner src: '../../rotatingclock-slow2.gif' if @busy
end
@@ -50,7 +46,7 @@ def componentWillMount()
# disable context menu and register mouse and keyboard handlers
def componentDidMount()
- $menu.style.display = :none
+ document.querySelector('.contextMenu').style.display = :none
window.onmousedown = self.window_click
# register keyboard handler on parent window and all frames
@@ -64,10 +60,11 @@ def componentDidMount()
# position and show context menu
def menu(event)
@selected = event.currentTarget.textContent
- $menu.style.left = event.clientX + 'px'
- $menu.style.top = event.clientY + 'px'
- $menu.style.position = :absolute
- $menu.style.display = :block
+ menu = document.querySelector('.contextMenu')
+ menu.style.left = event.clientX + 'px'
+ menu.style.top = event.clientY + 'px'
+ menu.style.position = :absolute
+ menu.style.display = :block
event.preventDefault()
end
@@ -78,7 +75,7 @@ def window_click(event)
return if target.class == 'contextMenu'
target = target.parentNode
end
- $menu.style.display = :none
+ document.querySelector('.contextMenu').style.display = :none
end
def select(event)