* 
 */
if (!defined('CON_FRAMEWORK')) {
    die('Illegal call');
}
$plugin_name = 'newsletter';
$oPage = new cPage();
$oRecipients = new RecipientCollection();
if (is_array($cfg['plugins']['recipients'])) {
    foreach ($cfg['plugins']['recipients'] as $plugin) {
        plugin_include("recipients", $plugin . "/" . $plugin . ".php");
    }
}
// Note, that the object name has to be $recipient for plugins
if ($action == "recipients_create" && $perm->have_perm_area_action($area, $action)) {
    $recipient = $oRecipients->create("*****@*****.**", " " . i18n("-- new recipient --", $plugin_name));
    $oPage->setReload();
} elseif ($action == "recipients_delete" && $perm->have_perm_area_action($area, $action)) {
    $oRecipients->delete($idrecipient);
    $recipient = new Recipient();
    $oPage->setReload();
} elseif ($action == "recipients_purge" && $perm->have_perm_area_action($area, "recipients_delete")) {
    $oClient = new cApiClient($client);
    $timeframe = $oClient->getProperty("newsletter", "purgetimeframe");
    if (!$timeframe) {
        $timeframe = 30;
    }
    $purgedrecipients = $oRecipients->purge($timeframe);
    /* backslashdollar: There is a problem translating \$ - it is either not recognized or translated correctly (using poEdit) */
    if ($purgedrecipients > 0) {
        $sNotis = $notification->messageBox("info", sprintf(str_replace("backslashdollar", "\$", i18n("%1backslashdollard recipients, which hasn't been confirmed since more than %2backslashdollard days has been removed.", $plugin_name)), $purgedrecipients, $timeframe), 0);
     $aInvalidLines[] = $sLine;
     $iInvalid++;
 } else {
     if (!isValidMail($sEMail)) {
         $aMessage[] = sprintf(i18n("Mail address '%s' is invalid, item ignored (row: %s)", $plugin_name), $sEMail, $iRow);
         $aInvalidLines[] = $sLine;
         $iInvalid++;
     } else {
         if ($oRecipients->emailExists($sEMail)) {
             $aMessage[] = sprintf(i18n("Recipient with mail address '%s' already exists, item skipped (row: %s)", $plugin_name), $sEMail, $iRow);
             $aInvalidLines[] = $sLine;
             $iDublettes++;
         } else {
             unset($sLine);
             // Must be $recipient for plugins
             if ($recipient = $oRecipients->create($sEMail, $sName, 0, '', 0, false)) {
                 $iID = $recipient->get($recipient->primaryKey);
                 $iAdded++;
                 unset($aPluginValue);
                 $aPluginValue = array();
                 foreach ($aFieldDetails as $sKey => $aDetails) {
                     if ($aDetails["col"] > -1) {
                         switch ($aDetails["fieldtype"]) {
                             case "field":
                                 switch ($aDetails["type"]) {
                                     case "boolean":
                                         $sValue = strtolower(trim($aParts[$aDetails["col"]]));
                                         // html is only treated as "true", to get html messages for recipients
                                         // - quick and dirty...
                                         if ($sValue == "yes" || $sValue == i18n("yes", $plugin_name) || $sValue == "true" || is_numeric($sValue) && $sValue > 0 || $sValue == "html") {
                                             $recipient->set($sKey, 1);