@@ -79,37 +79,48 @@ 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 ' ) {
89+ $ dovecotQuotaUsage [$ s [0 ]] = $ s [3 ] * 1024 ; // doveadm output is in kB
90+ } elseif ($ s [3 ] == 'STORAGE ' ) {
91+ $ dovecotQuotaUsage [$ s [0 ]] = $ s [4 ] * 1024 ; // doveadm output is in kB
92+ }
93+ }
94+ }
8695 }
8796
8897 foreach ($ mailboxes as $ mb ) {
8998 $ email = $ mb ['email ' ];
9099 $ email_parts = explode ('@ ' , $ mb ['email ' ]);
91100 $ 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 )) {
101+ if (count ( $ dovecotQuotaUsage ) > 0 && isset ( $ dovecotQuotaUsage [ $ email ]) ) {
102+ $ data [ $ email ][ ' used ' ] = $ dovecotQuotaUsage [ $ email] ;
103+ $ app -> log ( " Mail storage $ email : " . $ data [ $ email ][ ' used ' ], LOGLEVEL_DEBUG );
104+ } elseif (file_exists ($ filename ) && !is_link ($ filename )) {
96105 $ quotafile = file ($ filename );
97106 preg_match ('/storage.*?([0-9]+)/s ' , implode ('' ,$ quotafile ), $ storage_value );
98107 $ data [$ email ]['used ' ] = $ storage_value [1 ];
99- $ app ->log ("Mail storage $ email: " . $ storage_value [ 1 ], LOGLEVEL_DEBUG );
108+ $ app ->log ("Mail storage $ email: " . $ data [ $ email ][ ' used ' ], LOGLEVEL_DEBUG );
100109 unset($ quotafile );
101110 } else {
102111 $ app ->system ->exec_safe ('du -s ? ' , $ mb ['maildir ' ]);
103112 $ out = $ app ->system ->last_exec_out ();
104113 $ parts = explode (' ' , $ out [0 ]);
105114 $ data [$ email ]['used ' ] = intval ($ parts [0 ])*1024 ;
115+ $ app ->log ("Mail storage $ email: " . $ data [$ email ]['used ' ], LOGLEVEL_DEBUG );
106116 unset($ out );
107117 unset($ parts );
108118 }
109119 }
110120 }
111121
112122 unset($ mailboxes );
123+ unset($ dovecotQuotaUsage );
113124
114125 //* Dovecot quota check Courier in progress lathama@gmail.com
115126 /*
@@ -132,8 +143,8 @@ public function onRunJob() {
132143 $ res ['state ' ] = $ state ;
133144
134145 /*
135- * Insert the data into the database
136- */
146+ * Insert the data into the database
147+ */
137148 $ sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' .
138149 'VALUES (?, ?, UNIX_TIMESTAMP(), ?, ?) ' ;
139150 $ app ->dbmaster ->query ($ sql , $ res ['server_id ' ], $ res ['type ' ], serialize ($ res ['data ' ]), $ res ['state ' ]);
0 commit comments