Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Better workflow for adding contacts from emails #666

Merged
merged 25 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
be5749a
Fix: .gitignore hm3 files
henochit Sep 25, 2023
ffc1898
Fix: conflict
henochit Sep 25, 2023
452d558
Feat: add dropdown arrow image
henochit Jan 14, 2023
75c8e24
Fix: conflict
henochit Sep 25, 2023
1b8f4a5
Refactor (add contact function): split function by adding add contact…
henochit Jan 17, 2023
8db1d68
Fix: conflicts
henochit Sep 25, 2023
e61c3bb
Fix: refactor get contact function
henochit Jul 28, 2023
62dcf96
lint: remove space
henochit Jul 28, 2023
8d10698
Fix: git ignore scripts/hm3.rc
henochit Jul 28, 2023
637f0f3
Fix: git ignore scripts/hm3.ini
henochit Jul 28, 2023
64d1fc2
Fix: conflicts
henochit Sep 25, 2023
8187bad
Fix: conflicts
henochit Sep 25, 2023
5a2d883
Ref: Set simple UI as default
henochit Jul 31, 2023
45b7c9e
Fix: remove imap_per_page_setting from setup.php
henochit Aug 2, 2023
f2dd6a5
Ref: delete untracked files
henochit Aug 2, 2023
ddf3045
Feat: add dropdown on contact bubbles
henochit Aug 4, 2023
7d5eecd
Ref: search contact api
henochit Aug 6, 2023
cdb9880
Feat: implement edit contact dropdown
henochit Aug 6, 2023
c2db4a4
Fix: dropdown actions
henochit Aug 7, 2023
88ff720
Added a way to support sieve extensions
josaphatim Aug 1, 2023
feaf52b
Added a way to check sieve server capabilities
josaphatim Aug 8, 2023
39da55f
Fix: remove duplicated function 'add_contact_from_popup'
henochit Sep 25, 2023
e9de4fa
Fix: conflicts
henochit Sep 25, 2023
6140ef5
Ref: clean session storage on save contact
henochit Oct 17, 2023
2a2a9e0
Fix: remove wrong path in .gitignore
henochit Oct 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ scripts/test.php
*.sublime-workspace
composer.phar
lib/hm3/users/
/scripts/hm3.ini
/scripts/hm3.rc
henochit marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions lib/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ public static function __callStatic(string $method, array $parameters)
public static $trash = 'data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20x%3D%220px%22%20y%3D%220px%22%0D%0Awidth%3D%228%22%20height%3D%228%22%0D%0AviewBox%3D%220%200%2024%2024%22%3E%0D%0A%20%20%20%20%3Cpath%20d%3D%22M%2010%202%20L%209%203%20L%204%203%20L%204%205%20L%207%205%20L%2017%205%20L%2020%205%20L%2020%203%20L%2015%203%20L%2014%202%20L%2010%202%20z%20M%205%207%20L%205%2022%20L%2019%2022%20L%2019%207%20L%205%207%20z%22%3E%3C%2Fpath%3E%0D%0A%3C%2Fsvg%3E';
public static $draft = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAYAAABw4pVUAAAACXBIWXMAAAsTAAALEwEAmpwYAAAEI0lEQVR4nO2dTW7UQBCFn2BWLIEowClga0dhjTThEPkB8ZNkLpQhCgqKlKwQh2CFiJAYOAFixx6SRpZsaWK5Pe6Z7qrq7npSLazOOG1/rmq/GscBVCqVSqXyJ6OBIeeATAoECiTGi4BM3AdqIgkFAn4ICgT8Jz4aIAWAMuNxcUCqyW5kPE4m19TNNcjEfaAmkmAH0q6puW0baUDaNTW3bSMNiAYUiBF8IYjLEG4fUKgP6V9TchsnE3cpMJGEAgE/BFFAuH1AoT7kJhBuH1CqD+EvC0ZwsJcsDcgGwu0DCvUh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gFIUhCMpUM4Ne2xYoCkMQlKlmhhwoU4UhR5sKQ6VSqcCt/0kPcucfMlnUAAAAAElFTkSuQmCC';

public static $arrow_drop_down = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDI0djI0SDBWMHoiLz48cGF0aCBkPSJNNyAxMGw1IDUgNS01SDd6Ii8+PC9zdmc+';
public static $arrow_drop_up = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDI0djI0SDBWMHoiLz48cGF0aCBkPSJNNyAxNGw1LTUgNSA1SDd6Ii8+PC9zdmc+';
}

/**
Expand Down
21 changes: 17 additions & 4 deletions modules/contacts/hm-contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,24 @@ public function add_contact($data) {
return true;
}

public function get($id, $default=false) {
if (!array_key_exists($id, $this->contacts)) {
return $default;
public function get($id, $default=false, $email_address=""){
if(array_key_exists($id, $this->contacts)) {
henochit marked this conversation as resolved.
Show resolved Hide resolved
return $this->contacts[$id];
}
return $this->contacts[$id];

if(!empty($email_address)){
$res = false;
foreach ($this->contacts as $id => $contact) {
if ($contact->value('email_address') == $email_address) {
$res = $contact;
break;
}
}

return $res;
}

return $default;
}

public function search($flds) {
Expand Down
29 changes: 27 additions & 2 deletions modules/contacts/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,37 @@ var delete_contact = function(id, source, type) {
var add_contact_from_message_view = function() {
var contact = $('#add_contact').val();
var source = $('#contact_source').val();

if (contact) {
Hm_Ajax.request(
[
{ name: 'hm_ajax_hook', value: 'ajax_add_contact' },
{ name: 'contact_value', value: contact },
{ name: 'contact_source', value: source },
],
function (res) {
$('.add_contact_controls').toggle();
window.location.reload();
henochit marked this conversation as resolved.
Show resolved Hide resolved
remove_message_content();
}
);
}
};

var add_contact_from_popup = function() {
kroky marked this conversation as resolved.
Show resolved Hide resolved
var source = 'local:local';
var contact = $('#contact_info').text().replace('>','').replace('<','');

if (contact) {
Hm_Ajax.request(
[{'name': 'hm_ajax_hook', 'value': 'ajax_add_contact'},
{'name': 'contact_value', 'value': contact},
{'name': 'contact_source', 'value': source}],
function(res) { $('.add_contact_controls').toggle(); }
function (res) {
$(".popup .show").removeClass('show');
remove_message_content();
window.location.reload();
}
);
}
};
Expand Down Expand Up @@ -60,7 +85,7 @@ var autocomplete_contact = function(e, class_name, list_div) {
$(list_div).html('');
for (i in res.contact_suggestions) {
var suggestion = JSON.parse(res.contact_suggestions[i].replace(/&quot;/g, '"'))

div.html(suggestion.contact);
if ($(class_name).val().match(div.text())) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ function imap_data_sources($callback, $custom=array()) {
}}

/**
* Prepare and format message list data
* Prepare and format message list data
* @subpackage imap/functions
* @param array $msgs list of message headers to format
* @param object $mod Hm_Output_Module
Expand Down
81 changes: 78 additions & 3 deletions modules/imap/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,81 @@ protected function output() {
$value = sprintf('%s (%s)', $dt->format('c Z'), human_readable_interval($value));
} catch (Exception $e) {}
$txt .= '<tr class="header_'.$fld.'"><th>'.$this->trans($name).'</th><td>'.$this->html_safe($value).'</td></tr>';
}
elseif($fld == 'from'){

$regexp = '/\s*(.*[^\s])\s*<\s*(.*[^\s])\s*>/';

$contact_email = "";
$contact_name = "";

if(preg_match($regexp, $value, $matches)){
$contact_name = $matches[1];
$contact_email = $matches[2];
}else{
$EmailRegexp = "/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i";
if(preg_match($EmailRegexp, $value, $matches)){
$contact_email = $matches[0][0];
}
}

$contact = ($this->get('contact_store'))->get(null, false, $contact_email);
$contact_exists = !empty($contact);

$txt .= '<tr class="header_'.$fld.'"><th>'.$this->trans($name).'
</th>
<td>
<div class="popup" onclick="imap_show_add_contact_popup(event)">
<span id="contact_info">' . $this->html_safe($value) . '
</span>
<img alt="" class="icon_arrow_up" src="'.Hm_Image_Sources::$arrow_drop_up.'" width="20" height="20" />
<img alt="" class="icon_arrow_down" src="'.Hm_Image_Sources::$arrow_drop_down.'" width="20" height="20" />
<div class="popup-container" id="contact_popup">
<div class="popup-container_header">
<a onclick="imap_show_add_contact_popup()">x</a>
</div>';

if($contact_exists){
$txt .= '<div>
<table>
<tr>
<td><strong>Name :</strong></td>
<td>
'.$this->html_safe($contact->value('display_name')).'
</td>
</tr>
<tr>
<td><strong>Email :</strong></td>
<td>
'.$this->html_safe($contact->value('email_address')).'
</td>
</tr>
<tr>
<td><strong>Tel :</strong></td>
<td>
<a href="tel:'.$this->html_safe($contact->value('phone_number')).'">'.
$this->html_safe($contact->value('phone_number')).'</a>
</td>
</tr>
<tr>
<td><strong>Source :</strong></td>
<td>
'.$this->html_safe($contact->value('source')).'
</td>
</tr>
</table>
</div>';
} else {
$txt .= '<div class="popup-container_footer">
<button onclick="return add_contact_from_popup()" class="add_contact_btn" type="button" value="">'.$this->trans('Add local contacts').'
</button>
</div>';
}

$txt .= ' </div>
</div>
</td>
</tr>';
}
else {
if (strtolower($name) == 'flags') {
Expand Down Expand Up @@ -234,7 +309,7 @@ protected function output() {
if ($this->get('list_headers')) {
$txt .= format_list_headers($this);
}
$lc_headers = lc_headers($headers);
$lc_headers = lc_headers($headers);
if (array_key_exists('to', $lc_headers)) {
$addr_list = process_address_fld($lc_headers['to']);
$size = count($addr_list);
Expand All @@ -252,7 +327,7 @@ protected function output() {
});
$size += count($addr_list);
}

$txt .= '<tr><td class="header_space" colspan="2"></td></tr>';
$txt .= '<tr><th colspan="2" class="header_links">';
$txt .= '<div class="msg_move_to">'.
Expand Down Expand Up @@ -379,7 +454,7 @@ protected function output() {
$default_value = '';
if (isset($vals['sieve_config_host'])) {
$default_value = $vals['sieve_config_host'];

$res .= '<span><label class="screen_reader" for="imap_sieve_host_'.$index.'">'.$this->trans('Sieve Host').'</label>'.
'<input '.$disabled.' id="imap_sieve_host_'.$index.'" class="credentials imap_sieve_host_input" placeholder="Sieve Host" type="text" name="imap_sieve_host" value="'.$default_value.'"></span>';
}
Expand Down
1 change: 1 addition & 0 deletions modules/imap/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,4 @@
)
);


87 changes: 87 additions & 0 deletions modules/imap/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,90 @@
.snooze_date_picker { display: block; padding: 8px 15px; color: #333; font-size: 1rem; cursor: pointer; }
.unsnooze { color: teal; }
.header_x-snoozed .unsnooze { margin-left: 20px; }


/* Popup container - can be anything you want */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
display: flex;
align-items: center;
}

/* The actual popup */
.popup > .popup-container {
visibility: hidden;
min-width: 250px;
background-color: #fff;
border: 1px #0000004d solid;
box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;
border-radius: 6px;
padding: 5px 10px;
position: absolute;
z-index: 1;
top: 125%;
}

/* Popup arrow */
.popup > .popup-container::after {
content: "";
position: absolute;
bottom: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: transparent transparent #555 transparent;
}

.popup > .icon_arrow_up {
display: none;
}

.popup > .icon_arrow_down {
display: block;
}


/* Toggle this class - hide and show the popup */
.show > .popup-container {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
}

.show > .icon_arrow_up {
display: block;
}

.show > .icon_arrow_down {
display: none;
}

.popup-container_header {
display: flex;
justify-content: end;
margin-bottom: 10px;
}

.popup-container_footer {
display: flex;
justify-content: center;
}


/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}

@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
}
7 changes: 7 additions & 0 deletions modules/imap/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -1260,3 +1260,10 @@ var imap_archive_message = function(state, supplied_uid, supplied_detail) {
}
return false;
};

var imap_show_add_contact_popup = function() {
var popup = document.getElementById("contact_popup");
if(!popup.classList.contains("show")) {
popup.classList.toggle("show");
}
};