[pmg-devel] [PATCH pmg-api 2/4] ruledb disclaimer: if/elsif code cleanup
Dominik Csapak
d.csapak at proxmox.com
Tue Jan 9 14:59:02 CET 2024
by pulling out the text/{html,plain} regex directly in the elsif
condition, since the else there does not do anything
the comment now goes into the top-level else part, but the idea is the
same
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
src/PMG/RuleDB/Disclaimer.pm | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm
index 5eadc6f..24efa8a 100644
--- a/src/PMG/RuleDB/Disclaimer.pm
+++ b/src/PMG/RuleDB/Disclaimer.pm
@@ -165,25 +165,23 @@ sub sign {
last;
}
}
- } elsif ($entity->head->mime_type =~ m{text/}) {
- if ($entity->head->mime_type =~ m{text/(html|plain)}) {
- my $type = $1;
- my $cs = $entity->head->mime_attr("content-type.charset") // 'ascii';
- eval {
- my $encoded = encode($cs, $type eq 'html' ? $html : $text, Encode::FB_CROAK);
- $self->add_data($entity, $encoded);
- };
- # simply ignore if we can't represent the disclainer
- # with that encoding
- if ($@) {
- syslog('info', "%s: adding disclaimer failed (rule: %s)", $logid, $rulename);
- } else {
- syslog('info', "%s: added disclaimer (rule: %s)", $logid, $rulename);
- }
- $found = 1;
+ } elsif ($entity->head->mime_type =~ m{text/(html|plain)}) {
+ my $type = $1;
+ my $cs = $entity->head->mime_attr("content-type.charset") // 'ascii';
+ eval {
+ my $encoded = encode($cs, $type eq 'html' ? $html : $text, Encode::FB_CROAK);
+ $self->add_data($entity, $encoded);
+ };
+ # simply ignore if we can't represent the disclainer
+ # with that encoding
+ if ($@) {
+ syslog('info', "%s: adding disclaimer failed (rule: %s)", $logid, $rulename);
} else {
- # do nothing - unknown format
+ syslog('info', "%s: added disclaimer (rule: %s)", $logid, $rulename);
}
+ $found = 1;
+ } else {
+ # do nothing - unknown format
}
return $found;
--
2.30.2
More information about the pmg-devel
mailing list