* [pmg-devel] [PATCH pmg-api 1/4] ruledb disclaimer: cleanup trailing whitespace
2024-01-09 13:59 [pmg-devel] [PATCH pmg-api/gui] ruledb disclaimer improvements Dominik Csapak
@ 2024-01-09 13:59 ` Dominik Csapak
2024-01-12 15:47 ` [pmg-devel] applied: " Thomas Lamprecht
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 2/4] ruledb disclaimer: if/elsif code cleanup Dominik Csapak
` (4 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Dominik Csapak @ 2024-01-09 13:59 UTC (permalink / raw)
To: pmg-devel
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/PMG/RuleDB/Disclaimer.pm | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm
index c6afe54..5eadc6f 100644
--- a/src/PMG/RuleDB/Disclaimer.pm
+++ b/src/PMG/RuleDB/Disclaimer.pm
@@ -31,7 +31,7 @@ sub otype_text {
}
sub oisedit {
- return 1;
+ return 1;
}
sub final {
@@ -50,13 +50,13 @@ _EOD_
sub new {
my ($type, $value, $ogroup) = @_;
-
+
my $class = ref($type) || $type;
$value //= $std_discl;
-
+
my $self = $class->SUPER::new($class->otype(), $ogroup);
-
+
$self->{value} = $value;
return $self;
@@ -64,17 +64,17 @@ sub new {
sub load_attr {
my ($type, $ruledb, $id, $ogroup, $value) = @_;
-
+
my $class = ref($type) || $type;
defined($value) || die "undefined object attribute: ERROR";
-
+
my $obj = $class->new(decode('UTF-8', $value), $ogroup);
$obj->{id} = $id;
$obj->{digest} = Digest::SHA::sha1_hex($id, $value, $ogroup);
-
+
return $obj;
}
@@ -91,9 +91,9 @@ sub save {
if (defined ($self->{id})) {
# update
-
+
$ruledb->{dbh}->do(
- "UPDATE Object SET Value = ? WHERE ID = ?",
+ "UPDATE Object SET Value = ? WHERE ID = ?",
undef, $value, $self->{id});
} else {
@@ -104,14 +104,14 @@ sub save {
"VALUES (?, ?, ?);");
$sth->execute($self->ogroup, $self->otype, $value);
-
- $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
+
+ $self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
}
-
+
return $self->{id};
}
-sub add_data {
+sub add_data {
my ($self, $entity, $data) = @_;
$entity->bodyhandle || return undef;
@@ -122,14 +122,14 @@ sub add_data {
if (my $path = $entity->{PMX_decoded_path}) {
$fh = IO::File->new("<$path");
} else {
- $fh = $entity->open("r");
+ $fh = $entity->open("r");
}
return undef if !$fh;
# in memory (we can't modify the file, because
# a.) that would modify all entities (see ModGroup)
- # b.) bad performance
+ # b.) bad performance
my $body = new MIME::Body::InCore || return undef;
my $newfh = $body->open ("w") || return undef;
@@ -190,7 +190,7 @@ sub sign {
}
sub execute {
- my ($self, $queue, $ruledb, $mod_group, $targets,
+ my ($self, $queue, $ruledb, $mod_group, $targets,
$msginfo, $vars, $marks) = @_;
my $rulename = encode('UTF-8', $vars->{RULE} // 'unknown');
@@ -212,7 +212,7 @@ sub execute {
$parser->parse($tmp);
$parser->eof;
-
+
$self->sign($entity, "$html\n", "$text\n", $queue->{logid}, $rulename);
return;
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [pmg-devel] [PATCH pmg-api 2/4] ruledb disclaimer: if/elsif code cleanup
2024-01-09 13:59 [pmg-devel] [PATCH pmg-api/gui] ruledb disclaimer improvements Dominik Csapak
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 1/4] ruledb disclaimer: cleanup trailing whitespace Dominik Csapak
@ 2024-01-09 13:59 ` Dominik Csapak
2024-01-12 15:47 ` [pmg-devel] applied: " Thomas Lamprecht
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 3/4] fix #2606: ruledb disclaimer: add ability to add on top Dominik Csapak
` (3 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Dominik Csapak @ 2024-01-09 13:59 UTC (permalink / raw)
To: pmg-devel
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@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
^ permalink raw reply [flat|nested] 10+ messages in thread
* [pmg-devel] applied: [PATCH pmg-api 2/4] ruledb disclaimer: if/elsif code cleanup
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 2/4] ruledb disclaimer: if/elsif code cleanup Dominik Csapak
@ 2024-01-12 15:47 ` Thomas Lamprecht
0 siblings, 0 replies; 10+ messages in thread
From: Thomas Lamprecht @ 2024-01-12 15:47 UTC (permalink / raw)
To: Dominik Csapak, pmg-devel
Am 09/01/2024 um 14:59 schrieb Dominik Csapak:
> 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@proxmox.com>
> ---
> src/PMG/RuleDB/Disclaimer.pm | 32 +++++++++++++++-----------------
> 1 file changed, 15 insertions(+), 17 deletions(-)
>
>
applied this one already, thanks!
^ permalink raw reply [flat|nested] 10+ messages in thread
* [pmg-devel] [PATCH pmg-api 3/4] fix #2606: ruledb disclaimer: add ability to add on top
2024-01-09 13:59 [pmg-devel] [PATCH pmg-api/gui] ruledb disclaimer improvements Dominik Csapak
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 1/4] ruledb disclaimer: cleanup trailing whitespace Dominik Csapak
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 2/4] ruledb disclaimer: if/elsif code cleanup Dominik Csapak
@ 2024-01-09 13:59 ` Dominik Csapak
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 4/4] fix #2430: ruledb disclaimer: make separator configurable Dominik Csapak
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Dominik Csapak @ 2024-01-09 13:59 UTC (permalink / raw)
To: pmg-devel
there are usecases, where one wants to embed a disclaimer (or similar)
text or html at the beginning of the mail content, not at the end.
so introduce a 'top' parameter for the disclaimer that does exactly
that. we save it in the `Attribut` table when set.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/PMG/RuleDB/Disclaimer.pm | 51 ++++++++++++++++++++++++++++++++----
1 file changed, 46 insertions(+), 5 deletions(-)
diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm
index 24efa8a..95e8b31 100644
--- a/src/PMG/RuleDB/Disclaimer.pm
+++ b/src/PMG/RuleDB/Disclaimer.pm
@@ -49,7 +49,7 @@ If this e-mail or attached files contain information which do not relate to our
_EOD_
sub new {
- my ($type, $value, $ogroup) = @_;
+ my ($type, $value, $ogroup, $top) = @_;
my $class = ref($type) || $type;
@@ -58,6 +58,7 @@ sub new {
my $self = $class->SUPER::new($class->otype(), $ogroup);
$self->{value} = $value;
+ $self->{top} = $top;
return $self;
}
@@ -69,7 +70,20 @@ sub load_attr {
defined($value) || die "undefined object attribute: ERROR";
- my $obj = $class->new(decode('UTF-8', $value), $ogroup);
+ my $sth = $ruledb->{dbh}->prepare(
+ "SELECT * FROM Attribut WHERE Object_ID = ?");
+
+ $sth->execute($id);
+
+ my $top = 0;
+
+ while (my $ref = $sth->fetchrow_hashref()) {
+ $top = $ref->{value} if $ref->{name} eq 'top';
+ }
+
+ $sth->finish();
+
+ my $obj = $class->new(decode('UTF-8', $value), $ogroup, $top);
$obj->{id} = $id;
@@ -96,6 +110,9 @@ sub save {
"UPDATE Object SET Value = ? WHERE ID = ?",
undef, $value, $self->{id});
+ $ruledb->{dbh}->do(
+ "DELETE FROM Attribut WHERE Name = ? and Object_ID = ?",
+ undef, 'top', $self->{id});
} else {
# insert
@@ -108,6 +125,12 @@ sub save {
$self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
}
+ if (defined($self->{top})) {
+ $ruledb->{dbh}->do(
+ "INSERT INTO Attribut (Value, Name, Object_ID) VALUES (?, ?, ?)",
+ undef, $self->{top}, 'top', $self->{id});
+ }
+
return $self->{id};
}
@@ -134,13 +157,19 @@ sub add_data {
my $newfh = $body->open ("w") || return undef;
+ if ($self->{top}) {
+ $newfh->print($data);
+ }
+
while (defined($_ = $fh->getline())) {
$newfh->print($_); # copy contents
}
$newfh->print("\n"); # add final \n
- $newfh->print($data);
+ if (!$self->{top}) {
+ $newfh->print($data);
+ }
$newfh->close || return undef;
@@ -197,8 +226,12 @@ sub execute {
foreach my $ta (@$subgroups) {
my ($tg, $entity) = (@$ta[0], @$ta[1]);
-
- my $html = "<br>--<br>" . PMG::Utils::subst_values ($self->{value}, $vars);
+ my $html;
+ if ($self->{top}) {
+ $html = PMG::Utils::subst_values ($self->{value}, $vars) . "<br>--<br>";
+ } else {
+ $html = "<br>--<br>" . PMG::Utils::subst_values ($self->{value}, $vars);
+ }
my $text = "";
my $parser = HTML::Parser->new(
@@ -232,6 +265,12 @@ sub properties {
type => 'string',
maxLength => 2048,
},
+ top => {
+ description => "Put the disclaimer on top of the mail body, instead of the bottom.",
+ type => 'boolean',
+ optional => 1,
+ default => 0,
+ },
};
}
@@ -240,6 +279,7 @@ sub get {
return {
disclaimer => $self->{value},
+ top => $self->{top},
};
}
@@ -247,6 +287,7 @@ sub update {
my ($self, $param) = @_;
$self->{value} = $param->{disclaimer};
+ $self->{top} = $param->{top};
}
1;
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [pmg-devel] [PATCH pmg-api 4/4] fix #2430: ruledb disclaimer: make separator configurable
2024-01-09 13:59 [pmg-devel] [PATCH pmg-api/gui] ruledb disclaimer improvements Dominik Csapak
` (2 preceding siblings ...)
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 3/4] fix #2606: ruledb disclaimer: add ability to add on top Dominik Csapak
@ 2024-01-09 13:59 ` Dominik Csapak
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-gui 1/2] disclaimer edit: add 'top' checkbox Dominik Csapak
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-gui 2/2] disclaimer edit: add 'add-separator' checkbox Dominik Csapak
5 siblings, 0 replies; 10+ messages in thread
From: Dominik Csapak @ 2024-01-09 13:59 UTC (permalink / raw)
To: pmg-devel
add a new 'add-separator' property (default true) that controls if the
'--' separator is added.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/PMG/RuleDB/Disclaimer.pm | 39 ++++++++++++++++++++++++++----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/src/PMG/RuleDB/Disclaimer.pm b/src/PMG/RuleDB/Disclaimer.pm
index 95e8b31..d7ccb03 100644
--- a/src/PMG/RuleDB/Disclaimer.pm
+++ b/src/PMG/RuleDB/Disclaimer.pm
@@ -49,7 +49,7 @@ If this e-mail or attached files contain information which do not relate to our
_EOD_
sub new {
- my ($type, $value, $ogroup, $top) = @_;
+ my ($type, $value, $ogroup, $top, $separator) = @_;
my $class = ref($type) || $type;
@@ -59,6 +59,7 @@ sub new {
$self->{value} = $value;
$self->{top} = $top;
+ $self->{separator} = $separator;
return $self;
}
@@ -76,14 +77,16 @@ sub load_attr {
$sth->execute($id);
my $top = 0;
+ my $separator = 1;
while (my $ref = $sth->fetchrow_hashref()) {
$top = $ref->{value} if $ref->{name} eq 'top';
+ $separator = $ref->{value} if $ref->{name} eq 'separator';
}
$sth->finish();
- my $obj = $class->new(decode('UTF-8', $value), $ogroup, $top);
+ my $obj = $class->new(decode('UTF-8', $value), $ogroup, $top, $separator);
$obj->{id} = $id;
@@ -110,9 +113,11 @@ sub save {
"UPDATE Object SET Value = ? WHERE ID = ?",
undef, $value, $self->{id});
- $ruledb->{dbh}->do(
- "DELETE FROM Attribut WHERE Name = ? and Object_ID = ?",
- undef, 'top', $self->{id});
+ for my $prop (qw(top separator)) {
+ $ruledb->{dbh}->do(
+ "DELETE FROM Attribut WHERE Name = ? and Object_ID = ?",
+ undef, $prop, $self->{id});
+ }
} else {
# insert
@@ -125,10 +130,12 @@ sub save {
$self->{id} = PMG::Utils::lastid($ruledb->{dbh}, 'object_id_seq');
}
- if (defined($self->{top})) {
- $ruledb->{dbh}->do(
- "INSERT INTO Attribut (Value, Name, Object_ID) VALUES (?, ?, ?)",
- undef, $self->{top}, 'top', $self->{id});
+ for my $prop (qw(top separator)) {
+ if (defined($self->{$prop})) {
+ $ruledb->{dbh}->do(
+ "INSERT INTO Attribut (Value, Name, Object_ID) VALUES (?, ?, ?)",
+ undef, $self->{$prop}, $prop, $self->{id});
+ }
}
return $self->{id};
@@ -227,10 +234,11 @@ sub execute {
foreach my $ta (@$subgroups) {
my ($tg, $entity) = (@$ta[0], @$ta[1]);
my $html;
+ my $separator = $self->{separator} ? '<br>--<br>' : '<br>';
if ($self->{top}) {
- $html = PMG::Utils::subst_values ($self->{value}, $vars) . "<br>--<br>";
+ $html = PMG::Utils::subst_values ($self->{value}, $vars) . $separator;
} else {
- $html = "<br>--<br>" . PMG::Utils::subst_values ($self->{value}, $vars);
+ $html = $separator . PMG::Utils::subst_values ($self->{value}, $vars);
}
my $text = "";
@@ -271,6 +279,13 @@ sub properties {
optional => 1,
default => 0,
},
+ 'add-separator' => {
+ description => "If set to 1, adds a '--' separator between the disclaimer and the".
+ " content. Set to 0 to prevent that.",
+ type => 'boolean',
+ optional => 1,
+ default => 1,
+ },
};
}
@@ -280,6 +295,7 @@ sub get {
return {
disclaimer => $self->{value},
top => $self->{top},
+ 'add-separator' => $self->{separator},
};
}
@@ -288,6 +304,7 @@ sub update {
$self->{value} = $param->{disclaimer};
$self->{top} = $param->{top};
+ $self->{separator} = $param->{'add-separator'};
}
1;
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* [pmg-devel] [PATCH pmg-gui 1/2] disclaimer edit: add 'top' checkbox
2024-01-09 13:59 [pmg-devel] [PATCH pmg-api/gui] ruledb disclaimer improvements Dominik Csapak
` (3 preceding siblings ...)
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-api 4/4] fix #2430: ruledb disclaimer: make separator configurable Dominik Csapak
@ 2024-01-09 13:59 ` Dominik Csapak
2024-01-12 16:00 ` Thomas Lamprecht
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-gui 2/2] disclaimer edit: add 'add-separator' checkbox Dominik Csapak
5 siblings, 1 reply; 10+ messages in thread
From: Dominik Csapak @ 2024-01-09 13:59 UTC (permalink / raw)
To: pmg-devel
to enable adding the disclaimer on top
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
js/Utils.js | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/js/Utils.js b/js/Utils.js
index 7fa154e..daf0934 100644
--- a/js/Utils.js
+++ b/js/Utils.js
@@ -686,6 +686,11 @@ Ext.define('PMG.Utils', {
growMax: 250,
fieldLabel: gettext("Disclaimer"),
},
+ {
+ xtype: 'proxmoxcheckbox',
+ name: 'top',
+ fieldLabel: gettext("On Top"),
+ },
],
},
},
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [pmg-devel] [PATCH pmg-gui 1/2] disclaimer edit: add 'top' checkbox
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-gui 1/2] disclaimer edit: add 'top' checkbox Dominik Csapak
@ 2024-01-12 16:00 ` Thomas Lamprecht
0 siblings, 0 replies; 10+ messages in thread
From: Thomas Lamprecht @ 2024-01-12 16:00 UTC (permalink / raw)
To: Dominik Csapak, pmg-devel
Am 09/01/2024 um 14:59 schrieb Dominik Csapak:
> to enable adding the disclaimer on top
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> js/Utils.js | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/js/Utils.js b/js/Utils.js
> index 7fa154e..daf0934 100644
> --- a/js/Utils.js
> +++ b/js/Utils.js
> @@ -686,6 +686,11 @@ Ext.define('PMG.Utils', {
> growMax: 250,
> fieldLabel: gettext("Disclaimer"),
> },
> + {
> + xtype: 'proxmoxcheckbox',
> + name: 'top',
> + fieldLabel: gettext("On Top"),
This is IMO not really telling due to missing context.
While one could just change the label, that still wouldn't convey
the actual default position.
So, maybe using a "position" combobox (or radio-group, to reduce
required clicks) selection between "bottom" and "top" would
provide better UX here?
btw. this series seems to miss a (small) docs adaption to the
5.1.8. Disclaimer section.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [pmg-devel] [PATCH pmg-gui 2/2] disclaimer edit: add 'add-separator' checkbox
2024-01-09 13:59 [pmg-devel] [PATCH pmg-api/gui] ruledb disclaimer improvements Dominik Csapak
` (4 preceding siblings ...)
2024-01-09 13:59 ` [pmg-devel] [PATCH pmg-gui 1/2] disclaimer edit: add 'top' checkbox Dominik Csapak
@ 2024-01-09 13:59 ` Dominik Csapak
5 siblings, 0 replies; 10+ messages in thread
From: Dominik Csapak @ 2024-01-09 13:59 UTC (permalink / raw)
To: pmg-devel
for controlling if the separator should be included or not, default is
on (backend default).
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
js/Utils.js | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/js/Utils.js b/js/Utils.js
index daf0934..8529873 100644
--- a/js/Utils.js
+++ b/js/Utils.js
@@ -691,6 +691,13 @@ Ext.define('PMG.Utils', {
name: 'top',
fieldLabel: gettext("On Top"),
},
+ {
+ xtype: 'proxmoxcheckbox',
+ name: 'add-separator',
+ fieldLabel: gettext("Add Separator"),
+ uncheckedValue: 0,
+ value: true,
+ },
],
},
},
--
2.30.2
^ permalink raw reply [flat|nested] 10+ messages in thread