Index: inc/class.imapfp.inc.php
===================================================================
--- inc/class.imapfp.inc.php (revision 0)
+++ inc/class.imapfp.inc.php (revision 0)
@@ -0,0 +1,343 @@
+imap = new imap_functions();
+ $this->user = $this->imap->username;
+ $this->password = $this->imap->password;
+ $this->host = $this->imap->imap_server;
+ $this->port = $this->imap->imap_port;
+ $this->state="DISCONNECTED";
+ $this->connection=null;
+ $this->error="";
+ $this->must_update=false;
+ $this->tag=uniqid("HKC");
+ }
+
+ function get_error()
+ {
+ if($this->error)
+ return $this->error;
+ }
+
+ function get_state()
+ {
+ return $this->state;
+ }
+
+ function open($host="",$port="")
+ {
+ if(!empty($host))
+ {
+ if ($port == 993)
+ $this->host="ssl://$host";
+ else
+ $this->host=$host;
+ }
+ if(!empty($port))
+ $this->port=$port;
+ return $this->open_connection();
+ }
+
+ function close()
+ {
+ if($this->must_update)
+ $this->close_mailbox();
+ $this->logout();
+ @fclose($this->connection);
+ $this->connection=null;
+ $this->state="DISCONNECTED";
+ return true;
+ }
+
+ function get_mailboxes_size()
+ {
+
+ // todas as subfolder
+ //if($this->put_line($this->tag . " GETANNOTATION \"user/".$this->user ."/*\" \"/vendor/cmu/cyrus-imapd/size\" \"value.shared\"" ))
+
+ //Somente a inbox
+ //if($this->put_line($this->tag . " GETANNOTATION \"user/".$this->user ."\" \"/vendor/cmu/cyrus-imapd/size\" \"value.shared\"" ))
+
+ //Tudo
+ //if($this->put_line($this->tag . " GETANNOTATION \"user/" . $this->user . "*\" \"/vendor/cmu/cyrus-imapd/size\" \"value.shared\"" ))
+
+
+ // INBOX
+ if($this->put_line($this->tag . " GETANNOTATION \"user/".$this->user ."\" \"/vendor/cmu/cyrus-imapd/size\" \"value.shared\"" ))
+ {
+ $response_inbox=$this->get_server_responce();
+
+ if(substr($response_inbox,strpos($response_inbox,"$this->tag ")+strlen($this->tag)+1,2)!="OK")
+ {
+ $this->error= "Error : $response !
";
+ return false;
+ }
+ }
+ else
+ {
+ $this->error= "Error : Could not send User request.
";
+ return false;
+ }
+ $response_inbox_array = split("\r\n", $response_inbox);
+ array_pop($response_inbox_array);
+ array_shift($response_inbox_array);
+
+ // SUB_FOLDERS
+ if($this->put_line($this->tag . " GETANNOTATION \"user/".$this->user ."/*\" \"/vendor/cmu/cyrus-imapd/size\" \"value.shared\"" ))
+ {
+ $response_sub=$this->get_server_responce();
+
+ if(substr($response_sub,strpos($response_sub,"$this->tag ")+strlen($this->tag)+1,2)!="OK")
+ {
+ $this->error= "Error : $response !
";
+ return false;
+ }
+ }
+ else
+ {
+ $this->error= "Error : Could not send User request.
";
+ return false;
+ }
+
+ $response_sub_array = split("\r\n", $response_sub);
+ array_pop($response_sub_array);
+ array_shift($response_sub_array);
+
+ return array_merge($response_inbox_array, $response_sub_array);
+ }
+
+ //This function is used to get response line from server
+ function get_line()
+ {
+ while(!feof($this->connection))
+ {
+ $line.=fgets($this->connection);
+ if(strlen($line)>=2 && substr($line,-2)=="\r\n")
+ return(substr($line,0,-2));
+ }
+ }
+
+ //This function is to retrive the full response message from server
+ function get_server_responce()
+ {
+ $i=0;
+ while(1)
+ {
+ $i++;
+ $response.="\r\n".$this->get_line();
+ if(substr($response,strpos($response,$this->tag),strlen($this->tag))==$this->tag)
+ break;
+
+ //jakjr
+ if ($i>300)
+ {
+ if ($response)
+ return $response;
+ else
+ return false;
+ }
+ }
+ return $response;
+ }
+ // This function is to send the command to server
+ function put_line($msg="")
+ {
+ return @fputs($this->connection,"$msg\r\n");
+ }
+
+ //This function is to open the connection to the server
+ function open_connection()
+ {
+ if($this->state!="DISCONNECTED")
+ {
+ $this->error= "Error : Already Connected!
";
+ return false;
+ }
+ if(empty($this->host) || empty($this->port))
+ {
+ $this->error= "Error : Either HOST or PORT is undifined!
";
+ return false;
+ }
+ $this->connection= fsockopen($this->host, $this->port, $errno, $errstr, 5);
+ if(!$this->connection)
+ {
+ $this->error= "Could not make a connection to server , Error : $errstr ($errno)
";
+ return false;
+ }
+ $respone=$this->get_line();
+ $this->state="AUTHORIZATION";
+ return true;
+ }
+
+ //The logout function informs the server that the client is done with the connection.
+ function logout()
+ {
+ //jakjr
+ if(($this->state!="AUTHORIZATION") && ($this->state!="AUTHENTICATED"))
+ {
+ $this->error= "Error : No Connection Found!
";
+ return false;
+ }
+ if($this->put_line($this->tag." LOGOUT"))
+ {
+ $response=$this->get_server_responce();
+ if(substr($response,strpos($response,"$this->tag ")+strlen($this->tag)+1,2)!="OK")
+ {
+ $this->error= "Error : $response !
";
+ return false;
+ }
+ }
+ else
+ {
+ $this->error= "Error : Could not send User request.
";
+ return false;
+ }
+ return true;
+ }
+
+ //this function is used to login into server $user is a valid username and $pwd is a valid password.
+ function login($user,$pwd)
+ {
+ $this->user = $user;
+
+ if($this->state=="DISCONNECTED")
+ {
+ $this->error= "Error : No Connection Found!
";
+ return false;
+ }
+ if($this->state=="AUTHENTICATED")
+ {
+ $this->error= "Error : Already Authenticated!
";
+ return false;
+ }
+ if($this->put_line($this->tag." LOGIN $user $pwd"))
+ {
+ $response=$this->get_server_responce();
+
+ if(substr($response,strpos($response,"$this->tag ")+strlen($this->tag)+1,2)!="OK")
+ {
+ $this->error= "Error : $response !
";
+ return false;
+ }
+ }
+ else
+ {
+ $this->error= "Error : Could not send User request.
";
+ return false;
+ }
+ $this->state="AUTHENTICATED";
+ return true;
+ }
+
+/*
+ * TODO: Futuramente esse m?todo deve ser embutido na classe imap_functions,
+ * conforme m?todo 'get_quota_folders' comentado.
+ */
+ function get_mailboxes_quota(){
+
+ if(!$this->open($this->host,$this->port))
+ return $this->get_error();
+
+ if (!$this->login( $this->user,$this->password ))
+ return $this->get_error();
+
+ $response_array = $this->get_mailboxes_size();
+
+ if ($this->error)
+ return $this->get_error();
+
+ $data = array();
+ $quota_root = $this->imap->get_quota(array('folder_id' => "INBOX"));
+ $data["quota_root"] = $quota_root;
+
+ foreach ($response_array as $idx=>$line) {
+ $line2 = str_replace('"', "", $line);
+ $line2 = str_replace(" /vendor/cmu/cyrus-imapd/size (value.shared ",";",str_replace("* ANNOTATION ","",$line2));
+ list($folder,$size) = explode(";",$line2);
+ $size = str_replace(")","",$size);
+ $quotaPercent = (($size / 1048576) / $data["quota_root"]["quota_limit"])*100;
+ if ($size < 1048576 && $size > 1024)
+ $quota_used = round($size / 1024, 0).' Kb';
+ else if($size > 1024)
+ $quota_used = round($size / (1024*1024), 1).' Mb';
+ else
+ $quota_used = $size." b";
+ $folder = mb_convert_encoding($folder, "ISO_8859-1", "UTF7-IMAP");
+ if(!preg_match('/user\\'.$this->imap->imap_delimiter.$this->user.'\\'.$this->imap->imap_delimiter.'/i',$folder)){
+ $folder = $this->imap->functions->getLang("Inbox");
+ }
+ else
+ $folder = preg_replace('/user\\'.$this->imap->imap_delimiter.$this->user.'\\'.$this->imap->imap_delimiter.'/i','', $folder);
+
+ $data[$folder] = array("quota_percent" => sprintf("%.1f",round($quotaPercent,1)), "quota_used" => $quota_used);
+ }
+ return $data;
+ }
+
+ }
+
+/* function get_quota_folders(){
+ include_once("class.imapfp.inc.php");
+ $imapfp = new imapfp();
+
+ if(!$imapfp->open($this->imap_server,$this->imap_port))
+ return $imapfp->get_error();
+ if (!$imapfp->login( $this->username,$this->password ))
+ return $imapfp->get_error();
+
+ $response_array = $imapfp->get_mailboxes_size();
+ if ($imapfp->error)
+ return $imapfp->get_error();
+
+ $data = array();
+ $quota_root = $this->get_quota(array('folder_id' => "INBOX"));
+ $data["quota_limit"] = $quota_root['quota_limit'];
+
+ foreach ($response_array as $idx=>$line) {
+ $line2 = str_replace('"', "", $line);
+ sscanf(rtrim(ltrim($line2)),"* ANNOTATION %s /vendor/cmu/cyrus-imapd/size (value.shared %d)",$folder, $size);
+ $quotaPercent = (($size / 1048576) / $data["quota_limit"])*100;
+ if ($size < 1048576 && $size > 1024)
+ $quota_used = round($size / 1024, 0).' Kb';
+ else if($size > 1024)
+ $quota_used = round($size / (1024*1024), 1).' Mb';
+ else
+ $quota_used = $size." b";
+
+ if(!preg_match('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i',$folder)){
+ $folder = $this->functions->getLang("Inbox");
+ }
+ else
+ $folder = preg_replace('/user\\'.$this->imap_delimiter.$this->username.'\\'.$this->imap_delimiter.'/i','', $folder);
+
+ $data[$folder] = array("quota_percent" => $quotaPercent, "quota_used" => $quota_used);
+ }
+ return $data;
+ }*/
+?>
Index: js/InfoQuota.js
===================================================================
--- js/InfoQuota.js (revision 0)
+++ js/InfoQuota.js (revision 0)
@@ -0,0 +1,218 @@
+function emInfoQuota ()
+ {
+ this.win;
+ this.el;
+ this.preLoad();
+ }
+
+ emInfoQuota.prototype.preLoad = function(){
+ if(Element("table_quota")) {
+ Element("table_quota").style.cursor = "pointer";
+ Element("table_quota").title = "Visualizar quota utilizada por cada pasta";
+ Element("table_quota").onclick = function (){
+ InfoQuota.showList();
+ }
+ }
+ }
+
+ emInfoQuota.prototype.showList = function()
+ {
+ var _this = this;
+ var el = Element("window_InfoQuota");
+ if(!el) {
+ el = document.createElement("DIV");
+ el.style.visibility = "hidden";
+ el.style.position = "absolute";
+ el.style.left = "0px";
+ el.style.top = "0px";
+ el.style.overflowY = "auto";
+ el.align = "center";
+ div.style.height = "400px";
+ el.id = 'window_InfoQuota';
+ document.body.appendChild(el);
+ }
+
+ var handler_buildQuota = function(data){
+ el.appendChild(InfoQuota.buildQuota(data));
+ el.innerHTML += '
';
+ _this.showWindow(el);
+ }
+
+ //cExecute ("$this.imap_functions.get_quota_folders", handler_buildQuota);
+ cExecute ("$this.imapfp.get_mailboxes_quota", handler_buildQuota);
+ }
+
+ emInfoQuota.prototype.showWindow = function (div)
+ {
+ if(! this.win) {
+ div.style.height = "350px";
+ div.style.width = "450px";
+ var title = "Visualizar quota utilizada por cada pasta";
+ var wHeight = div.offsetHeight + "px";
+ var wWidth = div.offsetWidth + "px";
+
+ this.win = new dJSWin({
+ id: 'win_'+div.id,
+ content_id: div.id,
+ width: wWidth,
+ height: wHeight,
+ title_color: '#3978d6',
+ title_align: 'center',
+ bg_color: '#eee',
+ title: title,
+ title_text_color: 'white',
+ button_x_img: '../phpgwapi/images/winclose.gif',
+ border: true });
+
+ this.win.draw();
+ this.win.title.align = "center";
+ }
+
+ this.win.open();
+ }
+
+ emInfoQuota.prototype.close_window = function() {
+ this.win.close();
+ }
+
+ emInfoQuota.prototype.buildQuota = function (data){
+ if(Element("window_InfoQuota")){
+ Element("window_InfoQuota").innerHTML = '';
+ }
+ var content = '';
+ var q_limit = data.quota_root.quota_limit;
+
+ var value = '';
+ var q_used = '';
+ var table = document.createElement("TABLE");
+ table.id = "table_quota";
+ table.style.border="1px solid #CCC";
+ table.style.marginTop = "10px";
+ table.style.width="100%";
+ table.style.height="80%";
+ table.style.background = "#FFF";
+ table.cellSpacing = 5;
+ table.cellPadding = 0;
+ var thead = document.createElement("THEAD");
+ var tbody = document.createElement("TBODY");
+ var tfoot = document.createElement("TFOOT");
+ table.appendChild(thead);
+ table.appendChild(tbody);
+ table.appendChild(tfoot);
+ thead.style.background = "#FFF";
+ var tr_thead = document.createElement("TR");
+ tr_thead.style.fontSize = "10pt";
+ tr_thead.style.height = '10px';
+ tr_thead.style.background = "#3978d6";
+ tr_thead.style.color = "white";
+ tr_thead.style.fontWeight = "bold";
+ tr_thead.outerHTML = tr_thead.outerHTML;
+ thead.appendChild(tr_thead);
+ var th_thead = document.createElement("TH");
+ th_thead.style.paddingRight = '5px';
+ th_thead.style.paddingLeft = '5px';
+ th_thead.innerHTML = 'Pasta';
+ tr_thead.appendChild(th_thead);
+ th_thead = document.createElement("TH");
+ th_thead.style.paddingRight = '5px';
+ th_thead.style.paddingLeft = '5px';
+ th_thead.style.align = "center";
+ th_thead.colSpan = "2";
+ th_thead.noWrap = "true";
+ th_thead.innerHTML = '% utilizado';
+ tr_thead.appendChild(th_thead);
+ th_thead = document.createElement("TH");
+ th_thead.style.paddingRight = '5px';
+ th_thead.style.paddingLeft = '5px';
+ th_thead.noWrap = "true";
+ th_thead.innerHTML = 'Tamanho em bytes';
+ tr_thead.appendChild(th_thead);
+ tbody.style.overflowY = "auto";
+ tbody.style.overflowX = "hidden";
+ tbody.style.width = "50%";
+ var last_folder = 'null';
+ for(var x in data) {
+ if(x == 'quota_root') continue;
+ q_used = data[x]['quota_used'];
+ value = data[x]['quota_percent'];
+ td01 = document.createElement("TD");
+ td01.align="left";
+ if(x.indexOf(last_folder+"/") == -1){
+ last_folder = x;
+ td01.innerHTML = " "+x;
+ }
+ else {
+ var a_folder = x.split('/');
+ for (var i =0; i< a_folder.length;i++)
+ td01.innerHTML += " ";
+ td01.innerHTML += a_folder[a_folder.length-1];
+ }
+
+ td01.style.borderBottom = "1px dashed #DDD";
+ td01.width="40%";
+ td01.setAttribute("noWrap","true");
+ td02 = document.createElement("TD");
+ td02.align="center";
+ td02.width="5%";
+ td02.setAttribute("noWrap","true");
+ td02.innerHTML = value+"%";
+ td11 = document.createElement("TD");
+ td11.width="10%";
+ td11.align="center";
+ td11.setAttribute("noWrap","true");
+ td11.style.borderBottom = "1px dashed #DDD";
+ td11.innerHTML += ' ";
+ tr2 = document.createElement("TR");
+ td21 = document.createElement("TD");
+ td21.setAttribute("noWrap","true");
+ td21.height="15px";
+ td22 = document.createElement("TD");
+ td21.setAttribute("background","./templates/"+template+"/images/dsunused.gif");
+ table221 = document.createElement("TABLE");
+ tbody221 = document.createElement("TBODY");
+ table221.appendChild(tbody221);
+ table221.style.width=value+"%";
+ td21.width="30%";
+ table221.cellSpacing = 0;
+ table221.cellPadding = 0;
+ tr221 = document.createElement("TR");
+ td221 = document.createElement("TD");
+ td221.height="15px";
+ td221.className = 'dsused';
+ tr221.appendChild(td221);
+ tbody221.appendChild(tr221);
+ td21.appendChild(table221);
+ tr2.appendChild(td01);
+ tr2.appendChild(td02);
+ tr2.appendChild(td21);
+ tr2.appendChild(td11);
+ tbody.appendChild(tr2);
+ }
+ var tr_tfoot = document.createElement("TR");
+ tr_tfoot.style.fontSize = "10pt";
+ tr_tfoot.style.color = "#bbb";
+ tr_tfoot.style.fontWeight = "bold";
+ tfoot.appendChild(tr_tfoot);
+ var th_tfoot = document.createElement("TH");
+ th_tfoot.style.align = "center";
+ th_tfoot.colSpan = "4";
+ th_tfoot.style.paddingRight = '5px';
+ th_tfoot.style.paddingLeft = '5px';
+ th_tfoot.innerHTML = "Total armazenado no servidor é de "+data.quota_root.quota_used+"Mb ("+data.quota_root.quota_percent+"%)";
+ tr_tfoot.appendChild(th_tfoot);
+ return table;
+ }
+
+/* Build the Object */
+ var InfoQuota;
+ InfoQuota = new emInfoQuota();
+
+ /* Override function :: refresh and auto_refresh */
+ var __build_quota = build_quota;
+ build_quota = function (data) {
+ __build_quota(data);
+ if(InfoQuota.win)
+ InfoQuota.win.close();
+ InfoQuota.preLoad();
+ }
\ No newline at end of file
Index: js/draw_api.js
===================================================================
--- js/draw_api.js (revision 2246)
+++ js/draw_api.js (working copy)
@@ -711,6 +711,7 @@
connector.loadAllScripts(scripts);
}
+ connector.loadScript("InfoQuota");
}
function make_tr_message(headers_msgs, msg_folder){