* @copyright 2004-2007 The SquirrelMail Project Team, Alexandros Vellis * @package plugins * @subpackage avelsieve */ /** Includes */ include_once(SM_PATH . 'functions/identity.php'); /** * Display available filtering commands for current message. */ function avelsieve_commands_menu_do() { global $passed_id, $passed_ent_id, $color, $mailbox, $message, $compose_new_win, $javascript_on; sq_bindtextdomain('avelsieve', SM_PATH . 'plugins/avelsieve/locale'); textdomain ('avelsieve'); $output = array(); $filtercmds = array( 'auto' => array( 'algorithm' => 'auto', 'desc' => _("Automatically") ), 'sender' => array( 'algorithm' => 'address', 'desc' => _("Sender") ), 'from' => array( 'algorithm' => 'address', 'desc' => _("From") ), 'to' => array( 'algorithm' => 'address', 'desc' => _("To") ), 'subject' => array( 'algorithm' => 'header', 'desc' => _("Subject") ) /* 'priority' => array( 'algorithm' => 'header', 'desc' => _("Priority") ) */ ); $hdr = &$message->rfc822_header; /* Have identities handy to check for our email addresses in automatic * algorithm mode */ $idents = get_identities(); $myemails = array(); foreach($idents as $identity) { $myemails[] = strtolower($identity['email_address']); } foreach($filtercmds as $c => $i) { $url = '../plugins/avelsieve/edit.php?addnew=1&type=1'; switch($i['algorithm']) { case 'address': if(isset($hdr->$c) && !empty($hdr->$c)) { if(is_array($hdr->$c)) { for($j=0; $j$c); $j++) { $url .= '&cond['.$j.'][type]=address'; $url .= '&cond['.$j.'][address]='.ucfirst($c); $url .= '&cond['.$j.'][matchtype]=contains'; $url .= '&cond['.$j.'][addressmatch]='.urlencode( $hdr->{$c}[$j]->mailbox.'@'.$hdr->{$c}[$j]->host); } } else { $j=0; $url .= '&cond['.$j.'][type]=address'; $url .= '&cond['.$j.'][address]='.ucfirst($c); $url .= '&cond['.$j.'][matchtype]=contains'; $url .= '&cond['.$j.'][addressmatch]='.urlencode( $hdr->{$c}->mailbox.'@'.$hdr->{$c}->host); } } else { unset($url); } break; case 'header': if(isset($hdr->$c) && !empty($hdr->$c)) { $j=0; $url .= '&cond['.$j.'][type]=header'; $url .= '&cond['.$j.'][header]='.ucfirst($c); $url .= '&cond['.$j.'][matchtype]=contains'; $url .= '&cond['.$j.'][headermatch]='.rawurlencode(decodeHeader($hdr->$c, false, false)); /* TODO: Probably use $utfdecode = true instead of false in the * above function call of decodeHeader() (second argument). */ } break; case 'auto': if(isset($hdr->mlist['id']) && isset($hdr->mlist['id']['href'])) { /* List-Id: (href) */ $url .= '&cond[0][type]=header'; $url .= '&cond[0][header]=List-Id'. '&cond[0][matchtype]=contains'. '&cond[0][headermatch]='.rawurlencode( $hdr->mlist['id']['href'] ); } elseif(isset($hdr->mlist['id']) && isset($hdr->mlist['id']['mailto'])) { /* List-Id: (mailto) */ $url .= '&cond[0][type]=header'; $url .= '&cond[0][header]=List-Id'. '&cond[0][matchtype]=contains'. '&cond[0][headermatch]='.rawurlencode( $hdr->mlist['id']['mailto'] ); } elseif(isset($hdr->sender) && !empty($hdr->sender)) { /* Sender: */ $url .= '&cond[0][type]=address'; $url .= '&cond[0][address]=Sender'. '&cond[0][matchtype]=contains'. '&cond[0][addressmatch]='.rawurlencode($hdr->sender->mailbox.'@'.$hdr->sender->host); } else { $j = 0; /* Special check for To: Header */ /* FIXME - probably this is not such a good idea. */ if(isset($hdr->to) && !empty($hdr->to)) { /* To:, not including one of my identities*/ for($k=0; $kto); $k++) { $tempurl = ''; if(!in_array($hdr->to[$k]->mailbox.'@'.$hdr->to[$k]->host,$myemails)) { $tempurl .= '&cond['.$j.'][type]=address'. '&cond['.$j.'][address]=toorcc'. '&cond['.$j.'][matchtype]=contains'. '&cond['.$j.'][addressmatch]='.rawurlencode($hdr->to[$k]->mailbox.'@'.$hdr->to[$k]->host); $j++; } } } if($j > 0) { $url .= $tempurl; } else { /* The above method failed, continue with one of these: */ if(isset($hdr->from) && !empty($hdr->from)) { /* From: */ for($k=0; $kfrom); $k++) { $url .= '&cond[0][type]=address'. '&cond[0][address]=From'. '&cond[0][matchtype]=contains'. '&cond[0][addressmatch]='.rawurlencode($hdr->from[$k]->mailbox.'@'.$hdr->from[$k]->host); } } elseif(isset($hdr->subject) && !empty($hdr->subject)) { /* Subject */ $url .= '&cond[0][type]=header'. '&cond[0][header]=Subject'. '&cond[0][matchtype]=contains'. '&cond[0][headermatch]='.rawurlencode($hdr->subject); } } } break; } if(isset($url)) { if(!$compose_new_win) { /* For non-popup page we need this to come back here. */ $url .= '&passed_id='.$passed_id.'&mailbox='.urlencode($mailbox). (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); } if ($compose_new_win == '1') { $url .= '&popup=1'; } if ($compose_new_win == '1') { if($javascript_on) { $output[] = "".$i['desc'].''; } else { $output[] = ''.$i['desc'].''; } } else { $output[] = ''.$i['desc'].''; } } unset($url); } if (count($output) > 0) { echo ''; echo html_tag('td', '' . _("Create Filter") . ':  ', 'right', '', 'valign="middle" width="20%"') . "\n"; echo html_tag('td', '' . implode(' | ', $output) . '', 'left', $color[0], 'valign="middle" width="80%"') . "\n"; echo ''; } sq_bindtextdomain('squirrelmail', SM_PATH . 'locale'); textdomain ('squirrelmail'); }