Skip to content

Commit ac15a40

Browse files
committed
Preserve other DKIM keys while updating, #6688
1 parent 814781d commit ac15a40

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

interface/web/mail/mail_domain_edit.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ function onAfterUpdate() {
699699
if ( ($selector || $dkim_private || $dkim_active) && $dkim_active )
700700
//* create a new record only if the dns-zone exists
701701
if ( isset($soa) && !empty($soa) ) {
702-
$this->update_dns($this->dataRecord, $soa);
702+
$this->update_dns($this->dataRecord, $soa, $this->oldDataRecord);
703703
}
704704
if (! $dkim_active) {
705705
// updated existing dmarc-record to policy 'none'
@@ -718,15 +718,17 @@ function onAfterUpdate() {
718718

719719
}
720720

721-
private function update_dns($dataRecord, $new_rr) {
721+
private function update_dns($dataRecord, $new_rr, $oldDataRecord = null) {
722722
global $app, $conf;
723723

724-
// purge old rr-record(s)
725-
$sql = "SELECT * FROM dns_rr WHERE name LIKE ? AND data LIKE 'v=DKIM1%' AND " . $app->tform->getAuthSQL('r') . " ORDER BY serial DESC";
726-
$rec = $app->db->queryAllRecords($sql, '%._domainkey.'.$dataRecord['domain'].'.');
727-
if(is_array($rec)) {
728-
foreach($rec as $r) {
729-
$app->db->datalogDelete('dns_rr', 'id', $r['id']);
724+
// Purge old rr-record, incase the selector or domain changed.
725+
if (!empty($oldDataRecord)) {
726+
$sql = "SELECT * FROM dns_rr WHERE name LIKE ? AND data LIKE 'v=DKIM1%' AND " . $app->tform->getAuthSQL('r') . " ORDER BY serial DESC";
727+
$rec = $app->db->queryAllRecords($sql, $oldDataRecord['dkim_selector'].'._domainkey.'.$oldDataRecord['domain'].'.');
728+
if(is_array($rec)) {
729+
foreach($rec as $r) {
730+
$app->db->datalogDelete('dns_rr', 'id', $r['id']);
731+
}
730732
}
731733
}
732734

0 commit comments

Comments
 (0)