From: <guy...@us...> - 2003-04-28 02:28:01
|
Update of /cvsroot/outreach/opt/include In directory sc8-pr-cvs1:/tmp/cvs-serv17438 Modified Files: email.php Log Message: Adding a new type of project email source "list". This handles mailing list posts better than the other types. Index: email.php =================================================================== RCS file: /cvsroot/outreach/opt/include/email.php,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** email.php 31 Aug 2002 20:47:16 -0000 1.3 --- email.php 28 Apr 2003 02:12:08 -0000 1.4 *************** *** 31,35 **** // human-readable string in front of the e-mail address - you know, // the "John Doe" in "John Doe <j....@ib...>" ! if ($dest) { --- 31,35 ---- // human-readable string in front of the e-mail address - you know, // the "John Doe" in "John Doe <j....@ib...>" ! //echo("Dest on initial if is $dest<br>"); if ($dest) { *************** *** 43,47 **** $dest=substr($dest,1); } ! // echo("Dest: $dest<br>\n"); // The format for an e-mail that has to end up in the e-mail archive --- 43,47 ---- $dest=substr($dest,1); } ! //echo("dest_mail: $dest_mail<br>\n"); // The format for an e-mail that has to end up in the e-mail archive *************** *** 62,68 **** $proj=(substr($dest,$projpoz+1))+0; ! // echo("Processing $dest<br>\n"); $newreq=0; $dest_id=explode(" ",$dest); switch (strtolower($dest_id[1])) { --- 62,69 ---- $proj=(substr($dest,$projpoz+1))+0; ! //echo("Processing dest=$dest with proj=$proj<br>\n"); $newreq=0; $dest_id=explode(" ",$dest); + //echo("Switching on $dest_id[1]<br />"); switch (strtolower($dest_id[1])) { *************** *** 73,76 **** --- 74,80 ---- $thetable="requests"; break; + case "task": + $thetable="task"; + break; case "newrequest": $thetable="requests"; *************** *** 83,97 **** $thetable="forums"; break; default: ! // Let's check if this is an alias ! if ($m_start=strpos($dest_mail,"<")) //> { ! $dest_mail=substr($dest_mail,$mstart); $m_end=strpos($dest_mail,">"); $dest_mail=substr($dest_mail,0,$m_end); } ! // echo("dest_mail: $dest_mail"); $Sdest_mail=addslashes($dest_mail); ! list($proj)=OPT_fetch_row(CRM_run_query("select project from mail_repository where email='$Sdest_mail' and (entry_type & 1)=1")); if (!$proj) { return(0); --- 87,127 ---- $thetable="forums"; break; + case "events": + $thetable="events"; + break; default: ! // Let's check if this is an alias or a mailing list ! //echo("dest_mail before is: ".htmlspecialchars($dest_mail)."<br>"); ! $m_start=strpos($dest_mail,"<"); ! if (is_integer($m_start)) { ! $dest_mail=substr($dest_mail,$m_start+1); $m_end=strpos($dest_mail,">"); $dest_mail=substr($dest_mail,0,$m_end); } ! //echo("dest_mail after is: ".htmlspecialchars($dest_mail)."<br>"); $Sdest_mail=addslashes($dest_mail); ! $sql_query="select project, entry_type from mail_repository where email like ! '%$Sdest_mail%' and entry_type in (1,2)"; ! //echo(htmlspecialchars($sql_query)."<br />"); ! $addr_result=CRM_run_query($sql_query); ! if (OPT_num_rows($addr_result) == 1) ! { ! $addr_row=OPT_fetch_row($addr_result); ! $proj = $addr_row[0]; ! if ($addr_row[1] == 2) ! { // This is a mailing list so save who really sent it, even if they not an OPT user ! if (strpos($head["from"][0],"<")) ! { ! $dest_mail=substr($head["from"][0],strrpos($head["from"][0],"<")+1); ! $dest_mail=substr($dest_mail,0,strrpos($dest_mail,">")); ! } ! else ! { ! $dest_mail=$head["from"][0]; ! } ! } ! //echo("Found project $addr_row[0] with ".$head["from"][0]."<br>"); ! } if (!$proj) { return(0); *************** *** 105,114 **** $thetable="email"; $sender=OPT_gpc_slashes($sender); ! list($proj)=OPT_fetch_row(CRM_run_query("select project from mail_repository where email='$sender' and (entry_type & 1)=0")); if (!$proj) { return(0); } } ! // echo("Using table: $thetable<br>\n"); // Now, let's check if: --- 135,144 ---- $thetable="email"; $sender=OPT_gpc_slashes($sender); ! list($proj)=OPT_fetch_row(CRM_run_query("select project from mail_repository where email like '%$sender%' and (entry_type & 1)=0")); if (!$proj) { return(0); } } ! //echo("Using table: $thetable<br>\n"); // Now, let's check if: *************** *** 139,142 **** --- 169,178 ---- || ( + (strtolower($dest_id[1])=="task") + && + (crm_perm("task",$aproj=$proj)) + ) + || + ( (strtolower($dest_id[1])=="document") && *************** *** 153,157 **** ) { ! // echo(getvalue("people","fname",$CRM_user)." has got permissions in project '".getvalue("projects","name",$aproj)."'!<br>\n"); // Now that everything's ok, we "just" have to parse the e-mail and upload // it into the database. --- 189,193 ---- ) { ! //echo(getvalue("people","fname",$CRM_user)." has got permissions in project '".getvalue("projects","name",$aproj)."'!<br>\n"); // Now that everything's ok, we "just" have to parse the e-mail and upload // it into the database. *************** *** 294,298 **** { $email_id=OPT_get_ID("email"); ! if ($dest) { $sql="insert into email set id=$email_id, body=\"$buffer\", project=$proj, --- 330,334 ---- { $email_id=OPT_get_ID("email"); ! if (intval($sender)) { $sql="insert into email set id=$email_id, body=\"$buffer\", project=$proj, *************** *** 302,315 **** { $sql="insert into email set id=$email_id, body=\"$buffer\", project=$proj, ! emailSrc=\"$sender\", title=\"$title\", $thedate"; } $result=CRM_run_query($sql); } ! elseif ($thetable=="requests") { if ($newreq==0) { $sql="insert into request_answers set comment=\"$buffer\", ! request=$proj, src=$sender, $thedate"; CRM_run_query($sql); --- 338,352 ---- { $sql="insert into email set id=$email_id, body=\"$buffer\", project=$proj, ! emailSrc=\"$dest_mail\", title=\"$title\", $thedate"; } + //echo("$sql<br>"); $result=CRM_run_query($sql); } ! elseif ($thetable=="requests" && intval($sender)) { if ($newreq==0) { $sql="insert into request_answers set comment=\"$buffer\", ! request=$proj, src=$sender, $thedate"; CRM_run_query($sql); *************** *** 326,335 **** // We'll find out who's involved. ! $requestor_id=getvalue("requests","src",$req); ! $dst[]=$sender; ! if ($sender!=$requestor_id) { ! $dst[]=$requestor_id; ! } if (($owner) && ($owner!=$sender) && ($owner!=$requestor_id)) { --- 363,377 ---- // We'll find out who's involved. ! $notify_src=getvalue("requests","notify_src",$req,""); ! $sql="select person from request_submitters where request = $req"; ! $submitters_result=CRM_run_query($sql); ! while ($submitter_row=OPT_fetch_row($submitters_result)) { ! if (($notify_src == "1") && !@in_array($submitter_row[0],$dst)) ! { ! $dst[]=$submitter_row[0]; ! } ! } ! if (($owner) && ($owner!=$sender) && ($owner!=$requestor_id)) { *************** *** 430,434 **** } } ! elseif ($thetable=="documents") { $sql="insert into document_answers set comment=\"$buffer\", --- 472,539 ---- } } ! elseif ($thetable=="task" && intval($sender)) ! { ! $sql="INSERT INTO task_history SET taskID=$proj, record=\"$buffer\", ! authorID=$sender,Posted=".time(); ! CRM_run_query($sql); ! ! // And we'll also do the notifications in here ! $tk[]="TaskName"; ! $tk[]="TaskDesc"; ! $tkt=getvalue("task",$tk,$proj); ! $title=$tkt[0]; ! $comments=$tkt[1]; ! ! // We'll find out who's involved with this task ! $sql="select personID from person_task where taskID = $proj"; ! $involved_result=CRM_run_query($sql); ! while ($involved_row=OPT_fetch_row($involved_result)) ! { ! if (($involved_row[0] != $CRM_user) && !@in_array($involved_row[0],$dst)) ! { ! $dst[]=$involved_row[0]; ! } ! } ! ! $v[]="email"; ! $v[]="sal"; ! $v[]="fname"; ! $v[]="lname"; ! $s=getvalue("people",$v,$CRM_user); ! $pn=getvalue("task", "ProjectID", $proj); ! $p_n=getvalue("projects","name",$pn); ! $title=stripslashes($title); ! $comments=stripslashes($buffer); ! for ($i=0;$i<sizeOf($dst);$i++) // > ! { ! OPT_locale($dst[$i]); ! $d=getvalue("people",$v,$dst[$i]); ! $name="$d[1] $d[3]"; ! OPT_notify($dst[$i],sprintf(__("New comment on OPT task %s"),"#$proj, \"$title\""), ! sprintf(__("Dear %s,\n". ! "%s posted a new comment on task %s ". ! "related to the %s project.\n\n". ! "The task description follows:\n". ! "------------------------------------------------------------------------\n". ! "%s\n". ! "------------------------------------------------------------------------\n\n". ! "The newly posted comment follows:\n". ! "------------------------------------------------------------------------\n". ! "%s\n". ! "------------------------------------------------------------------------\n". ! "This task is accessible on the OPT server at this URL:\n"),$name, ! "$s[1] $s[2] $s[3]","#$task, \"$title\"","\"$p_n\"",$comments,$comment). ! "http://$SERVER_NAME$CRM_URL?URL=". ! rawurlencode("tasks/task/?action=display&proj=$proj&task=$proj"), ! __("You may post comments on the task by replying ". ! "to this e-mail. Please note only the message body will be ". ! "uploaded to OPT. You may also post comments by ". ! "visiting the OPT site.\n\nIMPORTANT!\nIn case you reply to this e-mail, ". ! "please don't quote the original message since the quotation ". ! "will also get unnecessarily posted on OPT.\n\nThank you!"), ! "OPT task #$proj <$CRM_system_email>"); ! } ! } ! elseif ($thetable=="documents" && intval($sender)) { $sql="insert into document_answers set comment=\"$buffer\", *************** *** 479,483 **** "OPT document #$doc <$CRM_system_email>",0); } ! elseif ($thetable=="forums") { $msg=OPT_get_ID("forums"); --- 584,588 ---- "OPT document #$doc <$CRM_system_email>",0); } ! elseif ($thetable=="forums" && intval($sender)) { $msg=OPT_get_ID("forums"); *************** *** 491,494 **** --- 596,606 ---- forum_notifications($msg,true); // The second parameter inhibits on-screen confirmations } + elseif ($thetable=="events" && intval($sender)) + { + $msg=OPT_get_ID("event_comments"); + $sql="insert into event_comments set id=$msg, comment=\"$buffer\", + event=$proj, src=$sender, $thedate"; + CRM_run_query($sql); + } } elseif ($thetable=="email") *************** *** 577,584 **** for($i=0;$i<sizeof($head);$i++) //> { ! if ((substr($val,-1)==";") || (substr($head[$i],0,1)=="\t")) { $val.=$head[$i]; $header[$key][sizeof($header[$key])-1]=$val; } else --- 689,697 ---- for($i=0;$i<sizeof($head);$i++) //> { ! if ((substr($val,-1)==";") || (substr($head[$i],0,1)=="\t") || (!ereg("^[a-zA-Z0-9]", substr($head[$i],0,1)))) { $val.=$head[$i]; $header[$key][sizeof($header[$key])-1]=$val; + //echo(htmlspecialchars("Adding header: key=$key, index=". (sizeof($header[$key])-1) .", val=$val")."<br />"); } else *************** *** 594,597 **** --- 707,711 ---- $cpos--; } + //echo(htmlspecialchars("Adding new header: key=$key, cpos=$cpos, val=$val")."<br />"); $header[$key][$cpos]=$val; } *************** *** 618,621 **** --- 732,736 ---- for ($i=0;$i<sizeOf($messages);$i++) // > { + unset($sender); $fname="$temp_CRM_dir/$messages[$i]"; $fh=fopen($fname,"r"); *************** *** 634,638 **** $head=OPT_headerinfo($header); $from=$head["from"][0]; ! // echo("Processing from field: $from<br>\n"); if (strpos($from,"<")) // > { --- 749,753 ---- $head=OPT_headerinfo($header); $from=$head["from"][0]; ! //echo("Processing from field: $from<br>\n"); if (strpos($from,"<")) // > { *************** *** 640,646 **** $sender=substr($sender,0,strrpos($sender,">")); } $sql="select id from people where email='$sender'"; $result=CRM_run_query($sql); ! // echo("Searching for $sender<br>\n"); if (!OPT_num_rows($result)) { $sql="select entry_id from mail_xtra where entry_type='people' and email='$sender'"; --- 755,765 ---- $sender=substr($sender,0,strrpos($sender,">")); } + else + { + $sender=$from; + } $sql="select id from people where email='$sender'"; $result=CRM_run_query($sql); ! //echo("Searching for $sender<br>\n"); if (!OPT_num_rows($result)) { $sql="select entry_id from mail_xtra where entry_type='people' and email='$sender'"; *************** *** 649,653 **** if ($myrow=OPT_fetch_row($result)) { ! // echo($sender." is registered<br>\n"); $CRM_user=$myrow[0]; $CRM_comp=getvalue("people","company",$CRM_user); --- 768,772 ---- if ($myrow=OPT_fetch_row($result)) { ! //echo($sender." is registered<br>\n"); $CRM_user=$myrow[0]; $CRM_comp=getvalue("people","company",$CRM_user); *************** *** 672,676 **** $old_k=$k; ! // Scanning the "to" list for ($m=0;$head["to"][$m];$m++) --- 791,795 ---- $old_k=$k; ! // Scanning the "to" list for ($m=0;$head["to"][$m];$m++) *************** *** 681,684 **** --- 800,804 ---- $to=trim($to_array[$n]); if ($to) { + //echo("About to call testMail with to of: $to<br />"); $k+=testMail($messages[$i],$head,$CRM_user, $to); } *************** *** 689,696 **** --- 809,818 ---- for ($m=0;$head["cc"][$m];$m++) { + //echo("CC is ".$head["cc"][$m]."<br />"); $cc_array=explode(",",$head["cc"][$m]); for ($n=0;$n<sizeof($cc_array);$n++) //> { $cc=trim($cc_array[$n]); + //echo("About to call testMail with cc of: $cc<br />"); if ($cc) { $k+=testMail($messages[$i],$head,$CRM_user, $cc); *************** *** 703,706 **** --- 825,829 ---- { if ($head["subject"]) { + //echo("About to call testMail with subject<br />"); $k+=testMail($messages[$i],$head,$CRM_user,$head["subject"][0]); } *************** *** 716,723 **** else { ! $sql="select project from mail_repository where email=\"$sender\" and (entry_type & 1)=0"; $result=CRM_run_query($sql); if (OPT_fetch_row($result)) { $k+=testMail($messages[$i],$head,$sender); } --- 839,847 ---- else { ! $sql="select project from mail_repository where email like \"%$sender%\" and entry_type = 0"; $result=CRM_run_query($sql); if (OPT_fetch_row($result)) { + //echo("Trying testmail because of sender match: $sql<br>"); $k+=testMail($messages[$i],$head,$sender); } *************** *** 725,729 **** { ! // Ok, nothing else worked - we'll now check for server aliases. $old_k=$k; --- 849,853 ---- { ! // Ok, nothing else worked - we'll now check for server aliases or mailing lists. $old_k=$k; *************** *** 736,740 **** { $to=trim($to_array[$n]); ! if ($to) { $k+=testMail($messages[$i],$head,$sender,$to); } --- 860,865 ---- { $to=trim($to_array[$n]); ! if ($to) { ! //echo("Trying testmail for to=$to<br>"); $k+=testMail($messages[$i],$head,$sender,$to); } *************** *** 750,753 **** --- 875,879 ---- $cc=trim($cc_array[$n]); if ($cc) { + //echo("Trying testmail for cc=$cc<br>"); $k+=testMail($messages[$i],$head,$sender,$cc); } *************** *** 876,891 **** { global $OPT_col_lt; ! echo("<SCRIPT LANGUAGE='JavaScript1.1' type='text/javascript'><!--\n"); ! echo("var emailWin;\nemailWin=window.open('','_blank','width=300,height=100,status=no,toolbar=no,menubar=no,location=no,resizable=no,titlebar=no,scrollbars=no,fullscreen=no,top=2,left=2');\n"); ! echo("emailWin.document.write('<HEAD><TITLE>OPT Message window</TITLE>".$_OPT["head_xtra"]."</HEAD>');\n"); ! echo("emailWin.document.write('<HTML><BODY bgcolor=\"$OPT_col_lt\"><CENTER><BIG><B>Parsing ".sizeOf($messages)." e-mail message(s)</B></BIG></CENTER></BODY></HTML>');\n"); ! echo("function closeEmailWin() {\n emailWin.close();\n}\n"); ! echo("//--></script>\n"); ! flush(); processMail($messages); ! echo("<SCRIPT LANGUAGE='JavaScript1.1' type='text/javascript'><!--\n"); ! echo("timer=setTimeout('closeEmailWin()',1);\n"); ! echo("//--></script>\n"); } $CRM_demo=$CDMO; ignore_user_abort($iab); --- 1002,1024 ---- { global $OPT_col_lt; ! if (is_admin()) ! { ! echo("<SCRIPT LANGUAGE='JavaScript1.1' type='text/javascript'><!--\n"); ! echo("var emailWin;\nemailWin=window.open('','_blank','width=300,height=100,status=no,toolbar=no,menubar=no,location=no,resizable=no,titlebar=no,scrollbars=no,fullscreen=no,top=2,left=2');\n"); ! echo("emailWin.document.write('<HEAD><TITLE>OPT Message window</TITLE>".$_OPT["head_xtra"]."</HEAD>');\n"); ! echo("emailWin.document.write('<HTML><BODY bgcolor=\"$OPT_col_lt\"><CENTER><BIG><B>Parsing ".sizeOf($messages)." e-mail message(s)</B></BIG></CENTER></BODY></HTML>');\n"); ! echo("function closeEmailWin() {\n emailWin.close();\n}\n"); ! echo("//--></script>\n"); ! flush(); ! } processMail($messages); ! if (is_admin()) ! { ! echo("<SCRIPT LANGUAGE='JavaScript1.1' type='text/javascript'><!--\n"); ! echo("timer=setTimeout('closeEmailWin()',1);\n"); ! echo("//--></script>\n"); ! } } + $CRM_demo=$CDMO; ignore_user_abort($iab); |