roundcube / roundcubemail

The Roundcube Webmail suite
https://roundcube.net
GNU General Public License v3.0
5.9k stars 1.64k forks source link

set to later: some coding on learning messages as spam/ham #1318

Closed rcubetrac closed 15 years ago

rcubetrac commented 16 years ago

Reported by seansan on 8 Feb 2008 19:54 UTC as Trac ticket #1484762

Some code on adding spamassassin support - maybe as plugin in the future. Want to log the code for future reference - who knows, maybe a future release?

problem at this stage was that running sa-learn from the current user (that RC is run with) is probably not allowed to set spam filters. User server config issue. For the rest is seems to work fine.


// INSERTION STARTS HERE @ move_del.inc line 31

// For testing purposes
$CONFIG[= TRUE;

// ok: ['learn_spam']('learn_spam']) is new config variable
// ok: For testing purposes add it to your main config file as 
// $rcmail_config[= TRUE;
if (!empty($CONFIG['junk_mbox']('learn_spam'])) && !empty($CONFIG[&& 
    isset($CONFIG['learn_spam']('junk_mbox']))) && ($CONFIG[ {

    // todo: Do I need to check other vars like SESSION to confirm current mbox?
    // seems ok
    $source = get_input_value('_mbox', RCUBE_INPUT_POST);

    // todo: Do I need to take _mbox and $target (already fetched in move_del) through checks?
    // todo: Do I need to take _mbox and $target and formaat otherwise so they are comparable with config?
    $s_type = NULL;
    if ($target == $CONFIG['junk_mbox']('learn_spam']==TRUE))
))
      $s_type = 'spam';
    else if ($source == $CONFIG[     $s_type = 'ham';

    if (!is_null($s_type))
    {

      $ret = system("which sa-learn", $retval);

      // todo: Anymore checks to add?
      if ($retval == 0 && file_exists($ret) && is_executable($ret))
      {

        // convert the list of uids to array
        $a_uids = is_string($uids) ? explode(',', $uids) : (is_array($uids) ? $uids : NULL);

        foreach ($a_uids as $uid)
        {

        // todo: Does this get the full e-mail, inlcuding headers?
        // todo: The IMAP function is referenced, how to call correctly?
        $src = $IMAP->get_raw_body($uid);

        // create tmpfile to feed to sa-learn
        $temp_dir = unslashify($CONFIG['temp_dir']('junk_mbox'])
));
        $tmpfname = $INSTALL_PATH . tempnam($temp_dir, 'SAL');

          if ($fp = @fopen($tmpfname, 'a'))
          {
            fwrite($fp, $src);
            fwrite($fp, "TEST");
            fclose($fp);

            // todo: Can we fork this process? (Seeing we are looping)
            // todo: How safe is this command and do we need to use escapeshellarg
            // todo: Is this the way to feed the full message source to sa-learn?
            $ret = system(escapeshellcmd(sprintf("sa-learn --no-sync --%s -f %s", $s_type, $tmpfname)), $retval);

            raise_error(array('code' => 701,'type' => 'server','file' => 'move_del.inc', 'line' => __LINE__,
            'message' => $ret), true, false);

            unlink($tmpfname);

          } else {

            raise_error(array('code' => 701,'type' => 'server','file' => move_del.inc, 'line' => __LINE__,
            'message' => "Cannot create temporary file, exiting loop:". $tmpfname), true, false);

            // Stop the loop
            break;
          }

        // sync sa-learn
        $ret = system(escapeshellcmd('sa-learn --sync'), $retval);

        }
      } else {

        raise_error(array('code' => 701,'type' => 'server','file' => move_del.inc, 'line' => __LINE__,
        'message' => "sa-learn not found, verify or turn config variable learn_spam to FALSE"), true, false);

      }
    } else {

        raise_error(array('code' => 701,'type' => 'server','file' => move_del.inc, 'line' => __LINE__,
        'message' => "Source and target both not spam directory"), true, false);
    }
  } else {

    raise_error(array('code' => 701,'type' => 'server','file' => move_del.inc, 'line' => __LINE__,
    'message' => "Config variables not set, skipping sa-learn plugin"), true, false);
  }

  // INSERTION ENDS HERE

_Keywords: spam filter spamassassin movedel Migrated-From: http://trac.roundcube.net/ticket/1484762

rcubetrac commented 16 years ago

Comment by @till on 9 Feb 2008 16:18 UTC

@Sean Which O.S. are you on? Windows, MacOSX, Linux? If you are not a coder, I know it can be a huge burdon, but generally for example Aptana (Eclipse-based) has SVN integration and a nifty tool to create patches. Those help us a lot.

If you don't want a full-flexed IDE like Aptana, there should be tools that create what's called a diff. You want a unified diff between the original file, and your edited outcome.

rcubetrac commented 15 years ago

Comment by @alecpl on 9 Oct 2009 10:23 UTC

This is definetly work for a plugin. Probably possible extending mark as junk plugin.

rcubetrac commented 15 years ago

Status changed by @alecpl on 9 Oct 2009 10:23 UTC

new => closed