19 $option[
'count'] = Mail\MailMessageTable::getCount();
20 $option[
'steps'] = Mail\Internals\MessageClosureTable::getList(array(
26 if ($option[
'steps'] < $option[
'count'])
28 if (!($option[
'mailboxId'] > 0) || $option[
'stage'] < 1)
30 $option[
'mailboxId'] = $DB->query(
31 'SELECT MAILBOX_ID FROM b_mail_message M WHERE NOT EXISTS (
32 SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = M.ID
34 )->fetch()[
'MAILBOX_ID'];
41 $option[
'mailboxId'] =
false;
46 if ($option[
'mailboxId'] > 0 && 1 == $option[
'stage'])
49 'SELECT M.ID, M.ID FROM b_mail_message M
50 WHERE M.MAILBOX_ID = %u AND (
51 M.IN_REPLY_TO IS NULL OR M.IN_REPLY_TO = \'\' OR M.IN_REPLY_TO = M.MSG_ID OR NOT EXISTS (
52 SELECT 1 FROM b_mail_message WHERE MAILBOX_ID = M.MAILBOX_ID AND MSG_ID = M.IN_REPLY_TO
54 ) AND NOT EXISTS (SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = M.ID)
56 (
int)$option[
'mailboxId']
59 $option[
'stage'] = $res < 40000 ? 2 : 1;
60 $option[
'steps'] += $res;
65 if ($option[
'mailboxId'] > 0 && 2 == $option[
'stage'])
68 'SELECT DISTINCT M.ID, C.PARENT_ID
70 LEFT JOIN b_mail_message R ON M.MAILBOX_ID = R.MAILBOX_ID AND M.IN_REPLY_TO = R.MSG_ID
71 LEFT JOIN b_mail_message_closure C ON R.ID = C.MESSAGE_ID
72 WHERE M.MAILBOX_ID = %u
73 AND EXISTS (SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = R.ID)
74 AND NOT EXISTS (SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = M.ID)',
75 (
int)$option[
'mailboxId']
78 $option[
'stage'] = $res > 0 ? 3 : 4;
83 if (3 == $option[
'stage'])
86 'SELECT DISTINCT C.MESSAGE_ID, C.MESSAGE_ID
87 FROM b_mail_message_closure C
88 WHERE NOT EXISTS (SELECT 1 FROM b_mail_message_closure WHERE PARENT_ID = C.MESSAGE_ID)'
91 $option[
'stage'] = $res > 0 ? 2 : 4;
94 if (4 == $option[
'stage'])
97 'SELECT M.ID, M.ID FROM b_mail_message M
98 WHERE M.MAILBOX_ID = %u
99 AND NOT EXISTS (SELECT 1 FROM b_mail_message_closure WHERE MESSAGE_ID = M.ID)
100 ORDER BY FIELD_DATE ASC LIMIT 1',
101 (
int)$option[
'mailboxId']
104 $option[
'stage'] = $res > 0 ? 2 : 0;