Skip to content

Commit

Permalink
Merge branch 'release/v1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sadikay committed Jul 13, 2017
2 parents 3bfd5b6 + a1dd14b commit a9a9462
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 28 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ A simple dockerized rails app to manage your emails and campaigns with taggings.

**Inbox Management:**
* Email inbox parsing and email macthing.
* Delete, archive emails from inbox.
* Add tags, and campaign-user tags directly from inbox
* Quick template responses from directly from inbox

Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ $( document ).ready(function() {
function reply_template_select(){
$('#body').val($('#reply_email_template').val());
}

function archiveSpinner(message_icon_id) {
var elm = document.getElementById(message_icon_id);
elm.className = "fa fa-spinner fa-spin";
}
30 changes: 30 additions & 0 deletions app/controllers/inbox_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class InboxController < ApplicationController
require 'net/imap'
before_action :set_imap_settings, only: :index
before_action :set_message_uid, only: [:add_to_archive, :delete_message]

def index
if params[:from].present? && params[:to].present?
Expand All @@ -17,6 +19,7 @@ def detail
@email = params[:email]
@has_attach = params[:has_attachments]
@user = current_account.users.find_by(email: @email)
@message_id = params[:message_id]

if @user.present?
if params[:cu_id].present?
Expand All @@ -40,7 +43,34 @@ def reply_email
UserMailer.reply_email(mail_to, subject, content, smtp_id).deliver_now
end

def add_to_archive
if @uid.present?
@imap.create('Archive') unless @imap.list('', 'Archive')
@imap.copy(@uid.try(:first), 'Archive')
@imap.store(@uid.try(:first), "+FLAGS", [:Deleted])
end
@imap.expunge
@imap.disconnect
end

def delete_message
@imap.store(@uid.try(:first), "+FLAGS", [:Deleted]) if @uid.present?
@imap.expunge
@imap.disconnect
end

private
# for adding to archive and delete
def set_message_uid
settings = current_account.imap_settings.find_by(id: params[:imap_id]) || current_account.imap_settings.first
@message_id = params[:message_id]

@imap = Net::IMAP.new(settings.address, settings.port, usessl: true, ssl: true)
@imap.login(settings.email, settings.password)

@imap.select("Inbox")
@uid = @imap.search(["HEADER", "Message-ID", @message_id])
end

# To read emails
def set_imap_settings
Expand Down
63 changes: 37 additions & 26 deletions app/views/inbox/_detail.html.haml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
.row
.col-sm-12
.panel.panel-default
.panel-heading Reply Email
.panel-body
= form_tag reply_email_inbox_index_path, method: :post, remote: true, id: 'reply-form' do
.col-md-12
= text_area_tag 'body', nil, rows: 5, placeholder: 'Write a reply... (recommended: HTML)', class: 'form-control'
= hidden_field_tag 'mail_to', @email
= hidden_field_tag 'subject', @subject

.col-md-12
.col-md-8
.col-md-6
Select an email template:
= select_tag 'reply_email_template', options_for_select(current_account.email_templates.map{|et| [ et.subject, et.body.html_safe ]}), onchange: 'reply_template_select()', include_blank: '- select -', class: 'form-control'
.col-md-6
Select SMTP Settings
= select_tag 'smtp_id', options_for_select(current_account.smtp_settings.map{|ss| [ ss.provider, ss.id ]}, current_account.smtp_settings.default_for_reply.try(:id)), include_blank: false, class: 'form-control'
.col-md-4.text-right
= submit_tag 'Send Message', id: 'reply-submit', class: 'btn btn-success', style: 'margin-top: 8%;'
.col-md-12
#message-status.text-center.text-success

.col-sm-12
- if user.present?
.panel.panel-default
Expand Down Expand Up @@ -45,39 +68,27 @@
%td= attr.key
%td= attr.value



.row
.col-sm-12
.panel.panel-default
.panel-heading
= @subject
%strong= @email
.panel-heading.clearfix
.pull-left
= @subject
%strong= @email
.pull-right.form-group
= form_tag(add_to_archive_inbox_index_path, method: 'post', remote: true) do
= hidden_field_tag 'message_id', @message_id
= hidden_field_tag 'imap_id', params[:imap_id]
= button_tag type: 'submit', class: 'btn btn-default btn-xs', onclick: "archiveSpinner('archiveIcon-#{@message_id}')" do
Add To Archive
%i.fa.fa-bookmark-o{id: "archiveIcon-#{@message_id}"}
= link_to delete_message_inbox_index_path(message_id: @message_id, imap_id: params[:imap_id]), class: 'btn btn-default btn-xs', onclick: "archiveSpinner('trashIcon-#{@message_id}')", method: :post, remote: true, data: { confirm: 'Are you sure to delete email?' } do
Delete
%i.fa.fa-trash-o{id: "trashIcon-#{@message_id}"}
.panel-body
- if @has_attach == 'true'
%p.text-warning
%i.fa.fa-exclamation-triangle
This email has an attachment.

= simple_format(@message, {}, :sanitize => false)


= form_tag reply_email_inbox_index_path, method: :post, remote: true, id: 'reply-form' do
.col-md-12
= text_area_tag 'body', nil, rows: 5, placeholder: 'Write a reply... (recommended: HTML)', class: 'form-control'
= hidden_field_tag 'mail_to', @email
= hidden_field_tag 'subject', @subject

.col-md-12
.col-md-8
.col-md-6
Select an email template:
= select_tag 'reply_email_template', options_for_select(current_account.email_templates.map{|et| [ et.subject, et.body.html_safe ]}), onchange: 'reply_template_select()', include_blank: '- select -', class: 'form-control'
.col-md-6
Select SMTP Settings
= select_tag 'smtp_id', options_for_select(current_account.smtp_settings.map{|ss| [ ss.provider, ss.id ]}, current_account.smtp_settings.default_for_reply.try(:id)), include_blank: false, class: 'form-control'
.col-md-4.text-right
= submit_tag 'Send Message', id: 'reply-submit', class: 'btn btn-success', style: 'margin-top: 8%;'
.col-md-12

#message-status.text-center.text-success
2 changes: 2 additions & 0 deletions app/views/inbox/add_to_archive.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var elm = document.getElementById("archiveIcon-<%= @message_id %>");
elm.className = "fa fa-bookmark";
3 changes: 3 additions & 0 deletions app/views/inbox/delete_message.js.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$('#email-detail').html('');
var elm = document.getElementById("message-panel-<%= @message_id %>");
elm.remove();
5 changes: 3 additions & 2 deletions app/views/inbox/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
.col-sm-4{style: "max-height: 700px; overflow: scroll;"}
.row
- @emails.each do |message|
.col-sm-12
.col-sm-12{id: "message-panel-#{message.message_id}"}
= form_tag(detail_inbox_index_path, method: 'post', remote: true) do
= button_tag :submit, style: 'all: unset; cursor: pointer; width: 100%;' do
.panel.panel-default
Expand All @@ -43,8 +43,9 @@
- campaign_user_id = /(?<=\bcampaign_user_id_)(\w+)/.match(message.to_s).to_s.presence || /(?<=\bcampaign_user_id_)(\w+)/.match(display_part).to_s
- email = message.from.first
= hidden_field_tag 'message', display_part.force_encoding("UTF-8")
= hidden_field_tag 'message_id', message.message_id
= hidden_field_tag 'email', email
= hidden_field_tag 'subject', message.subject
= hidden_field_tag 'has_attachments', message.attachments.present?
= hidden_field_tag 'cu_id', campaign_user_id
.col-sm-8#email-detail
.col-sm-8#email-detail
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@

resources :inbox do
collection do
post :add_to_archive
post :reply_email
post :detail
post :delete_message
end
end

Expand Down

0 comments on commit a9a9462

Please sign in to comment.