@@ -79,37 +79,44 @@ public function onRunJob() {
7979 if (is_array ($ mailboxes )) {
8080
8181 //* with dovecot we can use doveadm instead of 'du -s'
82- $ dovecot = false ;
83- if (isset ($ mail_config ['pop3_imap_daemon ' ]) && $ mail_config ['pop3_imap_daemon ' ] = 'dovecot ' && is_executable ('doveadm ' )) {
84- exec ('doveadm quota 2>&1 ' , $ tmp_output , $ tmp_retval ); // with dovecot 2.2.x 'doveadm quota' is unuseable
85- if ($ retval = 64 ) $ dovecot = true ;
82+ $ dovecotQuotaUsage = array ();
83+ if (isset ($ mail_config ['pop3_imap_daemon ' ]) && $ mail_config ['pop3_imap_daemon ' ] = 'dovecot ' ) {
84+ exec ("doveadm quota get -A 2>&1 " , $ res , $ retval );
85+ if ($ retval = 64 ) {
86+ foreach ($ res as $ v ) {
87+ $ s = preg_split ('/\s+/ ' , $ v );
88+ if ($ s [2 ] == 'STORAGE ' ) $ dovecotQuotaUsage [$ s [0 ]] = $ s [3 ] * 1024 ; // doveadm output is in kB
89+ }
90+ }
8691 }
8792
8893 foreach ($ mailboxes as $ mb ) {
8994 $ email = $ mb ['email ' ];
9095 $ email_parts = explode ('@ ' , $ mb ['email ' ]);
9196 $ filename = $ mb ['maildir ' ].'/.quotausage ' ;
92- if (! file_exists ( $ filename ) && $ dovecot ) {
93- $ app -> system -> exec_safe ( ' doveadm quota recalc -u ? ' , $ email) ;
94- }
95- if (file_exists ($ filename ) && !is_link ($ filename )) {
97+ if (count ( $ dovecotQuotaUsage ) > 0 && isset ( $ dovecotQuotaUsage [ $ email ]) ) {
98+ $ data [ $ email ][ ' used ' ] = $ dovecotQuotaUsage [ $ email] ;
99+ $ app -> log ( " Mail storage $ email : " . $ data [ $ email ][ ' used ' ], LOGLEVEL_DEBUG );
100+ } elseif (file_exists ($ filename ) && !is_link ($ filename )) {
96101 $ quotafile = file ($ filename );
97102 preg_match ('/storage.*?([0-9]+)/s ' , implode ('' ,$ quotafile ), $ storage_value );
98103 $ data [$ email ]['used ' ] = $ storage_value [1 ];
99- $ app ->log ("Mail storage $ email: " . $ storage_value [ 1 ], LOGLEVEL_DEBUG );
104+ $ app ->log ("Mail storage $ email: " . $ data [ $ email ][ ' used ' ], LOGLEVEL_DEBUG );
100105 unset($ quotafile );
101106 } else {
102107 $ app ->system ->exec_safe ('du -s ? ' , $ mb ['maildir ' ]);
103108 $ out = $ app ->system ->last_exec_out ();
104109 $ parts = explode (' ' , $ out [0 ]);
105110 $ data [$ email ]['used ' ] = intval ($ parts [0 ])*1024 ;
111+ $ app ->log ("Mail storage $ email: " . $ data [$ email ]['used ' ], LOGLEVEL_DEBUG );
106112 unset($ out );
107113 unset($ parts );
108114 }
109115 }
110116 }
111117
112118 unset($ mailboxes );
119+ unset($ dovecotQuotaUsage );
113120
114121 //* Dovecot quota check Courier in progress lathama@gmail.com
115122 /*
@@ -132,8 +139,8 @@ public function onRunJob() {
132139 $ res ['state ' ] = $ state ;
133140
134141 /*
135- * Insert the data into the database
136- */
142+ * Insert the data into the database
143+ */
137144 $ sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
138145 'VALUES (?, ?, UNIX_TIMESTAMP(), ?, ?) ' ;
139146 $ app ->dbmaster ->query ($ sql , $ res ['server_id ' ], $ res ['type ' ], serialize ($ res ['data ' ]), $ res ['state ' ]);
0 commit comments