function importPendingEmailAsComment(&$incoming_mail, &$project, &$user, &$mailbox, $page_id = '')
 {
     $parent = ProjectObjects::findById(!empty($page_id) ? $page_id : $incoming_mail->getParentId());
     //EOF:mod 20120820
     if (!instance_of($parent, 'ProjectObject')) {
         // parent object does not exists
         $incoming_mail->setState(INCOMING_MAIL_STATUS_PARENT_NOT_EXISTS);
         $incoming_mail_save = $incoming_mail->save();
         return new Error(incoming_mail_module_get_status_description(INCOMING_MAIL_STATUS_PARENT_NOT_EXISTS));
     }
     // if
     if (!$mailbox->getAcceptAllRegistered() && instance_of($user, 'User') && !$parent->canComment($user)) {
         // user cannot create comments to parent object
         $incoming_mail->setState(INCOMING_MAIL_STATUS_USER_CANNOT_CREATE_COMMENT);
         $incoming_mail_save = $incoming_mail->save();
         return new Error(incoming_mail_module_get_status_description(INCOMING_MAIL_STATUS_USER_CANNOT_CREATE_COMMENT));
     } else {
         if (!$parent->can_have_comments || $parent->getIsLocked() || $parent->getState() < STATE_VISIBLE) {
             // parent object can't have comments
             $incoming_mail->setState(INCOMING_MAIL_STATUS_USER_CANNOT_CREATE_COMMENT);
             $incoming_mail_save = $incoming_mail->save();
             return new Error(incoming_mail_module_get_status_description(INCOMING_MAIL_STATUS_USER_CANNOT_CREATE_COMMENT));
         }
         // if
     }
     // if
     $comment = new Comment();
     $comment->log_activities = false;
     $comment->setCreatedBy($user);
     $comment->setCreatedOn($incoming_mail->getCreatedOn());
     $comment->setProjectId($parent->getProjectId());
     $comment->setState(STATE_VISIBLE);
     $comment->setSource(OBJECT_SOURCE_EMAIL);
     $comment->setVisibility($parent->getVisibility());
     $comment->setParent($parent);
     $body_content = '';
     if (stripos($incoming_mail->getBody(), '-- REPLY ABOVE THIS LINE --') !== false) {
         $body_content = substr($incoming_mail->getBody(), 0, strpos($incoming_mail->getBody(), '-- REPLY ABOVE THIS LINE --'));
     } else {
         $body_content = $incoming_mail->getBody();
     }
     $comment->setBody($body_content);
     IncomingMailImporter::attachFilesToProjectObject($incoming_mail, $comment);
     //$save = $comment->save();
     $save = $comment->save(true);
     if ($save && !is_error($save)) {
         $activity = new NewCommentActivityLog();
         $activity->log($comment, $user);
         if (instance_of($user, 'User')) {
             $parent->subscribe($user);
         }
         // if
         $comment->ready();
         //BOF:mod 20111110 #493
         preg_match("/\\[CID(.*?)\\](.*)/is", $incoming_mail->getSubject(), $results);
         if (count($results) > 0) {
             $project = new Project($parent->getProjectId());
             $variables = array('owner_company_name' => get_owner_company(), 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'object_type' => $comment->getVerboseType(), 'object_name' => $comment->getName(), 'object_body' => $comment->getFormattedBody(), 'object_url' => $comment->getViewUrl(), 'comment_body' => $comment->getFormattedBody(), 'comment_url' => $comment->getViewUrl(), 'created_by_url' => $user->getViewUrl(), 'created_by_name' => $user->getDisplayName(), 'details_body' => '', 'comment_id' => $comment->getId());
             $emailed_comment_id = $results[1];
             $emailed_comment = new Comment($emailed_comment_id);
             $emailed_comment_creator_id = $emailed_comment->getCreatedById();
             $email_to = array();
             $temp_user_id = $user->getId();
             $temp_comment_id = $comment->getId();
             $rows = db_execute_all("select user_id from " . TABLE_PREFIX . "assignments_action_request where comment_id='" . $emailed_comment_id . "' and marked_for_email='1'");
             foreach ($rows as $row) {
                 if ($row['user_id'] != $temp_user_id) {
                     $email_to[] = new User($row['user_id']);
                     db_execute("insert into " . TABLE_PREFIX . "assignments_action_request (user_id, marked_for_email, selected_by_user_id, comment_id, date_added) values ('" . $row['user_id'] . "', '1', '" . $temp_user_id . "', '" . $temp_comment_id . "', now())");
                 }
             }
             $row = db_execute_one("select a.selected_by_user_id from " . TABLE_PREFIX . "assignments_action_request a where a.comment_id='" . $emailed_comment_id . "' and a.marked_for_email='1' and a.selected_by_user_id not in (select b.user_id from " . TABLE_PREFIX . "assignments_action_request b where b.comment_id='" . $emailed_comment_id . "' and b.marked_for_email='1') limit 0, 1");
             if (!empty($row['selected_by_user_id'])) {
                 if ($row['selected_by_user_id'] != $temp_user_id) {
                     $email_to[] = new User($row['selected_by_user_id']);
                     db_execute("insert into " . TABLE_PREFIX . "assignments_action_request (user_id, marked_for_email, selected_by_user_id, comment_id, date_added) values ('" . $row['selected_by_user_id'] . "', '1', '" . $temp_user_id . "', '" . $temp_comment_id . "', now())");
                 }
             }
             //ApplicationMailer::send(array(new User($emailed_comment_creator_id)), 'resources/new_comment', $variables, $parent);
             $attachments = null;
             $object_attachments = $comment->getAttachments();
             if ($object_attachments) {
                 $attachments = array();
                 foreach ($object_attachments as $object_attachment) {
                     $attachments[] = array('path' => $object_attachment->getFilePath(), 'name' => $object_attachment->getName(), 'mime_type' => $object_attachment->getMimeType());
                 }
             }
             ApplicationMailer::send($email_to, 'resources/new_comment', $variables, $parent, $attachments);
         }
         //EOF:mod 20111110 #493
         if (!empty($page_id)) {
             //$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             //mysql_select_db(DB_NAME, $link);
             //mysql_query("insert into testing (date_added, content) values (now(), 'Page_id: " . $page_id . "')");
             //mysql_close($link);
             $task =& IncomingMailImporter::importPendingEmailToTaskList($incoming_mail, $project, $user, $page_id, $comment);
             return $task;
         } else {
             return $comment;
         }
     }
     // if
     return $save;
 }