Class: Mailscope::MessagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Mailscope::MessagesController
- Defined in:
- app/controllers/mailscope/messages_controller.rb
Constant Summary collapse
- TRUTHY =
%w[1 true t yes y on].freeze
Instance Method Summary collapse
- #attachment ⇒ Object
- #body ⇒ Object
- #clear ⇒ Object
- #destroy ⇒ Object
- #download ⇒ Object
- #index ⇒ Object
- #show ⇒ Object
- #source ⇒ Object
-
#status ⇒ Object
Cheap endpoint the browser polls to notice new mail.
Instance Method Details
#attachment ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/mailscope/messages_controller.rb', line 59 def found = @message.(params[:attachment_id]) return head :not_found unless found bytes = @message.(found.id) return head :not_found unless bytes send_data bytes, filename: found.filename, type: found.content_type.presence || 'application/octet-stream', disposition: (found) ? 'inline' : 'attachment' end |
#body ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/mailscope/messages_controller.rb', line 36 def body renderer = BodyRenderer.new(@message, part: params[:part], block_remote: block_remote?, theme: params[:theme]) response.headers['Content-Security-Policy'] = renderer.content_security_policy response.headers['X-Mailscope-Blocked-Resources'] = renderer.blocked_resources.to_s response.headers['X-Frame-Options'] = 'SAMEORIGIN' response.headers['Cache-Control'] = 'no-store' render html: renderer.document.html_safe, layout: false end |
#clear ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'app/controllers/mailscope/messages_controller.rb', line 81 def clear removed = storage.clear respond_to do |format| format.json { render json: { ok: true, removed: removed, revision: storage.revision } } format.any { redirect_to root_path, status: :see_other } end end |
#destroy ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/controllers/mailscope/messages_controller.rb', line 72 def destroy storage.delete(@message.id) respond_to do |format| format.json { render json: { ok: true, revision: storage.revision } } format.any { redirect_to root_path(filter_params), status: :see_other } end end |
#download ⇒ Object
52 53 54 55 56 57 |
# File 'app/controllers/mailscope/messages_controller.rb', line 52 def download send_data @message.raw, filename: "#{@message.id}.eml", type: 'message/rfc822', disposition: 'attachment' end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/controllers/mailscope/messages_controller.rb', line 9 def index load_index @message ||= @messages.first respond_to do |format| format.html { render :index } format.json { render json: index_payload } end end |
#show ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/mailscope/messages_controller.rb', line 19 def show load_index respond_to do |format| format.html do # The pane is fetched on its own by the front-end; a full page load # (no JS, opened in a new tab) still renders the whole UI. if pane_request? render partial: 'mailscope/messages/pane', locals: { message: @message }, layout: false else render :index end end format.json { render json: @message.to_h } end end |
#source ⇒ Object
48 49 50 |
# File 'app/controllers/mailscope/messages_controller.rb', line 48 def source render plain: @message.raw, content_type: 'text/plain' end |
#status ⇒ Object
Cheap endpoint the browser polls to notice new mail.
91 92 93 94 |
# File 'app/controllers/mailscope/messages_controller.rb', line 91 def status response.headers['Cache-Control'] = 'no-store' render json: { revision: storage.revision, count: storage.all.size } end |