- if (!$allowed) {
- debug("clobbering attachment $partcount");
- $_->content_type_set('text/plain');
- $_->body_set("[ omitting part $partcount: $allowed ]");
-
- }
-
- $partcount++;
+ if ($message->content_type =~ m|^multipart/alternative|){
+ #according to RFC 1521, the last part is the most 'faithful'
+ while (scalar(@rawparts) && !scalar(@parts)){
+ my $part=pop(@rawparts);
+ if (check_part($part,$dest,$allowed_attachments)){
+ push(@parts,$part);
+ }
+ }
+ } else {
+ my $partcount=1;
+ foreach(@rawparts){
+ my $allowed=check_part($_,$dest,$allowed_attachments );
+ if (!$allowed) {
+ $_->content_type_set('text/plain');
+ $_->body_set("[ omitting part $partcount: $allowed ]");
+
+ }
+ push(@parts,$_);
+ $partcount++;
+ }