You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@spamassassin.apache.org by Robert Nicholson <ro...@elastica.com> on 2006/07/18 05:03:39 UTC

Mail::SpamAssassin::Message how to replace a header?

Also, if I have a Mail::SpamAssassin::Message and I want to replace a  
header in the message do I have to do all this myself and reconstruct  
a new message with the new header value?

 From what I can tell this class retains header and body as scalars.

Re: Mail::SpamAssassin::Message how to replace a header?

Posted by Theo Van Dinter <fe...@apache.org>.
On Tue, Jul 18, 2006 at 08:54:03AM -0500, Robert Nicholson wrote:
> Basically I'm processing archived mail thru spamassassin in an  
> attempt to weed out spam. In order to identify it as spam I will be  
> adding a header to the spam. so when I use "re_write" I get back a  
> Mail::SpamAssassin::Message but I then want to add my own header to  
> the message.
> 
>      #$mail->head->replace("X-Accept-Flag", "Spam");
> 
> I know SpamAssassin will add it's own headers but I want to add my  
> own in addition.

The only headers SA lets you add all start with "X-Spam-".  You can
add whatever ones you want, but the prefix is automatically added.
If you want to add/remove/replace other headers, you need to do it in
your own code.

> The rules my Mail client uses do not allow me to use regular  
> expressions which is why
> I need a reliable string that identifies that the mail was in fact  
> considered Spam.

Can you just use the default X-Spam-Flag?  It's value will be "YES"
if the message is considered spam (or "NO" if it isn't).

-- 
Randomly Generated Tagline:
"When I grow up, I want to be a principal or a caterpillar."
 
 	--Ralph Wiggum
 	  The Principal and the Pauper (Episode 4F23)

Re: Mail::SpamAssassin::Message how to replace a header?

Posted by Robert Nicholson <ro...@elastica.com>.
Basically I'm processing archived mail thru spamassassin in an  
attempt to weed out spam. In order to identify it as spam I will be  
adding a header to the spam. so when I use "re_write" I get back a  
Mail::SpamAssassin::Message but I then want to add my own header to  
the message.

f ($status->is_spam())
   {
      my $mail = message_from_string_or_arrayref($rewritten);
      #$mail->head->replace("X-Accept-Flag", "Spam");
      print "$filename is spam\n";
      open (NEW_MESSAGE, ">$filename.new") || die ("Couldn't open  
message $filename
:$!\n");
      print NEW_MESSAGE $first;
      print NEW_MESSAGE $mail->get_pristine;
      close(NEW_MESSAGE);
      exit;
      # backup old msg
      move ($filename, "$filename.backup") || die ("Couldn't move  
message $filename
:$!\n");
      # replace old with new
      move ("$filename.new", "$filename") || die ("Couldn't replace  
message $filena
me:$!\n");
   } else {
      print "$filename is not spam\n";
   }

  I know SpamAssassin will add it's own headers but I want to add my  
own in addition.

The rules my Mail client uses do not allow me to use regular  
expressions which is why
I need a reliable string that identifies that the mail was in fact  
considered Spam.

On Jul 17, 2006, at 10:22 PM, Theo Van Dinter wrote:

> On Mon, Jul 17, 2006 at 10:03:39PM -0500, Robert Nicholson wrote:
>> Also, if I have a Mail::SpamAssassin::Message and I want to replace a
>> header in the message do I have to do all this myself and reconstruct
>> a new message with the new header value?
>>
>> From what I can tell this class retains header and body as scalars.
>
> Can you be a little more specific about what you're trying to do?
>
> Generally speaking, without mucking about manually, which I don't  
> recommend,
> you can't modify the headers in the internal data structure.  You  
> can add and
> you can delete, but there's no modify function.  There's also no  
> way to modify
> the original headers on output, beyond adding in X-Spam-* headers.   
> You can
> take the output from rewrite_mail() and modify it yourself (it's  
> just a
> scalar).
>
> -- 
> Randomly Generated Tagline:
> Know a good chiropractor? My computer has a slipped disk.

Re: Mail::SpamAssassin::Message how to replace a header?

Posted by Theo Van Dinter <fe...@apache.org>.
On Mon, Jul 17, 2006 at 10:03:39PM -0500, Robert Nicholson wrote:
> Also, if I have a Mail::SpamAssassin::Message and I want to replace a  
> header in the message do I have to do all this myself and reconstruct  
> a new message with the new header value?
> 
> From what I can tell this class retains header and body as scalars.

Can you be a little more specific about what you're trying to do?

Generally speaking, without mucking about manually, which I don't recommend,
you can't modify the headers in the internal data structure.  You can add and
you can delete, but there's no modify function.  There's also no way to modify
the original headers on output, beyond adding in X-Spam-* headers.  You can
take the output from rewrite_mail() and modify it yourself (it's just a
scalar).

-- 
Randomly Generated Tagline:
Know a good chiropractor? My computer has a slipped disk.