Discussion:
[Mimedefang] replace_entire_message() help
Michael Fox
2017-11-17 15:46:00 UTC
Permalink
I need some help with the replace_entire_message() function. Apologies in
advance if the problem is my novice perl knowledge.

Assume $entity is the existing entity and $new_entity is the newly built
entity.

1) When building $new_entity, does every field need to be included? Or will
extra info be copied from the existing $entity? For example, suppose I have
the following in filter_end():

$new_entity = MIME::Entity->build(
Subject => $foo,
Data => $bar,
);

Do I also need to specifically set Bcc, Cc, Date, From, Message-ID, etc.
equal to the corresponding $entity values? Or will the extra fields be
copied from $entity?


2) I can't figure out how to replace the Subject header - even with a
string literal. For example, suppose I have the following in filter_end():

$new_subject = 'Replacement Subject';
$new_body = 'Replacement Body';
$new_entity = MIME::Entity->build(
Type => 'text/plain',
Subject => $new_subject,
Data => $new_body,
);
replace_entire_message($new_entity);

What comes through the filter (received in the user's mailbox) is a
text/plain message with the original subject and the replacement body. What
am I doing wrong?

Thanks,
Michael



_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman
Dianne Skoll
2017-11-17 16:00:53 UTC
Permalink
On Fri, 17 Nov 2017 07:46:00 -0800
Post by Michael Fox
1) When building $new_entity, does every field need to be included?
Yes.
Post by Michael Fox
Or will extra info be copied from the existing $entity?
No, unless you arrange for that in your code.
Post by Michael Fox
2) I can't figure out how to replace the Subject header - even with a
string literal. For example, suppose I have the following in
You can't replace top-level headers this way. You need to use
action_change_header(...)
Post by Michael Fox
What comes through the filter (received in the user's mailbox) is a
text/plain message with the original subject and the replacement
body. What am I doing wrong?
See above!

Regards,

Dianne.
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roaringpenguin.c
Michael Fox
2017-11-17 16:34:50 UTC
Permalink
Post by Dianne Skoll
Post by Michael Fox
1) When building $new_entity, does every field need to be included?
Yes.
Post by Michael Fox
2) I can't figure out how to replace the Subject header - even with a
You can't replace top-level headers this way. You need to use
action_change_header(...)
Thanks Dianne.

But I guess I'm misunderstanding something fundamental because I don't understand how those two answers are not in conflict with each other.

In other words, if the top-level headers can't be replaced by new values in the MIME::Entity->build() method, then why do I still need to include them when building the new entity?

Perhaps you meant I need to include all header fields if they are part of a body part in a multi-part message? Again, pardon if my nomenclature/phraseology isn't exactly correct.

Thanks,
Michael



_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roari
Dianne Skoll
2017-11-17 16:38:46 UTC
Permalink
On Fri, 17 Nov 2017 08:34:50 -0800
Post by Michael Fox
In other words, if the top-level headers can't be replaced by new
values in the MIME::Entity->build() method, then why do I still need
to include them when building the new entity?
Ah, I guess you don't. But I'd do it anyway just for the sake of sanity
and consistency. As you point out later, if you attach sub-entities to the
parent entity, they need the headers fully-specified.

Regards,

Dianne.
_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID. You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list ***@lists.roaringpenguin.com
http://lists.roari

Loading...