Skip to content

Commit

Permalink
Adding bulk-import accounts using csv sample file (#976)
Browse files Browse the repository at this point in the history
* Adding multiple server connection using csv sample file
  • Loading branch information
Shadow243 authored Sep 12, 2024
1 parent 6723ab2 commit 315dd1a
Show file tree
Hide file tree
Showing 28 changed files with 608 additions and 73 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"paragonie/random_compat": "^2.0.18",
"php": ">=8.1",
"symfony/dotenv": "^4.3 || 5.4",
"symfony/yaml": "~6.4.3",
"thomaspark/bootswatch": "^5.3",
"twbs/bootstrap": "^5.3",
"twbs/bootstrap-icons": "^1.11",
Expand Down
153 changes: 152 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions language/az.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,4 +636,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/de.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/es.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/et.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,4 +641,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/fa.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,4 +685,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/fr.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/hu.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/id.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/it.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/ja.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/pt-BR.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/ro.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/ru.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
2 changes: 2 additions & 0 deletions language/zh-Hans.php
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,6 @@
'Server capabilities' => false,
'Capabilities' => false,
'Screen %s first emails' => false,
'Yaml File' => false,
'Please ensure your YAML or CSV file follows the correct format' => false,
);
14 changes: 14 additions & 0 deletions modules/core/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,17 @@ function get_special_folders($mod, $id) {
}
return array();
}

/**
* @subpackage core/functions
*/
if (!hm_exists('check_file_upload')) {
function check_file_upload($request, $key) {
if (!is_array($request->files) || !array_key_exists($key, $request->files)) {
return false;
}
if (!is_array($request->files[$key]) || !array_key_exists('tmp_name', $request->files[$key])) {
return false;
}
return true;
}}
19 changes: 13 additions & 6 deletions modules/imap/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ function parse_sieve_config_host($host) {
}}

if (!hm_exists('connect_to_imap_server')) {
function connect_to_imap_server($address, $name, $port, $user, $pass, $tls, $imap_sieve_host, $enableSieve, $type, $context, $hidden = false, $server_id = false) {
function connect_to_imap_server($address, $name, $port, $user, $pass, $tls, $imap_sieve_host, $enableSieve, $type, $context, $hidden = false, $server_id = false, $show_errors = true) {
$imap_list = array(
'name' => $name,
'server' => $address,
Expand Down Expand Up @@ -1563,15 +1563,20 @@ function connect_to_imap_server($address, $name, $port, $user, $pass, $tls, $ima
$context->user_config->get('enable_sieve_filter_setting', DEFAULT_ENABLE_SIEVE_FILTER)) {
try {

include APP_PATH.'modules/sievefilters/hm-sieve.php';
include_once APP_PATH.'modules/sievefilters/hm-sieve.php';
$sieveClientFactory = new Hm_Sieve_Client_Factory();
$client = $sieveClientFactory->init(null, $server);

if (!$client) {
if (!$client && $show_errors) {
Hm_Msgs::add("ERRFailed to authenticate to the Sieve host");
}
} catch (Exception $e) {
Hm_Msgs::add("ERRFailed to authenticate to the Sieve host");
if ($show_errors) {
Hm_Msgs::add("ERRFailed to authenticate to the Sieve host");
}
if (! $server_id) {
Hm_IMAP_List::del($imap_server_id);
}
return;
}
}
Expand All @@ -1580,9 +1585,11 @@ function connect_to_imap_server($address, $name, $port, $user, $pass, $tls, $ima

if (imap_authed($imap)) {
return $imap_server_id;
}else {
} else {
Hm_IMAP_List::del($imap_server_id);
Hm_Msgs::add('ERRAuthentication failed');
if ($show_errors) {
Hm_Msgs::add('ERRAuthentication failed');
}
return null;
}
}
Expand Down
3 changes: 3 additions & 0 deletions modules/nux/assets/data/server_accounts_sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
server_name;username;password;jmap_server;jmap_hide_from_combined_view;imap_server;imap_port;imap_tls;imap_hide_from_combined_view;smtp_server;smtp_port;smtp_tls;sieve_host;sieve_port;profile_reply_to;profile_signature;profile_is_default
Mailbox 1;[email protected];secret;;FALSE;imap.example.org;993;TRUE;FALSE;smtp.example.org;465;TRUE;tls://imap.exemple.org;4190;[email protected];;FALSE
Mailbox 2;[email protected];secret2;jmap.example2.org;FALSE;;;;;smtp.example2.org;465;TRUE;tls://jmap.example2.org;4190;[email protected];my-signature;TRUE
Loading

0 comments on commit 315dd1a

Please sign in to comment.