Exemplo n.º 1
0
function uddeIMshowPostboxUser($myself, $userid, $item_id, $limit, $limitstart, $cryptpass, $config, $filter_user, $filter_unread, $filter_flagged, $sort_mode) {
	global $uddeicons_delayedpic, $uddeicons_flagged, $uddeicons_unflagged, $uddeicons_onlinepic, $uddeicons_offlinepic, $uddeicons_readpic, $uddeicons_unreadpic;
	
	$pathtosite = uddeIMgetPath('live_site');

	// invoke pruning if set so
	$my_gid = $config->usergid;

	// message limit for inbox?
	if ($config->inboxlimit && $config->allowarchive) {
		$universeflag = _UDDEIM_ARC_UNIVERSE_BOTH;	// inbox and archive
	} else {
		$universeflag = _UDDEIM_ARC_UNIVERSE_INBOX;	// inbox
	}

	if ($config->inboxlimit && $config->allowarchive) {		// inbox + archive, already stored messages in archive are not counted, when archive is disabled
		$total = uddeIMgetInboxArchiveCount($myself);
	} else {
		$total = uddeIMgetInboxCount($myself);				// also used for navigation
	}

	$limitwarning = "";
	// "You have XX messages in your inbox/inbox+archive."
	$limitreached = _UDDEIM_INBOX_LIMIT_1." ".$total;
	$limitreached.= " ".($total==1 ? _UDDEIM_INBOX_LIMIT_2_SINGULAR : _UDDEIM_INBOX_LIMIT_2)." ";
	$limitreached.= $universeflag;

	if ($config->inboxlimit) {		// there is a limit for inbox + archive
		if (!uddeIMisAdmin($my_gid) && !uddeIMisAdmin2($my_gid, $config)) {
			// "The allowed maximum is XX."
			// $limitreached.= _UDDEIM_INBOX_LIMIT_3." ".$config->maxarchive.". ";
			$limitreached.= " "._UDDEIM_SHOWINBOXLIMIT_2." ".$config->maxarchive.").";	// (of max. )

			if ($total > $config->maxarchive) {
				$limitwarning = _UDDEIM_INBOX_LIMIT_4;		// You can still receive and read messages but you will not be able to reply or to compose new ones until you delete messages.
			}
		}
	} else {						// there is a limit for the archive only
		$limitreached.= ".";		// so inbox is unlimited
	}

	


	$totalpostbox = uddeIMgetPostboxUserCount($myself, $userid, $filter_user, $filter_unread, $filter_flagged);

	// now load messages as required
	if(!$limitstart)
		$limitstart = 0;

	if(!$limit)
		$limit=$config->perpage;

	if ($limitstart>=$totalpostbox)
		$limitstart=max(0,$limitstart - $limit);

	// $allmessages = uddeIMselectInbox($myself, $limitstart, $limit, $config, $filter_user, $filter_unread, $filter_flagged, $sort_mode);
	$allmessages = uddeIMselectPostboxUser($myself, $userid, $limitstart, $limit, $config);


	// write the uddeim menu
	uddeIMprintMenu($myself, 'inbox', $item_id, $config);
	echo "<div id='uddeim-m'>\n";

	//if ($config->enablefilter==1 || $config->enablefilter==3)
	//	uddeIMprintFilter($myself, 'postboxuser', $totalpostbox, $item_id, $config, $filter_user, $filter_unread, $filter_flagged);

	// if no messages:
	if (count($allmessages)<1) { // no messages to list
		uddeIMshowNoMessage('postbox', $filter_user, $filter_unread, $filter_flagged);
		echo "</div>\n<div id='uddeim-bottomborder'>".uddeIMcontentBottomborder($myself, $item_id, 'standard', 'none', $config)."</div>\n";
		return;
	}

	uddeIMaddScript($pathtosite."/components/com_uddeim/js/uddeimtools.js");



	if ($config->blocksystem) {
		if ($userid && $userid!=$myself) {
			$isblocked = uddeIMcheckBlockerBlocked($myself, $userid);
			if (!$isblocked) {
				echo "<div id='uddeim-block'>";
				echo "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td align='left'>";
				$blockcell = "<div style='text-align:right;'><a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=blockuser&Itemid=".$item_id."&recip=".$userid."&ret=postboxuser")."'>"._UDDEIM_BLOCKNOW."</a></div>";
				echo $blockcell;
				echo "</td></tr></table>";
				echo "</div>";
			}
		}
	}
	
	

	echo "<form method='post' name='messages' action='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=inboxfork&Itemid=".$item_id)."'>\n";
	// now open the inbox container and table; write table headings
	echo "<div id='uddeim-overview'>";
	echo "<table cellpadding='7' width='100%'>\n";
	// checkcell
	$delall="<input type=\"checkbox\" name=\"arcmes[]\" value=\"\" onclick=\"wiglwogl(this);\" title=\""._UDDEIM_CHECKALL."\" />";
	echo "<tr>";
	echo "<th style='border:none; text-align:center;' class='sectiontableheader'>".$delall."</th>";
	echo "<th style='border:none;' class='sectiontableheader'>&nbsp;</th>";
	echo "<th style='border:none;' class='sectiontableheader'>"._UDDEIM_FROM."/"._UDDEIM_TO."</th>";
	echo "<th style='border:none;' class='sectiontableheader'>"._UDDEIM_DATE."</th>";
	echo "<th style='border:none;' class='sectiontableheader'>&nbsp;</th>";
	echo "</tr>\n";

	$k = 1;
	$i = 1;
	// now write the list
	foreach($allmessages as $themessage) {

		$isinbox = 0;
		$isoutbox = 0;
		if ($myself==$themessage->toid && $myself!=$themessage->fromid) {
			$isinbox = 1;
		} elseif ($myself==$themessage->fromid && $myself!=$themessage->toid) {
			$isoutbox = 1;
		} else {	// this case appears when a copy to me message has been trashed my myself
			$isinbox = 1;
		}

		$is_spam = 0;
		if ($config->reportspam)		// save one database query if possible
			$is_spam = uddeIMgetSpamStatus($themessage->id);

		$flagcell = "";
		$archivecell = "";
		$fwdcell = "";
		$deletecell = "";
		$recallcell = "";
		$attachcell = "";
		$spamcell = "";
		$spamcellflag = "";

		if ($isinbox) {
			if($config->allowflagged) {
				if($themessage->flagged)
					$flagcell="<br /><a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=unflag&recip=".$userid."&ret=postboxuser&Itemid=".$item_id."&messageid=".$themessage->id."&limit=".$limit."&limitstart=".$limitstart)."'>".$uddeicons_flagged."</a>";
				else
					$flagcell="<br /><a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=flag&recip=".$userid."&ret=postboxuser&Itemid=".$item_id."&messageid=".$themessage->id."&limit=".$limit."&limitstart=".$limitstart)."'>".$uddeicons_unflagged."</a>";
			}
			if($themessage->toread)
				$readcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=markunread&recip=".$userid."&ret=postboxuser&Itemid=".$item_id."&messageid=".$themessage->id."&limit=".$limit."&limitstart=".$limitstart)."'>".$uddeicons_readpic."</a>";
			else
				$readcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=markread&recip=".$userid."&ret=postboxuser&Itemid=".$item_id."&messageid=".$themessage->id."&limit=".$limit."&limitstart=".$limitstart)."'>".$uddeicons_unreadpic."</a>";

			if ($config->showlistattachment) {
				$cnt = uddeIMgetAttachmentCount($themessage->id);
				if ($cnt)
					$attachcell = "<br /><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/attachment.gif' alt='"._UDDEIM_ATTACHMENT."' title='"._UDDEIM_ATTACHMENT."' border='0' />";
			}

			if ($config->actionicons) {
				$deletecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=postboxdeleteinbox&recip=".$userid."&Itemid=".$item_id."&limit=".$limit."&limitstart=".$limitstart."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/trash.gif' alt='"._UDDEIM_DELETELINK."' title='"._UDDEIM_DELETELINK."' /></a>";
				if ($config->allowforwards) {
					if ($themessage->cryptmode==2 || $themessage->cryptmode==4) {	// Message is encrypted, so go to enter password page
						$fwdcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=forwardpass&Itemid=".$item_id."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/forward.gif' alt='"._UDDEIM_FORWARDLINK."' title='"._UDDEIM_FORWARDLINK."' /></a><br />";
					} else {	// normal message
						$fwdcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=forward&Itemid=".$item_id."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/forward.gif' alt='"._UDDEIM_FORWARDLINK."' title='"._UDDEIM_FORWARDLINK."' /></a><br />";
					}
				}
				if ($config->allowarchive && $themessage->toread)
					$archivecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=archivemessage&Itemid=".$item_id."&limit=".$limit."&limitstart=".$limitstart."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/archive.gif' alt='"._UDDEIM_STORE."' title='"._UDDEIM_STORE."' /></a><br />";
			} else {
				$deletecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=postboxdeleteinbox&recip=".$userid."&Itemid=".$item_id."&limit=".$limit."&limitstart=".$limitstart."&messageid=".$themessage->id)."'>"._UDDEIM_DELETELINK."</a>";
				if ($config->allowforwards) {
					if ($themessage->cryptmode==2 || $themessage->cryptmode==4) {	// Message is encrypted, so go to enter password page
						$fwdcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=forwardpass&Itemid=".$item_id."&messageid=".$themessage->id)."'>"._UDDEIM_FORWARDLINK."</a><br />";
					} else {	// normal message
						$fwdcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=forward&Itemid=".$item_id."&messageid=".$themessage->id)."'>"._UDDEIM_FORWARDLINK."</a><br />";
					}
				}
				if ($config->allowarchive && $themessage->toread)
					$archivecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=archivemessage&Itemid=".$item_id."&limit=".$limit."&limitstart=".$limitstart."&messageid=".$themessage->id)."'>"._UDDEIM_STORE."</a><br />";
			}

			if ($config->reportspam) {		// uddeIMcheckPlugin('spamcontrol') &&  not required since uddeIMcheckConfig sets this 0 if plugin is missing
				if ($is_spam) {
					$spamcell = "<br /><br /><a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=unreportspam&Itemid=".$item_id."&messageid=".$themessage->id."&recip=".$userid."&ret=postboxuser")."'>"._UDDEIM_SPAMCONTROL_UNREPORT."</a>";
					$spamcellflag = "<br /><div class='uddeim-messagefrom-spam'>"._UDDEIM_SPAMCONTROL_MARKED."</div>";
				} else {
					$spamcell = "<br /><br /><a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=reportspam&Itemid=".$item_id."&messageid=".$themessage->id."&recip=".$userid."&ret=postboxuser")."'>"._UDDEIM_SPAMCONTROL_REPORT."</a>";
				}
			}
		}

		if ($isoutbox) {
			if ($themessage->delayed) {
				$readcell=$uddeicons_delayedpic;
			} else {
				if ($themessage->toread)
					$readcell=$uddeicons_readpic;
				else
					$readcell=$uddeicons_unreadpic;
			}

			if ($config->showlistattachment) {
				$cnt = uddeIMgetAttachmentCount($themessage->id);
				if ($cnt)
					$attachcell = "<br /><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/attachment.gif' alt='"._UDDEIM_ATTACHMENT."' title='"._UDDEIM_ATTACHMENT."' border='0' />";
			}

			if ($config->actionicons) {
				$deletecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=postboxdeleteoutbox&recip=".$userid."&Itemid=".$item_id."&limit=".$limit."&limitstart=".$limitstart."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/trash.gif' alt='"._UDDEIM_DELETELINK."' title='"._UDDEIM_DELETELINK."' /></a>";
				if ($config->allowforwards) {
					if ($themessage->cryptmode==2 || $themessage->cryptmode==4) {	// Message is encrypted, so go to enter password page
						$fwdcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=forwardoutboxpass&Itemid=".$item_id."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/forward.gif' alt='"._UDDEIM_FORWARDLINK."' title='"._UDDEIM_FORWARDLINK."' /></a><br />";
					} else {	// normal message
						$fwdcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=forwardoutbox&Itemid=".$item_id."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/forward.gif' alt='"._UDDEIM_FORWARDLINK."' title='"._UDDEIM_FORWARDLINK."' /></a><br />";
					}
				}
			} else {
				$deletecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=postboxdeleteoutbox&recip=".$userid."&Itemid=".$item_id."&limit=".$limit."&limitstart=".$limitstart."&messageid=".$themessage->id)."'>"._UDDEIM_DELETELINK."</a>";
				if ($config->allowforwards) {
					if ($themessage->cryptmode==2 || $themessage->cryptmode==4) {	// Message is encrypted, so go to enter password page
						$fwdcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=forwardoutboxpass&Itemid=".$item_id."&messageid=".$themessage->id)."'>"._UDDEIM_FORWARDLINK."</a><br />";
					} else {	// normal message
						$fwdcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=forwardoutbox&Itemid=".$item_id."&messageid=".$themessage->id)."'>"._UDDEIM_FORWARDLINK."</a><br />";
					}
				}
			}
			if(!$themessage->toread) {	// if not read then a recall is possible
				if($config->actionicons) {
					if ($themessage->cryptmode==2 || $themessage->cryptmode==4) {	// Message is encrypted, so go to enter password page
						$recallcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=recallpass&Itemid=".$item_id."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/restore.gif' alt='"._UDDEIM_RECALL."' title='"._UDDEIM_RECALL."' /></a><br />";
					} else {	// normal message
						$recallcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=recall&Itemid=".$item_id."&messageid=".$themessage->id)."'><img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/restore.gif' alt='"._UDDEIM_RECALL."' title='"._UDDEIM_RECALL."' /></a><br />";
					}
				} else {
					if ($themessage->cryptmode==2 || $themessage->cryptmode==4) {	// Message is encrypted, so go to enter password page
						$recallcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=recallpass&Itemid=".$item_id."&messageid=".$themessage->id)."'>"._UDDEIM_RECALL."</a><br />";
					} else {	// normal message
						$recallcell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=recall&Itemid=".$item_id."&messageid=".$themessage->id)."'>"._UDDEIM_RECALL."</a><br />";
					}
				}
			}
		}

		


		if ($isinbox) {
			if ($config->actionicons) {
				$newemail = "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=reply&recip=".$userid."&Itemid=".$item_id."&messageid=".$themessage->id)."'>";
				$newemail .= "<img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/menu_new.gif' alt='"._UDDEIM_COMPOSE."' />";
				$newemail .= "</a>";
			} else {
				$newemail = "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=reply&recip=".$userid."&Itemid=".$item_id."&messageid=".$themessage->id)."'>"._UDDEIM_COMPOSE."</a>";
			}
		}
		if ($isoutbox) {
			if ($config->actionicons) {
				$newemail = "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=new&recip=".$userid."&Itemid=".$item_id)."'>";
				$newemail .= "<img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/menu_new.gif' alt='"._UDDEIM_COMPOSE."' />";
				$newemail .= "</a>";
			} else {
				$newemail = "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=new&recip=".$userid."&Itemid=".$item_id)."'>"._UDDEIM_COMPOSE."</a>";
			}
		}

		
		
		// CRYPT
		$cm = uddeIMgetMessage($themessage->message, $cryptpass, $themessage->cryptmode, $themessage->crypthash, $config->cryptkey);
		$teasermessage=$cm;
		// if it is a system message or bb codes allowed, parse BB codes
		if ($themessage->systemflag || $config->allowbb)
			$teasermessage=uddeIMbbcode_strip($teasermessage);

		$teasermessage=uddeIMteaser(stripslashes($teasermessage), $config->firstwordsinbox, $config->quotedivider, $config->languagecharset);
		$teasermessage=htmlspecialchars($teasermessage, ENT_QUOTES, $config->charset);
		$teasermessage=str_replace("&amp;#", "&#", $teasermessage);
		$safemessage=htmlspecialchars(stripslashes($cm), ENT_QUOTES, $config->charset);

		$showemail = "";
		if ($isinbox) {
			if ($themessage->cryptmode==2 || $themessage->cryptmode==4) {	// Message is encrypted, so go to enter password page
				$messagecell= "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=showpass&Itemid=".$item_id."&messageid=".$themessage->id)."'>".$teasermessage."</a>";
				$showemail  = "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=showpass&Itemid=".$item_id."&messageid=".$themessage->id)."'>";
				$showemail .= "<img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/page_white_magnify.gif' alt='"._UDDEIM_DISPLAY."' />";;
				$showemail .= "</a>";
			} else {							// normal message
				// $messagecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=show&Itemid=".$item_id."&messageid=".$themessage->id)."'>".$teasermessage."</a>";
				$messagecell="<a href='javascript:uddeIMtoggleLayer2(\"".$i."\");'>".$teasermessage."</a>";
				$showemail  = "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=show&Itemid=".$item_id."&messageid=".$themessage->id)."'>";
				$showemail .= "<img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/page_white_magnify.gif' alt='"._UDDEIM_DISPLAY."' />";;
				$showemail .= "</a>";
			}
		}
		if ($isoutbox) {
			if ($themessage->cryptmode==2 || $themessage->cryptmode==4) {	// Message is encrypted, so go to enter password page
				$messagecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=showoutpass&Itemid=".$item_id."&messageid=".$themessage->id)."'>".$teasermessage."</a>";
				$showemail  = "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=showoutpass&Itemid=".$item_id."&messageid=".$themessage->id)."'>";
				$showemail .= "<img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/page_white_magnify.gif' alt='"._UDDEIM_DISPLAY."' />";;
				$showemail .= "</a>";
			} else {	// normal message
				// $messagecell="<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=showout&Itemid=".$item_id."&messageid=".$themessage->id)."'>".$teasermessage."</a>";
				$messagecell="<a href='javascript:uddeIMtoggleLayer2(\"".$i."\");'>".$teasermessage."</a>";
				$showemail  = "<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=showout&Itemid=".$item_id."&messageid=".$themessage->id)."'>";
				$showemail .= "<img src='".$pathtosite."/components/com_uddeim/templates/".$config->templatedir."/images/page_white_magnify.gif' alt='"._UDDEIM_DISPLAY."' />";;
				$showemail .= "</a>";
			}
		}

		$datumcell=uddeDate($themessage->datum, $config, uddeIMgetUserTZ());

		// checkcell
		$delcell="<input type='checkbox' name='arcmes[]' value='".$themessage->id."' />";

		//echo "<tr class='sectiontableentry1'>";
		echo "<tr class='uddeim-messagebody2header'>";
		echo "<td style='padding:4px; border-bottom:none; border-right:none; width:32px; text-align:center; vertical-align:top'>".$delcell."</td>";		// checkcell
		echo "<td style='padding:4px; border-bottom:none; border-right:none; width:32px; text-align:center; vertical-align:top'>".
						$readcell.$attachcell.$flagcell.
						"</td>";
		$st=uddeIMgetStyleForThumb($config);
		//echo "<td ".$st.">";
		echo "<td style='padding:4px; border-bottom:none; border-right:none; vertical-align:top'>";
		if ($isinbox)
			echo uddeIMdoInboxHeader($myself, $themessage, $config);
		if ($isoutbox)
			echo uddeIMdoOutboxHeader($myself, $themessage, $config);
		echo "</td>";
		echo "<td style='padding:4px; border-bottom:none; border-right:none; vertical-align:top'>";
		echo $datumcell;
		echo $spamcell.$spamcellflag;
		echo "</td>";
		if ($config->actionicons) {
			echo "<td style='padding:4px; border-bottom:none; width:32px; text-align:center; vertical-align:top'>".
//						$fwdcell.$recallcell.$archivecell.$deletecell."<br /><br />".$newemail.
						$fwdcell.$recallcell.$archivecell.$deletecell.
						"</td>";
		} else {
			echo "<td style='padding:4px; border-bottom:none; vertical-align:top' class='pathway'>".
						$fwdcell.$recallcell.$archivecell.$deletecell."<br /><br />".$newemail.
						"</td>";
		}
		echo "</tr>\n";

		
//		if ($themessage->cryptmode!=2 && $themessage->cryptmode!=4) {	// Message is encrypted, so display no message

			// ############################################################# MESSSAGE

			$cm = uddeIMgetMessage($themessage->message, $cryptpass, $themessage->cryptmode, $themessage->crypthash, $config->cryptkey);

			// echo str_replace("&amp;#", "&#", nl2br(htmlspecialchars(stripslashes($cm), ENT_QUOTES, $config->charset)));
			$dmessage = nl2br(htmlspecialchars(stripslashes($cm), ENT_QUOTES, $config->charset));
			$dmessage = str_replace("&amp;#", "&#", $dmessage);		// unicode workaround
			// if system message or bbcodes allowed, call parser
			if ($themessage->systemflag || $config->allowbb)
				$dmessage = uddeIMbbcode_replace($dmessage, $config);
			if ($config->allowsmile)
				$dmessage = uddeIMsmile_replace($dmessage, $config);
			$bodystring = $dmessage;			// converted message for email body


if (0) {
			echo "<tr class='uddeim-messagebody2body'>";
			echo "<td colspan='3' style='border-style:none; padding:0 8px 0 8px; text-align:left; vertical-align:bottom'>";
				echo str_replace("<br />", "", $fwdcell."&nbsp".$recallcell."&nbsp".$archivecell."&nbsp".$deletecell."&nbsp;&nbsp;&nbsp;".$newemail);
			echo "</td>";
			echo "<td colspan='2' style='border-style:none; padding:0 8px 0 8px; text-align:right; vertical-align:middle'>";
				echo str_replace("<br />", "", $readcell.$attachcell.$flagcell);
			echo "</td>";
			echo "</tr>";
}


			echo "<tr class='uddeim-messagebody2body'>";
			echo "<td colspan='4' style='padding:8px; border-top:none; border-right:none;'>";
				// echo "<div style='text-align:right;'><a href='javascript:uddeIMtoggleLayer2(\"".$i."\");'>"._UDDEADM_SPAMCONTROL_SHOWHIDE."</a></div>";

				if ($config->postboxfull==0) {
					$st_preview = "display:inline;";
					$st_normal = "display:none;";
				}
				if ($config->postboxfull==1) {
					if ($i==1) {
						$st_preview = "display:none;";
						$st_normal = "display:inline;";
					} else {
						$st_preview = "display:inline;";
						$st_normal = "display:none;";
					}
				}
				if ($config->postboxfull==2) {
					$st_preview = "display:none;";
					$st_normal = "display:inline;";
				}
				
				echo "<div id='uddeimdivlayerpreview_".$i."' style='".$st_preview."'>";
				echo "<div class='uddeim-messagebody2'>".$messagecell."</div>";
				echo "</div>\n";

				echo "<div id='uddeimdivlayer_".$i."' style='".$st_normal."'>";
				$messagecell="<a href='javascript:uddeIMtoggleLayer2(\"".$i."\");'>".uddeIMreplyquoteMarkup($bodystring,$config->quotedivider)."</a>";
				echo "<div class='uddeim-messagebody2'>".$messagecell."</div>";
				// UDDEIMFILE
				if( $config->enableattachment )	{ // Always show attachments when attachments are enabled
					if ($isinbox)
						uddeIMshowAttachments("inbox", $item_id, $themessage->id, $config);
					if ($isoutbox)
						uddeIMshowAttachments("outbox", $item_id, $themessage->id, $config);
				}
				echo "</div>\n";

			echo "</td>\n";
			echo "<td style='padding:4px; border-top:none; border-left:none; width:32px; text-align:center; vertical-align:top'>";
				echo $newemail."<br />".$showemail;
			echo "</td>\n";
			echo "</tr>\n";
//		}
		

		
		$i++;
		$k++;
		if ($k > 2)
			$k = 1;
	}

	$muldel = uddeIMsefRelToAbs("index.php?option=com_uddeim&task=mulpostboxdelete&Itemid=".$item_id."&recip=".$userid."&limitstart=0&limit=".$limit);
	if($config->bottomlineicons) {
		echo "<tr><th style='border:none; text-align:center;' class='sectiontablefooter'>";
		echo '<a href="#" onclick="inboxDelete(\''.$muldel.'\'); return false;"><img src="'.$pathtosite.'/components/com_uddeim/templates/'.$config->templatedir.'/images/trash.gif" alt="'._UDDEIM_TRASHCHECKED.'" title="'._UDDEIM_TRASHCHECKED.'"/></a>';
		echo "</th><th style='border:none;' class='sectiontablefooter'>&nbsp;</th><th style='border:none;' class='sectiontablefooter'>&nbsp;</th><th style='border:none;' class='sectiontablefooter'>&nbsp;</th><th style='border:none;' class='sectiontablefooter'>&nbsp;</th></tr>\n";
	}
	
	// now close inbox table and container
	echo "</table></div>\n";
	// checkcell
	echo "</form>\n";

	// write the inbox navigation links
	$pageNav = new uddeIMmosPageNav($totalpostbox, $limitstart, $limit);
	$referlink = "index.php?option=com_uddeim&task=postboxuser&Itemid=".$item_id."&recip=".$userid;
	if ($totalpostbox>$limit) {
		$shownav = $pageNav->writePagesLinks($referlink);
		$shownav = uddeIMarrowReplace($shownav, $config->templatedir);
		echo "<div id='uddeim-pagenav'>".$shownav."<br />";
		echo "[<a href='".uddeIMsefRelToAbs("index.php?option=com_uddeim&task=postboxuser&Itemid=".$item_id."&recip=".$userid."&limitstart=0&limit=".$totalpostbox)."'>"._UDDEIM_SHOWALL."</a>]";
		echo "</div>\n";
	}

	$showinboxlimit_borderbottom = "";
	if ($limitwarning) {
		$showinboxlimit_borderbottom = "<span class='uddeim-warning'>";
		$showinboxlimit_borderbottom.= $limitreached." ";
		$showinboxlimit_borderbottom.= $limitwarning;
		$showinboxlimit_borderbottom.= "</span>";
	}

	$keephours1=($config->ReadMessagesLifespan) * 1;  // this are days
	$keephours2=($config->UnreadMessagesLifespan) * 1;  // this are days
	echo "<div id='uddeim-bottomlines'>";
	if(!$config->bottomlineicons)
		echo '<p><a href="#" onclick="inboxDelete(\''.$muldel.'\'); return false;">'._UDDEIM_TRASHCHECKED.'</a></p>';
	if ($config->ReadMessagesLifespanNote)
		echo "<p>"._UDDEIM_READ_INFO_1.$keephours1._UDDEIM_READ_INFO_2."</p>";
	if ($config->UnreadMessagesLifespanNote)
		echo "<p>"._UDDEIM_UNREAD_INFO_1.$keephours2._UDDEIM_UNREAD_INFO_2."</p>";
	if ($showinboxlimit_borderbottom)
		echo "<p>".$showinboxlimit_borderbottom."</p>";
	echo "</div>\n";

	//if ($config->enablefilter==2 || $config->enablefilter==3)
	//	uddeIMprintFilter($myself, 'postboxuser', $totalpostbox, $item_id, $config, $filter_user, $filter_unread, $filter_flagged);

	echo "</div>\n<div id='uddeim-bottomborder'>".uddeIMcontentBottomborder($myself, $item_id, 'standard', $limitreached, $config)."</div>\n";
//	echo "</div>\n<div id='uddeim-bottomborder'>".uddeIMcontentBottomborder($myself, $item_id, 'standard', $showinboxlimit_borderbottom, $config)."</div>\n";
}
Exemplo n.º 2
0
function uddeIMblockUserUdde($myself, $item_id, $recip, $ret, $config) {
	$addlink = "";
	if ($recip)
		$addlink = "&recip=".(int)$recip;
	
	$task = "inbox";
	if ($ret=="postboxuser" && $config->enablepostbox)
		$task = "postboxuser";

	if (!$config->blocksystem) {
		$mosmsg = _UDDEIM_BLOCKSDISABLED;
		uddeJSEFredirect("index.php?option=com_uddeim&task=".$task."&Itemid=".$item_id.$addlink, $mosmsg);
	}

	// is this user already blocked?
	$isblocked = uddeIMcheckBlockerBlocked($myself, $recip);
	if ($isblocked)
		uddeJSEFredirect("index.php?option=com_uddeim&task=settings&Itemid=".$item_id);

	$recip_gid = uddeIMgetGID($recip);
	if (uddeIMisAdmin($recip_gid) || uddeIMisAdmin2($recip_gid, $config)) {	
		$mosmsg = _UDDEIM_CANTBLOCKADMINS;
		uddeJSEFredirect("index.php?option=com_uddeim&task=".$task."&Itemid=".$item_id.$addlink, $mosmsg);	
	}

	uddeIMinsertBlockerBlocked($myself, $recip);
	uddeJSEFredirect("index.php?option=com_uddeim&task=settings&Itemid=".$item_id);	
}
Exemplo n.º 3
0
function uddeIMsaveMessage($myself, $to_name, $to_id, $pmessage, $tobedeleted, $tobedeletedsent, $forceembedded, $item_id, $messageid, $copytome, $addccinfo, $sendeform_showallusers, $cryptpass, $backto, $config) {
	$database = uddeIMgetDatabase();

	$to_name = stripslashes($to_name);

	// I could have modified this function to process mails to public users but instead of adding
	// several exceptions it is better to have an own function for this purpose.
	// Everything we need is available here, so we can use this for the new function.
	// When we have the public frontend enabled and the user saves a REPLY (=$messageid exists) and the receiver is a public user then do it...
	if ($config->pubfrontend && $messageid && !$to_id) {
		uddeIMtoPublicSaveMessage($myself, $pmessage, $tobedeleted, $tobedeletedsent, $forceembedded, $item_id, $messageid, $copytome, $cryptpass, $backto, $config);
		return;
	}

	$my_gid = $config->usergid;
	$to_name_bak = $to_name;				// save all already typed in names

	if($config->inboxlimit) {
		if ($config->allowarchive) {		// have an archive and an "archive and inbox" limit, so get number of messages in inbox and archive
			$total = uddeIMgetInboxArchiveCount($myself);
		} else {							// user has switched of archive but there is an limit for "inbox and archive", so count inbox messages only
			$total = uddeIMgetInboxCount($myself);
		}
		if($total>$config->maxarchive && !uddeIMisAdmin($my_gid) && !uddeIMisAdmin2($my_gid, $config)) {
			$mosmsg=_UDDEIM_MSGLIMITREACHED;
			uddeJSEFredirect("index.php?option=com_uddeim&task=inbox&Itemid=".$item_id, $mosmsg);
		}
	}
	
	// link to drop down box with names of connected users, value is 2 since it is shown the first time (so selecting the link does not show an error message because of an empty recipient field)
	if(!$to_id && !$to_name && $sendeform_showallusers!=2) {
		// write the uddeim menu
		uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 5, $config);
		return;
	}

	if($sendeform_showallusers) {	// =2, click on button / =1, keep on showing
		// write the uddeim menu
		uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 1, $config);
		return;
	}

	$lastsent = uddeIMgetEMNlastsent($myself);
	$flooding = 0;
	if ($config->timedelay>0) {
		if (uddeIMisReggedOnly($config->usergid)) {
			if ($lastsent) {
				$delay = uddetime($config->timezone) - $lastsent;
				if ($delay <= $config->timedelay)
					$flooding = 1;
			}
		}
	}
	if($flooding) {
		// write the uddeim menu
		uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 14, $config);
		return;
	}
	
	if( ($config->enablelists==1) ||
	    ($config->enablelists==2 && (uddeIMisSpecial($my_gid) || uddeIMisSpecial2($my_gid, $config))) || 
	    ($config->enablelists==3 && (uddeIMisAdmin($my_gid)   || uddeIMisAdmin2($my_gid, $config))) ) {
		// when userlists are not enabled, then "#listname" is treated as "normal" username
		$ok = uddeIMreplaceListsWithNames($to_name, $myself, $config);
		if (!$ok) {
			// write the uddeim menu
			uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 11, $config);
			return;
		}
		// the list is ok, so we work with the expanded names from now
		$to_name_bak = $to_name;					// save all expanded names, we do not want to work with lists because this minimizes db queries
	}

	if ($config->separator==1)
		$anames = explode(";", $to_name);
	else
		$anames = explode(",", $to_name);

	// expand always, so the next condition may be fulfilled
	if( ( $config->allowmultiplerecipients && count($anames)>$config->maxrecipients && $config->maxrecipients>0) ||
		(!$config->allowmultiplerecipients && count($anames)>1)														) { 	// too many recipients
		// write the uddeim menu
		uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 6, $config);
		return;
	}

	// FIRST ROUND: Check all names that were typed in (lists have been replaced by the corresponding names)
	// ATTENTION: $to_name contains one name only below this line, to restore what the user typed in use $to_name_bak

	// NOTE: A reply contains a valid $to_id and an emtpy string in $to_name, so the array contains an empty entry here.
	foreach ($anames as $value) {

		$to_name = trim($value);

		// when we have a name, then resolve the name
		// remember that replies provide $to_id only and $to_name is empty, so do not try to resolve names when it is empty
		if ($to_name) {
			$to_id = uddeIMgetIDfromName($to_name, $config, true);		// add "AND block=0"
			// BUGBUG: maybe it is a good idea to do the query vice versa (so I could add a query for "realname"s here)
			if (!$to_id) { // no user with this name found, so try again with username (maybe we do the query twice (see query above, but who cares)
				if ($config->realnames) {
					$to_id = uddeIMgetIDfromUsername($to_name, true);	// add "AND block=0"
				}
			}

			if(!$to_id) { // no user with this username found
				// display to form again so that the user can correct his/her fault
				// the wrong name is displayed in brackets (add brackets only once)
				if (substr($to_name,0,1)!="(") {
					$to_name = str_replace($to_name, "(".$to_name.")", $to_name_bak);
				}
				// write the uddeim menu
				uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 3, $config);
				return;
			} elseif ($to_id==$myself) { // don't send to yourself
				if (substr($to_name,0,1)!="(") {
					$to_name = str_replace($to_name, "(".$to_name.")", $to_name_bak);
				}
				// write the uddeim menu
//				$to_name=stripslashes($to_name_bak);		// all names
				uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 2, $config);
				return;
			}
		}

		// now check banning
		if (uddeIMisAllNotAdmin($my_gid) && !uddeIMisAdmin2($my_gid, $config)) {	// I am not an admin, so check if the recipient has been banned
			$is_banned = uddeIMisBanned($to_id, $config);
			if ($is_banned) {
				if (substr($to_name,0,1)!="(") {
					$to_name = str_replace($to_name, "(".$to_name.")", $to_name_bak);
				}
				// write the uddeim menu
				uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 17, $config);
				return;
			}
		}

		// now check blocking
		$isblocked = uddeIMcheckBlockerBlocked($to_id, $myself);
		// well, should be changed in a way that the user can change his input again
		if ($isblocked && $config->blocksystem) { // must not send message to to_id
			if ($config->blockalert) { // sending user shall be informed that (s)he's been blocked
				if (substr($to_name,0,1)!="(") {
					$to_name = str_replace($to_name, "(".$to_name.")", $to_name_bak);
				}
				// write the uddeim menu
				uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 9, $config);
				return;
			}
		}

		// now check group blocking
		if (uddeIMisReggedOnly($my_gid)) {	// I am a registered user, so check if I am allowed to send to this group
			$is_group_blocked = uddeIMisRecipientBlockedReg($myself, $to_id, $config);
			if ($is_group_blocked) {
				if (substr($to_name,0,1)!="(") {
					$to_name = str_replace($to_name, "(".$to_name.")", $to_name_bak);
				}
				// write the uddeim menu
				uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 10, $config);
				return;
			}
		}
	}

	if(!$pmessage) {
		// write the uddeim menu
		$to_name = $to_name_bak;
		uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 4, $config);
		return;
	}

	// BADWORDFILTER
	$temp = trim($config->badwords);
	if ($temp) {
		$badwordlist = explode(";", $temp);
		//$badwordlist = Array();
		//$badwordlist[] = 'badword1';
		//$badwordlist[] = 'badword2';

		$pmessage_orig = $pmessage;
		foreach ($badwordlist as $val) {
			$tval = trim($val);
			$pmessage = preg_replace("/\b$tval\b/i", '***',$pmessage);
		}

		if ($pmessage_orig!=$pmessage) {
			$to_name = $to_name_bak;
			uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 21, $config);
			return;
		}
	}

	// UDDEIMFILE
	// We have checked that everything is ok, now do the file uploads
	$uploadfile_temppathname = array();
	$uploadfile_original = array();
	$uploadfile_id = array(); 
	$uploadfile_size = array(); 
	$uploadfile_error = array();
	if( $config->enableattachment && uddeIMisAttachmentAllowed($my_gid, $config)) {
		$noerror = uddeIMhandleAttachments($uploadfile_temppathname, $uploadfile_original, $uploadfile_id, $uploadfile_size, $uploadfile_error, $config);
		if (!$noerror) { // something goes wrong
			// BUGBUG: that is not the best error handling possible but is will do the work
			// iterate through all errorcodes and show the first error found, rest of data will be lost
			// ==> delete all files that were uploaded ok
			while (list($key, $value) = each( $uploadfile_temppathname )) {
				if (file_exists($value))
					unlink($value);
			}
			while (list($key, $value) = each( $uploadfile_error )) {
				if ($value==-1) {	// upload failed
					uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 18, $config);
					return;
				}
				if ($value==-2) {	// file size exceeded
					uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 19, $config);
					return;
				}
				if ($value==-3) {	// file type not allowed
					uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 20, $config);
					return;
				}
			}
			$uploadfile_temppathname = array();		// should never been reached when an error occurs but neverthless destroy old arrays
			$uploadfile_original = array();
			$uploadfile_id = array(); 
			$uploadfile_size = array(); 
			$uploadfile_error = array();
		}
	}
	// The uploaded file is stored in "$uploadfile_tempname" (with path) ad the original name in "$uploadfile_original" (without path) and an Id for the file.
	// When we reach this line we can store these fileames in the DB.


	if(!$to_id) {					// this should never be reached
		$mosmsg = _UDDEIM_NOID;
		uddeJSEFredirect("index.php?option=com_uddeim&task=new&Itemid=".$item_id, $mosmsg);
	}

	// CAPTCHA (first check for all other errors and then the CAPTCHA)
	if (!uddeIMcheckCAPTCHA($my_gid, $config)) {
		$to_name = $to_name_bak;
		uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 7, $config);
		return;
	}

	if (!uddeIMcheckCSRF($config)) {
		$to_name = $to_name_bak;
		uddeIMmenuWriteform($myself, $my_gid, $item_id, $to_name, $pmessage, 15, $config);
		return;
	}

	foreach ($anames as $value) {

		$to_name = trim($value);

		if ($to_name) {
			$to_id = uddeIMgetIDfromName($to_name, $config, true);		// add "AND block=0"
			// BUGBUG: maybe it is a good idea to do the query vice versa (so I could add a query for "realname"s here)
			if (!$to_id) { // no user with this name found, so try again with username (maybe we do the query twice (see query above, but who cares)
				if ($config->realnames) {
					$to_id = uddeIMgetIDfromUsername($to_name, true);	// add "AND block=0"
				}
			}
		}
		if (!$to_id) {	// that should never happen, but you never know...
			$mosmsg=_UDDEIM_NOID;
			uddeJSEFredirect("index.php?option=com_uddeim&task=new&Itemid=".$item_id, $mosmsg);
		}

		// now check blocking
		$isblocked = uddeIMcheckBlockerBlocked($to_id, $myself);
		if ($isblocked && $config->blocksystem) { // must not send message to to_id
			continue;
		}

		$savedatum  = uddetime($config->timezone);
		$savetoid   = $to_id;
		$savefromid = $myself;

		// CRYPT
		if ($config->cryptmode>=1) {	// because of encoding do not use slashes
			$savemessage=strip_tags($pmessage);
		} else {
			$savemessage=addslashes(strip_tags($pmessage));   // original 0.6+
		}

		$savemessage = uddeIMRemoveXSS($savemessage);
		if (!$config->allowbb)
			$savemessage=uddeIMbbcode_strip($savemessage);

		// set message max length
		if ($config->maxlength>0)		// because if 0 do not use any maxlength
			$savemessage=uddeIM_utf8_substr($config->languagecharset, $savemessage, 0, $config->maxlength);

		// add CC: information
		if ($config->allowmultipleuser && $addccinfo && count($anames)>1) {
			$ccinfo = implode(", ", $anames);
			if ($config->allowbb)
				$ccheader = "\n\n[i]"._UDDEIM_CC." ".(($config->cryptmode>=1) ? $ccinfo : addslashes($ccinfo))."[/i]";
			else
				$ccheader = "\n\n"._UDDEIM_CC." ".(($config->cryptmode>=1) ? $ccinfo : addslashes($ccinfo))."";
			$savemessage .= $ccheader;
		}

		// ##################################################################################################
		// SAVE MESSAGE
		// ##################################################################################################

		uddeIMemit("onSaveMessage", Array( "fromid" => $savefromid, "toid" => $savetoid, "replyid" => $messageid ) );
		$insID = uddeIMsaveRAWmessage($savefromid, $savetoid, $messageid, $savemessage, $savedatum, $config, $config->cryptmode, $cryptpass);

		// update lastsent field (record already exists since we check this at the very beginning of this component)
		uddeIMupdateEMNlastsent($myself, uddetime($config->timezone));

		// When the account is moderated, delay the message
		$ismoderated = uddeIMgetEMNmoderated($myself);
		if ($ismoderated) { // && uddeIMisReggedOnly($my_gid)) {
			uddeIMupdateDelayed($myself, $insID, 1);
		}

		// Check if E-Mail notification or popups are enabled by default, if so create a record for the receiver.
		// Note: Not necessary for "copy to myself" sind the record for the current user has been set at the very beginning...
		if ($config->modnewusers>0 || $config->notifydefault>0 || $config->popupdefault>0 || $config->pubfrontenddefault>0 || $config->autoresponder>0 || $config->autoforward>0) {
			if (!uddeIMexistsEMN($savetoid))
				uddeIMinsertEMNdefaults($savetoid, $config);
		}

		// get the group ID of the recipient
		$rec_gid = uddeIMgetGID((int)$savetoid);
		
		// UDDEIMFILE
		// Now save the uploads
		if (count($uploadfile_temppathname)>=1) {
			$num = count($uploadfile_temppathname);
			uddeIMemit("onSaveMessageAttachment", Array( "num" => $num, "fromid" => $savefromid, "toid" => $savetoid, "replyid" => $messageid ) );
		}
		if( $config->enableattachment && uddeIMisAttachmentAllowed($my_gid, $config))
			uddeIMsaveAttachments($insID, $uploadfile_temppathname, $uploadfile_original, $uploadfile_id, $uploadfile_size, $savedatum, $config);

		
		// ##################################################################################################
		// autoforward code
		// ##################################################################################################
		if ($config->autoforward==1 || 
		   ($config->autoforward==2 && (uddeIMisAdmin($my_gid)   || uddeIMisAdmin2($my_gid, $config))) ||
		   ($config->autoforward==3 && (uddeIMisSpecial($my_gid) || uddeIMisSpecial2($my_gid, $config))) ) {
			$ison = uddeIMgetEMNautoforward($savetoid);						// recipient has autoforward enabled
			if ($ison==1) {
				$autoforwardid = uddeIMgetEMNautoforwardid($savetoid);	// new recipient

				if (uddeIMgetUserExists($autoforwardid)) {
					if (!uddeIMgetUserBlock($autoforwardid)) {
						$temp = uddeIMgetNameFromID($savetoid, $config);
						$temp = (($config->cryptmode>=1) ? $temp : addslashes($temp));
						if ($config->allowbb)
							$forwardheader="\n\n[i]("._UDDEIM_THISISAFORWARD.$temp.")[/i]";
						else
							$forwardheader="\n\n("._UDDEIM_THISISAFORWARD.$temp.")";
						$savemessagecopy = $savemessage.$forwardheader;

						$insIDforward = uddeIMsaveRAWmessage($savefromid, $autoforwardid, 0, $savemessagecopy, $savedatum, $config, $config->cryptmode, $cryptpass);

						// When the account is moderated, delay also the forwarded message
						if (uddeIMgetEMNmoderated($myself) ) { // && uddeIMisReggedOnly($my_gid)) {
							uddeIMupdateDelayed($myself, $insIDforward, 1);
						}

						// UDDEIMFILE
						if( $config->enableattachment && uddeIMisAttachmentAllowed($my_gid, $config))
							uddeIMsaveAttachments($insIDforward, $uploadfile_temppathname, $uploadfile_original, $uploadfile_id, $uploadfile_size, $savedatum, $config);
					}
				}
			}
		}

		// ##################################################################################################
		// copy to myself?
		// ##################################################################################################
		if($copytome && $config->allowcopytome) {
			$to_name = uddeIMgetNameFromID($savetoid, $config);
			// set reply id if necessary (also copy2me messages might be replies)
			$replyid = $messageid;

			$temp = (($config->cryptmode>=1) ? $to_name : addslashes($to_name));
			if ($config->allowbb)
				$copyheader="\n\n[i]("._UDDEIM_THISISACOPY.$temp.")[/i]";
			else
				$copyheader="\n\n("._UDDEIM_THISISACOPY.$temp.")";

			$savemessagecopy = $savemessage.$copyheader;
			$copyname = _UDDEIM_TO_SMALL." ".$temp;		// "to username" in systemmsg
			// if($config->allowarchive) { $archiveflag=1; }

			// it is a copy to myself, so assume that the message has already been trashed in the senders outbox (remember: system messages are not shown in the outbox)
			// so set totrashoutbox=1, totrashdateoutbox=uddetime($config->timezone)
			// CRYPT
			$themode=0;
			if ($config->cryptmode==1) {
				$cm = uddeIMencrypt($savemessagecopy,$config->cryptkey,CRYPT_MODE_BASE64);
				$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$savefromid.", ".(int)$savefromid.", ".(int)$replyid.", 1, '".$cm."', ".$savedatum.", 1, 2, '".$copyname."', 1,".$savedatum.",1,'".md5($config->cryptkey)."')";
			} elseif ($config->cryptmode==2) {
				$themode=2;
				$thepass=$cryptpass;
				if (!$thepass) {	// no password entered, then fallback to obfuscating
					$themode=1;
					$thepass=$config->cryptkey;
				}
				$cm = uddeIMencrypt($savemessagecopy,$thepass,CRYPT_MODE_BASE64);
				$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$savefromid.", ".(int)$savefromid.", ".(int)$replyid.", 1, '".$cm.             "', ".$savedatum.", 1, 2, '".$copyname."', 1,".$savedatum.",".$themode.",'".md5($thepass)."')";
			} elseif ($config->cryptmode==3) {
				$cm = uddeIMencrypt($savemessagecopy,"",CRYPT_MODE_STOREBASE64);
				$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, totrashoutbox, totrashdateoutbox, cryptmode) VALUES (".(int)$savefromid.", ".(int)$savefromid.", ".(int)$replyid.", 1, '".$cm."', ".$savedatum.", 1, 2, '".$copyname."', 1,".$savedatum.",3)";
			} elseif ($config->cryptmode==4) {
				$themode=4;
				$thepass=$cryptpass;
				$cipher = CRYPT_MODE_3DESBASE64;
				if (!$thepass) {	// no password entered, then fallback to obfuscating
					$themode=1;
					$thepass=$config->cryptkey;
					$cipher = CRYPT_MODE_BASE64;
				}
				$cm = uddeIMencrypt($savemessagecopy,$thepass,$cipher);
				$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$savefromid.", ".(int)$savefromid.", ".(int)$replyid.", 1, '".$cm.             "', ".$savedatum.", 1, 2, '".$copyname."', 1,".$savedatum.",".$themode.",'".md5($thepass)."')";
			} else {
				$sql="INSERT INTO #__uddeim (fromid, toid, replyid, toread, message, datum, disablereply, systemflag, systemmessage, totrashoutbox, totrashdateoutbox) VALUES (".(int)$savefromid.", ".(int)$savefromid.", ".(int)$replyid.", 1, '".$savemessagecopy."', ".$savedatum.", 1, 2, '".$copyname."', 1,".$savedatum.")";
			}
			$database->setQuery($sql);
			if (!$database->query()) {
				die("SQL error when attempting to save a message" . $database->stderr(true));
			}
			
			// UDDEIMFILE
			$insCopyID = $database->insertid();
			if( $config->enableattachment && uddeIMisAttachmentAllowed($my_gid, $config))
				uddeIMsaveAttachments($insCopyID, $uploadfile_temppathname, $uploadfile_original, $uploadfile_id, $uploadfile_size, $savedatum, $config);
			
		}

		// ##################################################################################################
		// autoresponder
		// ##################################################################################################
		if ($config->autoresponder==1 || 
		   ($config->autoresponder==2 && (uddeIMisAdmin($rec_gid) || uddeIMisAdmin2($rec_gid, $config)))) {
			$ison = uddeIMgetEMNautoresponder($savetoid);
			if ($ison==1) {

				// NOTE: An autoresponder message is created and the outbox message is marked deleted.
				// This is not a bug since in my opinion it does not make sense to store autoresponder messages AND the received message.
				$autorespondertext = uddeIMgetEMNautorespondertext($savetoid);
				$savemessage2=addslashes(strip_tags($autorespondertext));
				// $sql="INSERT INTO #__uddeim (fromid, toid, message, datum, totrashoutbox, totrashdateoutbox) VALUES (".(int)$savetoid.", ".(int)$savefromid.", '". $savemessage ."', ".$savedatum.", 1,".$savedatum.")";

				$themode=0;
				if ($config->cryptmode==1) {
					$themode=1;
					$thepass=$config->cryptkey;
					$cm = uddeIMencrypt($savemessage2,$config->cryptkey,CRYPT_MODE_BASE64);
					$sql="INSERT INTO #__uddeim (fromid, toid, message, datum, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$savetoid.", ".(int)$savefromid.", '". $cm ."', ".$savedatum.", 1,".$savedatum.",".$themode.",'".md5($thepass)."')";
				} elseif ($config->cryptmode==2) {
					// no password entered, then fallback to obfuscating
					$themode=1;
					$thepass=$config->cryptkey;
					$cm = uddeIMencrypt($savemessage2,$thepass,CRYPT_MODE_BASE64);
					$sql="INSERT INTO #__uddeim (fromid, toid, message, datum, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$savetoid.", ".(int)$savefromid.", '". $cm ."', ".$savedatum.", 1,".$savedatum.",".$themode.",'".md5($thepass)."')";
				} elseif ($config->cryptmode==3) {
					$cm = uddeIMencrypt($savemessage2,"",CRYPT_MODE_STOREBASE64);
					$sql="INSERT INTO #__uddeim (fromid, toid, message, datum, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$savetoid.", ".(int)$savefromid.", '". $cm ."', ".$savedatum.", 1,".$savedatum.", 3)";
				} elseif ($config->cryptmode==4) {
					// no password entered, then fallback to obfuscating
					$themode=1;
					$thepass=$config->cryptkey;
					$cm = uddeIMencrypt($savemessage2,$thepass,CRYPT_MODE_BASE64);
					$sql="INSERT INTO #__uddeim (fromid, toid, message, datum, totrashoutbox, totrashdateoutbox, cryptmode, crypthash) VALUES (".(int)$savetoid.", ".(int)$savefromid.", '". $cm ."', ".$savedatum.", 1,".$savedatum.",".$themode.",'".md5($thepass)."')";
				} else {
					$cm = $savemessage2;
					$sql="INSERT INTO #__uddeim (fromid, toid, message, datum, totrashoutbox, totrashdateoutbox) VALUES (".(int)$savetoid.", ".(int)$savefromid.", '". $cm ."', ".$savedatum.", 1,".$savedatum.")";
				}
				$database->setQuery($sql);
				if (!$database->query()) {
					die("SQL error when attempting to save a message" . $database->stderr(true));
				}
			}
		}

		// ##################################################################################################
		// email notification
		// ##################################################################################################
		// is this a reply?
		$itisareply = stristr($savemessage, $config->quotedivider);
		// is the receiver currently online?
		$currentlyonline = uddeIMisOnline($savetoid);

		if ($config->cryptmode>=1) {
			$email=stripslashes($savemessage);
		} else {
			$email=stripslashes(stripslashes($savemessage));	// without encoding remove the safety slashes
		}

		if ($config->emailwithmessage==2 && !uddeIMisAdmin($my_gid) && !uddeIMisAdmin2($my_gid, $config) ||
			$config->emailwithmessage==1 ||
			$config->emailwithmessage==0)
			$forceembedded = 0;

		$type = 0; 			// 0=normal message, 1=forgetmenot, 2=admin forces text
		if ($forceembedded)
			$type = 2;		// admin forces

		// BUGBUG: it would be better to have the correct cryptmode here (it might be 1 when no password has been entered, otherwise 2
		if($config->allowemailnotify==1 && !$ismoderated) {
			$ison = uddeIMgetEMNstatus($savetoid);
			if (($ison==1) || ($ison==2 && !$currentlyonline) || ($ison==10 && !$itisareply) || ($ison==20 && !$currentlyonline && !$itisareply))  {
				uddeIMdispatchEMN($insID, $item_id, $config->cryptmode, $savefromid, $savetoid, $email, $type, $config);
				// 0 stands for normal (not forgetmenot)
			}
		} elseif($config->allowemailnotify==2 && !$ismoderated) {
			if (uddeIMisAdmin($rec_gid) || uddeIMisAdmin2($rec_gid, $config)) {
				$ison = uddeIMgetEMNstatus($savetoid);
				if (($ison==1) || ($ison==2 && !$currentlyonline) || ($ison==10 && !$itisareply) || ($ison==20 && !$currentlyonline && !$itisareply))  {
					uddeIMdispatchEMN($insID, $item_id, $config->cryptmode, $savefromid, $savetoid, $email, $type, $config);
					// 0 stands for normal (not forgetmenot)
				}
			}
		}
		if ($tobedeletedsent) {
			$deletetime=uddetime($config->timezone);
			uddeIMdeleteMessageFromOutbox($myself, $insID, $deletetime);
		}
	}

	// delete original message?
	if ($tobedeleted) {
		$deletetime=uddetime($config->timezone);
		uddeIMdeleteMessageFromInbox($myself, $messageid, $deletetime);
	}

	if($messageid) {
		$mosmsg=_UDDEIM_MESSAGE_REPLIEDTO;
	} else {
		$mosmsg=_UDDEIM_MESSAGE_SENT;
	}
	if ($tobedeleted) {
		$mosmsg.=_UDDEIM_MOVEDTOTRASH;
	}

	if($backto) {
		uddeIMmosRedirect($backto, $mosmsg);
	}
	uddeJSEFredirect("index.php?option=com_uddeim&task=inbox&Itemid=".$item_id, $mosmsg);
}