fix(preferences): Fix the issue when signature is too long and preferences are not saved. Note that MySQL profile table should be updated with a migration script

This commit is contained in:
smizrahi
2023-07-25 17:22:11 +02:00
parent ec27f7e714
commit 326bc68f4c
13 changed files with 95 additions and 9 deletions

View File

@@ -3283,6 +3283,9 @@ current version of SOGo from the previous release.
[cols="100a"]
|=======================================================================
h|5.9.0
|Run the shell script `sql-update-5.8.4_to_5.9.0.sh` (if you are using MySQL). This will change the `c_defaults` to `MEDIUMTEXT`.
h|5.8.2
|Changes in Mac OS X Ventura 13.3. For mac Apple's Calendar users, the account must be removed and re-added (https://bugs.sogo.nu/view.php?id=5639#c16901). This can be achived in `` / `System Settings` / `Internet Accounts`.

View File

@@ -0,0 +1,26 @@
#!/bin/bash
set -euo pipefail
# This script only works with PostgreSQL and MySQL - it does:
#
# - increase the c_defaults column of user profile table to medium text
profiletype=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ SOGoProfileURL =/ {print $2}' | awk -F: '{ print $1 }')
if [ -z "$profiletype" ]; then
echo "Failed to obtain session table type" >&2
exit 1
fi
if [[ "$profiletype" == "mysql" ]]; then
profiletable=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ SOGoProfileURL =/ {print $2}' | awk -F/ '{print $NF}')
mysqlargs=$(sogo-tool dump-defaults -f /etc/sogo/sogo.conf | awk -F\" '/ SOGoProfileURL =/ {print $2}' | sed 's/mysql:\/\/\([^:]\+\):\([^@]\+\)@\([^\:]\+\):\([^\/]\+\)\/\([^\/]\+\).\+/-h \3 -P \4 -u \1 -p\2 \5/')
echo "Converting c_defaults from TEXT to MEDIUMTEXT in sessions table ($profiletable)"
mysql -v $mysqlargs -e "ALTER TABLE $profiletable MODIFY c_defaults MEDIUMTEXT;"
else
echo "Unsupported database type $profiletype"
exit 1
fi
exit 0

View File

@@ -31,6 +31,7 @@
NSString *fieldName;
}
- (unsigned long long)getCDefaultsSize;
@end

View File

@@ -239,4 +239,33 @@ static EOAttribute *textColumn = nil;
return rc;
}
- (unsigned long long) getCDefaultsSize {
unsigned long long r;
NSString *sql;
NSException *ex;
GCSChannelManager *cm;
EOAdaptorChannel *channel;
EOAdaptorContext *context;
NSArray *attrs;
NSDictionary *infos;
r = 65535;
cm = [GCSChannelManager defaultChannelManager];
channel = [cm acquireOpenChannelForURL: tableURL];
sql = [NSString stringWithFormat: @"select character_octet_length as CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '%@' AND column_name = 'c_defaults'", [tableURL gcsTableName]];
ex = [channel evaluateExpressionX: sql];
if (!ex) {
attrs = [channel describeResults: NO];
infos = [channel fetchAttributes: attrs withZone: NULL];
[cm releaseChannel: channel immediately: YES];
if (infos && [infos objectForKey:@"CHARACTER_MAXIMUM_LENGTH"]) {
r = [[infos objectForKey:@"CHARACTER_MAXIMUM_LENGTH"] longLongValue];
}
}
return r;
}
@end

View File

@@ -86,6 +86,8 @@ NSString *SOGoPasswordRecoverySecondaryEmail = @"SecondaryEmail";
[ud setObject: @"text" forKey: @"SOGoMailComposeMessageType"];
}
[ud setObject: [NSNumber numberWithUnsignedLongLong: [up getCDefaultsSize]] forKey: @"CDefaultsSize"]; // Add c_defaults field size
return ud;
}

View File

@@ -22,6 +22,7 @@ endif
MainUI_RESOURCE_FILES += \
product.plist \
SOGoProfile.sql \
SOGoProfile-mysql.sql \
SOGoProfile-oracle.sql \
OCSFolderInfo.sql \
OCSFolderInfo-oracle.sql \

View File

@@ -0,0 +1,11 @@
--
-- (C) 2004-2005 SKYRIX Software AG
-- (C) 2006-2007 Inverse inc.
-- (C) 2023 Alinto
--
CREATE TABLE @{tableName} (
c_uid VARCHAR(255) NOT NULL PRIMARY KEY,
c_defaults MEDIUMTEXT,
c_settings TEXT
);

View File

@@ -248,6 +248,7 @@
"Digitally sign the message by default" = "Digitally sign the message by default";
"Always try to encrypt the message" = "Always try to encrypt the message";
"An error occurred while importing the certificate. Verify your password." = "An error occurred while importing the certificate. Verify your password.";
"Data too big. Please contact technical support." = "Data too big. Please contact technical support.";
/* Additional Parameters */
"Additional Parameters" = "Additional Parameters";

View File

@@ -248,6 +248,7 @@
"Digitally sign the message by default" = "Toujours signer le message";
"Always try to encrypt the message" = "Toujours tenter de crypter le message";
"An error occurred while importing the certificate. Verify your password." = "Une erreur est survenue lors de l'importation du certificat. Veuillez vérifier votre mot de passe.";
"Data too big. Please contact technical support." = "Données trop longues. Contactez votre support technique.";
/* Additional Parameters */
"Additional Parameters" = "Paramètres supplémentaires";

View File

@@ -1743,6 +1743,9 @@ static NSArray *reminderValues = nil;
else
results = (id <WOActionResults>) [self responseWithStatus: 503
andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Service temporarily unavailable", @"message", nil]];
} else {
results = (id <WOActionResults>) [self responseWithStatus: 500
andJSONRepresentation: [NSDictionary dictionaryWithObjectsAndKeys: @"Error during the validation", @"message", nil]];
}
}

File diff suppressed because one or more lines are too long

View File

@@ -7,22 +7,21 @@
/**
* @ngInject
*/
AccountDialogController.$inject = ['$timeout', '$window', '$mdDialog', 'FileUploader', 'Dialog', 'sgSettings', 'defaults', 'account', 'accountId', 'mailCustomFromEnabled'];
function AccountDialogController($timeout, $window, $mdDialog, FileUploader, Dialog, Settings, defaults, account, accountId, mailCustomFromEnabled) {
AccountDialogController.$inject = ['$timeout', '$window', '$mdDialog', 'FileUploader', 'Dialog', 'sgSettings', 'defaults', 'account', 'accountId', 'mailCustomFromEnabled', 'maxSize'];
function AccountDialogController($timeout, $window, $mdDialog, FileUploader, Dialog, Settings, defaults, account, accountId, mailCustomFromEnabled, maxSize) {
var vm = this, usesSSO = $window.usesCASAuthentication || $window.usesSAML2Authentication;
this.defaultPort = 143;
this.defaults = defaults;
this.account = account;
this.maxSize = maxSize;
this.accountId = accountId;
this.hostnameRE = usesSSO && accountId > 0 ? /^(?!(127\.0\.0\.1|localhost(?:\.localdomain)?)$)/ : /./;
this.emailRE = String.emailRE;
this.addressesSearchText = '';
this.ckConfig = {
'autoGrow_minHeight': 70,
'toolbar': [['Bold', 'Italic', '-', 'Link',
'Font','FontSize','-','TextColor',
'BGColor', 'Source']],
removeButtons: 'Save,NewPage,Preview,Print,Templates,Cut,Copy,Paste,PasteText,PasteFromWord,Undo,Redo,Find,Replace,SelectAll,Scayt,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,CopyFormatting,RemoveFormat,NumberedList,BulletedList,Outdent,Indent,Blockquote,CreateDiv,JustifyLeft,JustifyCenter,JustifyRight,JustifyBlock,BidiLtr,BidiRtl,Language,Unlink,Anchor,Flash,Table,HorizontalRule,Smiley,SpecialChar,PageBreak,Iframe,Styles,Format,Maximize,ShowBlocks,About,Strike,Subscript,Superscript,Underline,Image,Emojipanel,Emoji,',
language: defaults.ckLocaleCode
};
@@ -155,7 +154,14 @@
};
this.save = function () {
// Check if the size of the content os not too big. Otherwise it will fail while storing in database.
// This usually happens when using image signature
var data = JSON.stringify(this.account);
if (data.length > this.maxSize) {
Dialog.alert(l('Error'), l('Data too big. Please contact technical support.'));
} else {
$mdDialog.hide();
}
};
}

View File

@@ -145,7 +145,8 @@
defaults: this.preferences.defaults,
account: account,
accountId: index,
mailCustomFromEnabled: $window.mailCustomFromEnabled
mailCustomFromEnabled: $window.mailCustomFromEnabled,
maxSize: this.preferences.defaults.CDefaultsSize
}
}).then(function() {
// Automatically expand the new mail account
@@ -173,7 +174,8 @@
defaults: this.preferences.defaults,
account: account,
accountId: index,
mailCustomFromEnabled: $window.mailCustomFromEnabled
mailCustomFromEnabled: $window.mailCustomFromEnabled,
maxSize: this.preferences.defaults.CDefaultsSize
}
}).then(function() {
vm.preferences.defaults.AuxiliaryMailAccounts[index] = account.$omit();