Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't create mailbox if quota is not filled in #342

Closed
Jan-Kruis opened this issue Mar 15, 2020 · 9 comments
Closed

can't create mailbox if quota is not filled in #342

Jan-Kruis opened this issue Mar 15, 2020 · 9 comments

Comments

@Jan-Kruis
Copy link
Contributor

Hey,

I have found the following problem.

If the field 'mailbox quota' table 'domain' is set to the value 0 (= unlimited) for a domain and I want to create a new mailbox for that domain and do not enter the field of the quota for that mailbox with a value, then I got the error that the mailbox cannot be created. However, an alias with that name is created for the domain.
In the previous version of postfixadmin, the value 0 (= unlimited) was entered in the "quota" table "mailbox" of the database (if no value was entered).
This does not happen now, see also the error message that the web server (in my case apache2) makes.

[php7: notice]… Invalid query: SQLSTATE [HY000]: General error: 1366 Incorrect integer value: '' for column 'quota' at row 1 caused by INSERT INTO mailbox (username
, local_part, domain, maildir, password, name, quota, active, phone, email_other, token, token_validity, created, modified, password_expiry) VALUES (: username,: local_part,: domain,: maildir,: password,: name ,: quota,: active,: phone,: email_other,: token,: token
_validity, now (), now () ,: password_expiry), referer: http: //x.x.x.x/pfa/edit.php? table = mailbox

If I enter the value 0 in the quota field when creating the mailbox for the domain, everything works fine.

I think there should be a check.

If the value of 'quota' in the table 'domain' is equal to 0, no value is entered in the quota field when creating a mailbox for that domain, then the value for 'quota' in the table 'mailbox' must be set to 0 are set.

This problem was not present with the previous version.

I tested the latest git version of postfixadmin (03/14/2020).

DavidGoodwin added a commit that referenced this issue Mar 16, 2020
@Jan-Kruis
Copy link
Contributor Author

Hi David,
thanks for the quick fix.

however, there is still a problem.
when saving the mailbox the value 0 is placed in the record of 'quota'. But if I want to change the mailbox by editing the value -1 is placed in the quota field when it should be 0.
If you are not aware of this wrong change, the value change from 'unlimited' to 'disable'

I think this is due to either
the change '30f97c9' model / MailboxHandler.php
or
the change 'fefe3f7' model / DomainHandler.php

@Jan-Kruis Jan-Kruis reopened this Mar 17, 2020
@Jan-Kruis
Copy link
Contributor Author

should not have closed

@DavidGoodwin
Copy link
Member

would this fix it (in MailboxHandler) - around line 200.

    protected function read_from_db_postprocess($db_result) {
        foreach ($db_result as $key => $row) {
            if (isset($row['quota']) && is_numeric($row['quota']) && $row['quota'] > -1) { # quota could be disabled in $struct
                $db_result[$key]['quotabytes'] = $row['quota'];
                $db_result[$key]['quota'] = divide_quota($row['quota']); # convert quota to MB
            } else {
                $db_result[$key]['quotabytes'] = -1;
                $db_result[$key]['quota'] = -1;
            }
        }
        return $db_result;
    }

I'm not sure whether i need the && $row['quota'] > -1 in the if statement or not.

@Jan-Kruis
Copy link
Contributor Author

hi david,
I have tested your proposed modification but it has no effect.
I also tested some other variations but had no effect the display value remains -1

test 2
if (isset ($ row ['quota']) && is_numeric ($ row ['quota']) && $ row ['quota'] = 0)

test 3
if (isset ($ row ['quota']) && is_numeric ($ row ['quota']) and $ row ['quota'] = 0)

But just a question about the functions
'quotaabyte' is not a record in the mailbox table why it is filled with the value of 'quota' or with the value -1

i will test further with other variations but i feel it will be overwritten later

@DavidGoodwin
Copy link
Member

DavidGoodwin commented Mar 17, 2020

  • -1 - disabled
  • 0 - unlimited
  • any-other-number - quota.

quotabytes is meant to be a virtual field (derived from another)....

@Jan-Kruis
Copy link
Contributor Author

replacing

if (isset ($ row ['quota']) && is_numeric ($ row ['quota']) && $ row ['quota'] = 0)

back to

if (isset ($ row ['quota']) )

solves my problem

a question
why are the other condition added to it

@Jan-Kruis
Copy link
Contributor Author

Sorry David
the code your wrote works prefect en fix the problem

I was not paying attention and did not adapt a piece of code,so that made it seem that the code was not working

so your comment above no longer applies

@DavidGoodwin
Copy link
Member

DavidGoodwin commented Mar 18, 2020

Sorry David
the code your wrote works prefect en fix the problem

I was not paying attention and did not adapt a piece of code,so that made it seem that the code was not working

so your comment above no longer applies

Sorry; just for the sake of avoiding possible confusion. Is this the correct code ?

 if (isset($row['quota']) && is_numeric($row['quota']) && $row['quota'] > -1) { 

@Jan-Kruis
Copy link
Contributor Author

Yes that is the correct code

Thnx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants