@@ -544,13 +544,13 @@ protected function initFolderValues(string $sFolderName) : array
544
544
$ aFolderStatus = $ this ->oImapClient ->FolderStatus ($ sFolderName , $ aTypes );
545
545
546
546
return [
547
- $ aFolderStatus [FolderResponseStatus::MESSAGES ] ?: 0 ,
547
+ \max ( 0 , $ aFolderStatus [FolderResponseStatus::MESSAGES ] ?: 0 ) ,
548
548
549
- $ aFolderStatus [FolderResponseStatus::UNSEEN ] ?: 0 ,
549
+ \max ( 0 , $ aFolderStatus [FolderResponseStatus::UNSEEN ] ?: 0 ) ,
550
550
551
- $ aFolderStatus [FolderResponseStatus::UIDNEXT ] ?: 0 ,
551
+ \max ( 0 , $ aFolderStatus [FolderResponseStatus::UIDNEXT ] ?: 0 ) ,
552
552
553
- $ aFolderStatus [FolderResponseStatus::HIGHESTMODSEQ ] ?: 0 ,
553
+ \max ( 0 , $ aFolderStatus [FolderResponseStatus::HIGHESTMODSEQ ] ?: 0 ) ,
554
554
555
555
$ aFolderStatus [FolderResponseStatus::APPENDLIMIT ] ?: $ this ->oImapClient ->AppendLimit (),
556
556
@@ -575,11 +575,15 @@ public function GenerateFolderHash(string $sFolder, int $iCount, int $iUidNext,
575
575
);
576
576
}
577
577
578
+ /**
579
+ * Returns list of new messages since $iPrevUidNext
580
+ * Currently only for INBOX
581
+ */
578
582
private function getFolderNextMessageInformation (string $ sFolderName , int $ iPrevUidNext , int $ iCurrentUidNext ) : array
579
583
{
580
584
$ aNewMessages = array ();
581
585
582
- if ($ iPrevUidNext && $ iPrevUidNext != $ iCurrentUidNext )
586
+ if ($ iPrevUidNext && $ iPrevUidNext != $ iCurrentUidNext && ' INBOX ' === $ sFolderName && \ MailSo \Config:: $ CheckNewMessages )
583
587
{
584
588
$ this ->oImapClient ->FolderSelect ($ sFolderName );
585
589
@@ -611,22 +615,15 @@ private function getFolderNextMessageInformation(string $sFolderName, int $iPrev
611
615
\MailSo \Mime \Enumerations \Parameter::CHARSET
612
616
);
613
617
614
- $ sCharset = '' ;
615
- if (\strlen ($ sContentTypeCharset ))
616
- {
617
- $ sCharset = $ sContentTypeCharset ;
618
- }
619
-
620
- if (\strlen ($ sCharset ))
621
- {
622
- $ oHeaders ->SetParentCharset ($ sCharset );
618
+ if ($ sContentTypeCharset ) {
619
+ $ oHeaders ->SetParentCharset ($ sContentTypeCharset );
623
620
}
624
621
625
622
$ aNewMessages [] = array (
626
623
'Folder ' => $ sFolderName ,
627
624
'Uid ' => $ iUid ,
628
- 'Subject ' => $ oHeaders ->ValueByName (\MailSo \Mime \Enumerations \Header::SUBJECT , !\strlen ( $ sCharset ) ),
629
- 'From ' => $ oHeaders ->GetAsEmailCollection (\MailSo \Mime \Enumerations \Header::FROM_ , !\strlen ( $ sCharset ) )
625
+ 'Subject ' => $ oHeaders ->ValueByName (\MailSo \Mime \Enumerations \Header::SUBJECT , !$ sContentTypeCharset ),
626
+ 'From ' => $ oHeaders ->GetAsEmailCollection (\MailSo \Mime \Enumerations \Header::FROM_ , !$ sContentTypeCharset )
630
627
);
631
628
}
632
629
}
@@ -677,8 +674,7 @@ public function FolderInformation(string $sFolderName, int $iPrevUidNext = 0, ar
677
674
'HighestModSeq ' => $ iHighestModSeq ,
678
675
'AppendLimit ' => $ iAppendLimit ,
679
676
'MailboxId ' => $ sMailboxId ,
680
- 'NewMessages ' => 'INBOX ' === $ sFolderName && \MailSo \Config::$ CheckNewMessages ?
681
- $ this ->getFolderNextMessageInformation ($ sFolderName , $ iPrevUidNext , $ iUidNext ) : array ()
677
+ 'NewMessages ' => $ this ->getFolderNextMessageInformation ($ sFolderName , $ iPrevUidNext , $ iUidNext )
682
678
);
683
679
}
684
680
@@ -1017,7 +1013,7 @@ public function MessageList(\MailSo\Mail\MessageListParams $oParams) : MessageCo
1017
1013
1018
1014
$ oMessageCollection ->UidNext = $ iUidNext ;
1019
1015
1020
- if (!$ oParams ->iThreadUid && $ oParams -> iPrevUidNext && ' INBOX ' === $ oParams -> sFolderName )
1016
+ if (!$ oParams ->iThreadUid )
1021
1017
{
1022
1018
$ oMessageCollection ->NewMessages = $ this ->getFolderNextMessageInformation (
1023
1019
$ oParams ->sFolderName , $ oParams ->iPrevUidNext , $ iUidNext );
@@ -1033,14 +1029,12 @@ public function MessageList(\MailSo\Mail\MessageListParams $oParams) : MessageCo
1033
1029
$ bUseThreads = false ;
1034
1030
}
1035
1031
1036
- if (0 < $ iMessageRealCount && !$ bMessageListOptimization )
1032
+ if ($ iMessageRealCount && !$ bMessageListOptimization )
1037
1033
{
1038
- $ aUids = $ this ->GetUids ($ oParams ->oCacher , '' ,
1039
- $ oMessageCollection ->FolderName , $ oMessageCollection ->FolderHash , $ bUseSortIfSupported , $ oParams ->sSort );
1040
-
1041
1034
if ($ bUseThreads ) {
1042
1035
$ aAllThreads = $ this ->MessageListThreadsMap ($ oMessageCollection ->FolderName , $ oMessageCollection ->FolderHash , $ oParams ->oCacher );
1043
- if (0 < $ oParams ->iThreadUid )
1036
+
1037
+ if ($ oParams ->iThreadUid )
1044
1038
{
1045
1039
$ aUids = [$ oParams ->iThreadUid ];
1046
1040
// Only show the selected thread messages
@@ -1053,13 +1047,20 @@ public function MessageList(\MailSo\Mail\MessageListParams $oParams) : MessageCo
1053
1047
}
1054
1048
else
1055
1049
{
1056
- // Show all threads
1057
- // $aUids = array();
1058
- // \array_walk_recursive($aAllThreads, function($a) use (&$aUids) { $aUids[] = $a; });
1050
+ $ aUids = $ this ->GetUids ($ oParams ->oCacher , '' ,
1051
+ $ oMessageCollection ->FolderName , $ oMessageCollection ->FolderHash , $ bUseSortIfSupported , $ oParams ->sSort );
1052
+ // Remove all threaded UID's except the most recent of each thread
1053
+ foreach ($ aAllThreads as $ aMap ) {
1054
+ unset($ aMap [\array_key_last ($ aMap )]);
1055
+ $ aUids = \array_diff ($ aUids , $ aMap );
1056
+ }
1059
1057
}
1058
+ } else {
1059
+ $ aUids = $ this ->GetUids ($ oParams ->oCacher , '' ,
1060
+ $ oMessageCollection ->FolderName , $ oMessageCollection ->FolderHash , $ bUseSortIfSupported , $ oParams ->sSort );
1060
1061
}
1061
1062
1062
- if (\strlen ( $ sSearch ) && \is_array ( $ aUids ))
1063
+ if ($ aUids && \strlen ( $ sSearch ))
1063
1064
{
1064
1065
$ aSearchedUids = $ this ->GetUids ($ oParams ->oCacher , $ sSearch ,
1065
1066
$ oMessageCollection ->FolderName , $ oMessageCollection ->FolderHash );
@@ -1084,26 +1085,19 @@ public function MessageList(\MailSo\Mail\MessageListParams $oParams) : MessageCo
1084
1085
$ aUids = \array_unique ($ aNewUids );
1085
1086
unset($ aNewUids );
1086
1087
}
1087
- else
1088
- {
1089
- $ aUids = array ();
1090
- }
1091
1088
}
1092
1089
1093
- if (\is_array ($ aUids ))
1094
- {
1095
- $ oMessageCollection ->MessageCount = $ iMessageRealCount ;
1096
- $ oMessageCollection ->MessageUnseenCount = $ iMessageUnseenCount ;
1097
- $ oMessageCollection ->MessageResultCount = \count ($ aUids );
1090
+ $ oMessageCollection ->MessageCount = $ iMessageRealCount ;
1091
+ $ oMessageCollection ->MessageUnseenCount = $ iMessageUnseenCount ;
1092
+ $ oMessageCollection ->MessageResultCount = \count ($ aUids );
1098
1093
1099
- if (\count ($ aUids ))
1100
- {
1101
- $ aRequestUids = \array_slice ($ aUids , $ oParams ->iOffset , $ oParams ->iLimit );
1102
- $ this ->MessageListByRequestIndexOrUids ($ oMessageCollection , $ aRequestUids , true );
1103
- }
1094
+ if (\count ($ aUids ))
1095
+ {
1096
+ $ aRequestUids = \array_slice ($ aUids , $ oParams ->iOffset , $ oParams ->iLimit );
1097
+ $ this ->MessageListByRequestIndexOrUids ($ oMessageCollection , $ aRequestUids , true );
1104
1098
}
1105
1099
}
1106
- else if (0 < $ iMessageRealCount )
1100
+ else if ($ iMessageRealCount )
1107
1101
{
1108
1102
if ($ this ->oLogger )
1109
1103
{
@@ -1148,11 +1142,12 @@ public function MessageList(\MailSo\Mail\MessageListParams $oParams) : MessageCo
1148
1142
}
1149
1143
}
1150
1144
1151
- if ($ bUseThreads && !$ oParams ->iThreadUid && $ aAllThreads )
1145
+ if ($ aAllThreads && !$ oParams ->iThreadUid )
1152
1146
{
1153
1147
foreach ($ oMessageCollection as $ oMessage ) {
1154
1148
$ iUid = $ oMessage ->Uid ();
1155
- // Find thread
1149
+ // Find thread and set it.
1150
+ // Used by GUI to delete/move the whole thread or other features
1156
1151
foreach ($ aAllThreads as $ aMap ) {
1157
1152
if (\in_array ($ iUid , $ aMap )) {
1158
1153
$ oMessage ->SetThreads ($ aMap );
0 commit comments