Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(Adressbook): change return value
Browse files Browse the repository at this point in the history
* skip isset email
  • Loading branch information
Christian Feitl committed Jul 23, 2021
1 parent 6badb95 commit f52e802
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tine20/Addressbook/Frontend/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ public function removeSpecialChar($opts)
}

/**
* usage: method=Addressbook.importMailList csv=test.csv
* usage: method=Addressbook.importMailList csv=test.csv domain=secondarydomains
*csv file = "listname","listEmailAdress"
* @param $opts
* @return false
* @throws Tinebase_Exception_AccessDenied
Expand All @@ -508,16 +509,17 @@ public function importMailList($opts)
{
$args = $this->_parseArgs($opts);
$csv = $args['csv'];

$config = Tinebase_Config::getInstance()->get(Tinebase_Config::SMTP)->toArray();
$domain = isset($config['secondarydomains']) ? $config['secondarydomains'] : $config['primarydomain'];
if (! $csv) {
return false;
$domain = isset($args['domain']) ? $config[$args['domain']]: $config['primarydomain'];
if (!$csv) {
return 2;
}

$stream = fopen($csv, 'r');
if (!$stream) {
echo "file could not be opened: " . $csv . "\n";
return false;
return 2;
}
while ($line = fgetcsv($stream, 0, ',')) {
$list = Addressbook_Controller_List::getInstance()->search(Tinebase_Model_Filter_FilterGroup::getFilterForModel(
Expand All @@ -530,11 +532,14 @@ public function importMailList($opts)
['name' => $line[0]]));
}

$list->email = $line[1] . '@' . $domain;
if( !isset($list->email) || $list->email === '') {
$list->email = $line[1] . '@' . $domain;
}
$list->list_type = 'MAILINGLIST';
$list->xprops()[Addressbook_Model_List::XPROP_USE_AS_MAILINGLIST] = 1;
Addressbook_Controller_List::getInstance()->update($list);
}
fclose($stream);
return 0;
}
}

0 comments on commit f52e802

Please sign in to comment.