[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/Emails/ -> mailbox.php (source)

   1  <?php
   2  /*********************************************************************************
   3  ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9  *
  10   ********************************************************************************/
  11  
  12  //get the mail server info
  13  global $current_user;
  14  require_once ('include/utils/UserInfoUtil.php');
  15  $mailInfo = getMailServerInfo($current_user);
  16     $temprow = $adb->fetch_array($mailInfo);
  17      if($temprow["mail_protocol"] == 'POP')
  18      {
  19           $ServerName = "{".$temprow["mail_servername"]."/pop3:110/notls}INBOX"; 
  20          }
  21      else
  22      {
  23     $ServerName = "{".$temprow["mail_servername"]."/imap:143/notls}INBOX";
  24     // For a IMAP connection    (PORT 143)
  25        }
  26     $UserName = $temprow["mail_username"];
  27     $PassWord = $temprow["mail_password"];
  28     
  29     $mbox = imap_open($ServerName, $UserName,$PassWord) or die("Could not open Mailbox - try again later!");
  30     
  31     if ($hdr = imap_check($mbox)) {
  32         echo "Total Messages  :-> " . $hdr->Nmsgs ."\n\n<br><br>";
  33         $msgCount = $hdr->Nmsgs;
  34     } else {
  35         echo "failed";
  36     }
  37  $MN=$msgCount;
  38  $overview=imap_fetch_overview($mbox,"1:$MN",0);
  39  $mime_type = get_mime_type($overview);
  40  //$size=sizeof($overview);
  41  $size = imap_num_msg($mbox);
  42  
  43  global $app_strings,$current_user;
  44  
  45  if(isset($_REQUEST['view']) && $_REQUEST['view']!='')
  46  {
  47    $msgid = $_REQUEST['view'];
  48    $header = @imap_headerinfo($mbox, $msgid, 80, 80);
  49    $fromaddress[$msgid] = $header->from[0]->host;
  50    $domain = $fromaddress[$msgid];
  51    $fromname[$msgid] = $header->from[0]->mailbox;
  52    $sendername=$fromname[$msgid];
  53    $from[$msgid]= $fromname[$msgid]."@".$fromaddress[$msgid];
  54    $totalfromaddress = $sendername ."@".$domain;
  55        $val=$overview[$msgid-1];
  56        $msg=$val->msgno;
  57        $from=$val->from;
  58        $date=$val->date;
  59        $subj=$val->subject;
  60        //transformHTML($subj);
  61        $seen=$val->seen;
  62     
  63        $from = ereg_replace("\"","",$from);
  64     
  65        echo '<script language="JavaScript">
  66            var b;
  67         browser = navigator.appName;
  68         if (browser == "Microsoft Internet Explorer") {
  69             b = "ie";
  70         } else {
  71             b = "other";
  72         }
  73            
  74  	   function handleFile(nr) {
  75             if (b != "ie") {
  76                     alert("This feature is currently only available for Microsoft Internet Explorer 5.5+ users\n\nWait for an update!");
  77             } else {
  78                 check = confirm("Do you want to download the file ?");
  79              if (check) {
  80                  setTimeout("this.location.reload()",8000);
  81                  location.href="index.php?action=gotodownload&module=Emails&download=1&file="+ nr +"&msgno='.$msg.'";                         } else {
  82                  location.reload();
  83              }
  84          }
  85       }
  86      </script>';           
  87  
  88        // MAKE DANISH DATE DISPLAY
  89        list($dayName,$day,$month,$year,$time) = split(" ",$date); 
  90        $time = substr($time,0,5);
  91        $date = $day ." ". $month ." ". $year . " ". $time;
  92     
  93        if ($bgColor == "#F0F0F0") {
  94          $bgColor = "#FFFFFF";
  95        } else {
  96          $bgColor = "#F0F0F0";
  97          }
  98     
  99        if (strlen($subj) > 60) {
 100          $subj = substr($subj,0,59) ."...";
 101          get_part();
 102          }
 103      
 104      echo get_module_title("Emails",'Emails', true);
 105      echo "<br>";
 106      echo "<form action='' method=post>";
 107      echo '<table border="0" cellpadding="0" cellspacing="1" width="80%" class="formOuterBorder">';
 108      echo '<tr><td class="formSecHeader" colspan=2>Email Information</td></tr>';
 109      echo "<tr><td class='datalabel' width='15%'>From:</td><td>" . $from ."</td></tr>";
 110      echo "<tr><td class='datalabel'>Date:</td><td>" .$date ."</td></tr>";
 111      echo "<tr><td class='datalabel'>Subject:</td><td>" .$subj."</td></tr>";
 112      echo "<tr><td class='datalabel' valign=top>Mail body:</td><td>";
 113      $content = get_part($mbox,$msg,$mime_type);
 114      echo nl2br($content);
 115      echo "</td></tr></table>";
 116      //get the attachment
 117      $struct = imap_fetchstructure($mbox,$msg);
 118      $contentParts = count($struct->parts);
 119            if ($contentParts >= 2) {
 120                   for ($i=2;$i<=$contentParts;$i++) {
 121                    $att[$i-2] = imap_bodystruct($mbox,$msg,$i);
 122                }
 123             for ($k=0;$k<sizeof($att);$k++) {
 124              if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value    == "US-ASCII") {
 125                  if ($att[$k]->parameters[1]->value != "") {
 126                      $selectBoxDisplay[$k] = $att[$k]->parameters[1]->value;
 127                  }
 128                     } 
 129              elseif ($att[$k]->parameters[0]->value != "iso-8859-1" &&    $att[$k]->parameters[0]->value != "ISO-8859-1") {
 130                  $selectBoxDisplay[$k] = $att[$k]->parameters[0]->value;
 131              }
 132              }
 133          }
 134          
 135          if (sizeof($selectBoxDisplay) > 0) {
 136                     echo "<br><select name=\"attachments\" size=\"3\" class=\"tblContent\"    onChange=\"handleFile(this.value)\" style=\"width:170;\">";
 137                 for ($j=0;$j<sizeof($selectBoxDisplay);$j++) {
 138                   echo "\n<option value=\"$j\">". $selectBoxDisplay[$j]    ."</option>";
 139                 }
 140                 echo "</select>";
 141          }    
 142  
 143          echo '<form name=f1 action=index.php method=post>
 144              <input type="hidden" name="module" value="Emails">
 145          <input type="hidden" name="action">
 146          <input type="hidden" name="return_module" value="Emails">
 147          <input type="hidden" name="return_id" value="{RETURN_ID}">
 148          <input type="hidden" name="return_action" value="mailbox">
 149          <input type="hidden" name="from" value="'.$from .'">;
 150            <input type="hidden" name="sname" value="'.$ServerName .'">
 151            <input type="hidden" name="uname" value="'.$UserName .'">
 152           <input type="hidden" name="passwd" value="'.$PassWord .'">';
 153          
 154          
 155      
 156          $date_fmt = Array();
 157      list($mday,$mmon,$myear,$mtime)=split(" ",$date);
 158      $maildate = strtotime($mday." ".$mmon." ".$myear);
 159      list($date_fmt[0],$date_fmt[1],$date_fmt[2]) = split("-",$current_user->date_format);
 160      for($i=0;$i<=2;$i++)
 161      {
 162          if(stristr($date_fmt[$i],"d"))
 163          $date_fmt[$i] = "d";
 164          elseif(stristr($date_fmt[$i],"m"))
 165          $date_fmt[$i] = "m";
 166          elseif(stristr($date_fmt[$i],"y"))
 167          $date_fmt[$i] = "Y";
 168      }
 169      #echo date("$date_fmt[0]-$date_fmt[1]-$date_fmt[2]",$maildate);
 170      echo '<input type=hidden name="date_start" value="'.date("$date_fmt[0]-$date_fmt[1]-$date_fmt[2]",$maildate).'">
 171      <input type=hidden name="time_start" value="'.$mtime.'">
 172      <input type=hidden name="assigned_user_id" value="'.$current_user->id.'">
 173      <input type=hidden name="description" value="'.$content.'">
 174      <input type=hidden name="subject" value="'.$subj.'">
 175          <input type=hidden name="fromemail" value="'.$totalfromaddress.'">
 176          <br><input type=checkbox name=addbox value=Add>  Add to vtiger CRM  <br>
 177          <input type=checkbox name=deletebox value='.$msg.'> Delete from Mail Server <br>';
 178      echo '<br><table width=80%><tr><td align=center><input title="'.$app_strings[LBL_ADD_VTIGER_BUTTON_TITLE].'" accessKey="'.$app_strings['LBL_ADD_VTIGER_BUTTON_KEY'].'" class="button" onclick="this.form.action.value=\'Save\';" type="submit" name="button" value="'.$app_strings['LBL_SAVE_LABEL'].'">&nbsp;<input class=button type=button value=Cancel onclick="window.history.back()" ></td></tr></table>
 179      </form>';
 180  
 181  }
 182  else
 183  {
 184      echo get_module_title("Emails",'Emails', true); 
 185      echo "<br>";
 186      echo "<form action='index.php>module=Emails&action=Save' method=post>";
 187      echo '<table border="0" cellpadding="0" cellspacing="0" width="80%"><tr><td>';
 188      echo get_form_header("Received Emails", "<table width=\"100%\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\"><tr></tr></table>", false );
 189      echo "</td></tr></table>";
 190      echo '<table border="0" cellpadding="0" cellspacing="0" class="FormBorder" width="80%">';
 191      echo '<tr class="ModuleListTitle" height=20>';
 192      echo '<td width="10" class="moduleListTitle" style="padding:0px 3px 0px 3px;"></td>';
 193      echo '<td width="15" class="moduleListTitle" style="padding:0px 3px 0px 3px;"><input type="checkbox" name="selectall" onClick=toggleSelect(this.checked,"selected_id")></td>';
 194      echo '<td width="" class="moduleListTitle" style="padding:0px 3px 0px 3px;">Sender</td>';
 195      echo '<td width="" class="moduleListTitle" style="padding:0px 3px 0px 3px;">Subject</td>';
 196      echo '<td width="" class="moduleListTitle" style="padding:0px 3px 0px 3px;">Date</td>';
 197      echo '</tr>';
 198          
 199      for($i=$size-1;$i>=0;$i--)
 200      {
 201            $j = $i+1;
 202            $header = @imap_headerinfo($mbox, $j, 80, 80);
 203            
 204            $fromaddress[$j] = $header->from[0]->host;
 205            $domain = $fromaddress[$j];
 206            $fromname[$j] = $header->from[0]->mailbox;
 207            $sendername=$fromname[$j];
 208            $sender[$j]= $fromname[$j]."@".$fromaddress[$j];
 209            $totalfromaddress = $sendername ."@".$domain;
 210            
 211        $val=$overview[$i];
 212        $msg=$val->msgno;
 213            $from=$val->from;
 214           
 215        $date=$val->date;
 216        $subj=$val->subject;
 217        //transformHTML($subj);
 218        $seen=$val->seen;
 219            //imap_delete($mbox, 1);
 220            //imap_expunge($mbox);
 221  
 222        $from = ereg_replace("\"","",$from);
 223     
 224        // MAKE DANISH DATE DISPLAY
 225        list($dayName,$day,$month,$year,$time) = split(" ",$date); 
 226        $time = substr($time,0,5);
 227        $date = $day ." ". $month ." ". $year . " ". $time;
 228     
 229        if ($bgColor == "#F0F0F0") {
 230          $bgColor = "#FFFFFF";
 231          $rowClass = "oddListRow";
 232        } else {
 233          $bgColor = "#F0F0F0";
 234          $rowClass = "evenListrow";
 235          }
 236     
 237        if (strlen($subj) > 60) {
 238          $subj = substr($subj,0,59) ."...";
 239          get_part();
 240          }
 241            
 242        echo "<tr class=\"$rowClass\"><td height=\"21\" style=\"padding:0px 3px 0px 3px;\">$msg</td><td style=\"padding:0px 3px 0px 3px;\"><input type=checkbox NAME=\"selected_id\" onClick=toggleSelectAll(this.name,\"selectall\")>$sendername</td><td style=\"padding:0px 3px 0px 3px;\">$totalfromaddress </td><td style=\"padding:0px 3px 0px 3px;\"><a href=\"index.php?action=mailbox&module=Emails&view=".$j."\">$subj</a></td>
 243              <td style=\"padding:0px 3px 0px 3px;\">$date</td></tr>\n ";
 244      }
 245  
 246      echo "</table>";
 247      echo "</form>";
 248  }
 249  imap_close($mbox);
 250  
 251  
 252  
 253  
 254  
 255  function get_mime_type(&$structure) 
 256  {
 257      global $log;
 258      $log->debug("Entering get_mime_type(".$structure.") method ...");
 259    $primary_mime_type = array("TEXT", "MULTIPART","MESSAGE", "APPLICATION", "AUDIO","IMAGE", "VIDEO", "OTHER");
 260    if($structure->subtype) {
 261      $log->debug("Exiting get_mime_type method ...");
 262      return $primary_mime_type[(int) $structure->type] . '/' .$structure->subtype;
 263    }
 264      $log->debug("Exiting get_mime_type method ...");
 265    return "TEXT/PLAIN";
 266  }
 267  
 268  
 269  function get_part($stream, $msg_number, $mime_type, $structure = false,$part_number    = false) 
 270  {
 271       global $log;
 272          $log->debug("Entering get_part(".$stream.", ".$msg_number.", ".$mime_type.", ".$structure.",".$part_number.") method ...");
 273   
 274      if(!$structure) {
 275      $structure = imap_fetchstructure($stream, $msg_number);
 276    }
 277    if($structure) {
 278      if($mime_type == get_mime_type($structure)) {
 279        if(!$part_number) {
 280          $part_number = "1";
 281        }
 282        $text = imap_fetchbody($stream, $msg_number, $part_number);
 283        if($structure->encoding == 3) {
 284      $log->debug("Exiting get_part method ...");
 285          return imap_base64($text);
 286        } else if($structure->encoding == 4) {
 287      $log->debug("Exiting get_part method ...");
 288          return imap_qprint($text);
 289        } else {
 290      $log->debug("Exiting get_part method ...");
 291          return $text;
 292        }
 293      }
 294     
 295      if($structure->type == 1) /* multipart */ {
 296        while(list($index, $sub_structure) = each($structure->parts)) {
 297          if($part_number) {
 298            //$prefix = $part_number . '.';
 299            $prefix = $part_number ;
 300          }
 301          $data = get_part($stream, $msg_number, $mime_type, $sub_structure,$prefix .    ($index + 1));
 302          if($data) {
 303          $log->debug("Exiting get_part method ...");
 304            return $data;
 305          }
 306        } // END OF WHILE
 307      } // END OF MULTIPART
 308    } // END OF STRUTURE
 309    $log->debug("Exiting get_part method ...");
 310    return false;
 311  } // END OF FUNCTION
 312  
 313  
 314  /*
 315   // GET TEXT BODY
 316     $dataTxt = get_part($mbox, $msgno, "TEXT/PLAIN");
 317     
 318     // GET HTML BODY
 319     $dataHtml = get_part($mbox, $msgno, "TEXT/HTML");
 320     
 321     if ($dataHtml != "") {
 322         $msgBody = $dataHtml;
 323         $mailformat = "html";
 324     } else {
 325         $msgBody = ereg_replace("\n","<br>",$dataTxt);
 326         $mailformat = "text";
 327     }
 328      // To out put the message body to the user simply print $msgBody like this.
 329     
 330     if ($mailformat == "text") {
 331         echo "<html><head><title>Messagebody</title></head><body    bgcolor=\"white\">$msgBody</body></html>";
 332     } else {
 333         echo $msgBody; // It contains all HTML HEADER tags so we don't have to make them.
 334     }
 335  
 336  */
 337  
 338  
 339  
 340   function transformHTML($str) {
 341    global $log;
 342          $log->debug("Entering transformHTML(".$str.") method ...");
 343     if ((strpos($str,"<HTML") < 0) || (strpos($str,"<html")    < 0)) {
 344            $makeHeader = "<html><head><meta http-equiv=\"Content-Type\"    content=\"text/html; charset=iso-8859-1\"></head>\n";
 345         if ((strpos($str,"<BODY") < 0) || (strpos($str,"<body")    < 0)) {
 346             $makeBody = "\n<body>\n";
 347             $str = $makeHeader . $makeBody . $str ."\n</body></html>";
 348         } else {
 349             $str = $makeHeader . $str ."\n</html>";
 350         }
 351     } else {
 352         $str = "<meta http-equiv=\"Content-Type\" content=\"text/html;    charset=iso-8859-1\">\n". $str;
 353     }
 354          $log->debug("Exiting transformHTML method ...");
 355         return $str;
 356   }
 357     
 358   if ($dataHtml != "") {
 359      $msgBody = transformHTML($dataHtml);
 360   } else {
 361     $msgBody = ereg_replace("\n","<br>",$dataTxt);
 362     $msgBody = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i","$1http://$2",    $msgBody);
 363     $msgBody = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<A    TARGET=\"_blank\" HREF=\"$1\">$1</A>", $msgBody);
 364     $msgBody = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A    HREF=\"mailto:$1\">$1</A>",$msgBody);
 365   }
 366  
 367  
 368  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7