Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
enzevalos
enzevalos_iphone
Commits
48479856
Commit
48479856
authored
Apr 23, 2021
by
Oliver Wiese
Browse files
fix mailhandler: decrease number of fetched mails on first fetch
parent
a4205a29
Changes
1
Hide whitespace changes
Inline
Side-by-side
enzevalos_iphone/MailHandler.swift
View file @
48479856
...
...
@@ -395,7 +395,7 @@
}
private
func
loadMessagesFromServer
(
_
uids
:
MCOIndexSet
,
folderPath
:
String
,
maxLoad
:
Int
=
MailHandler
.
MAXMAILS
,
completionCallback
:
@escaping
((
_
error
:
MailServerConnectionError
?)
->
()))
{
guard
IMAPSession
!=
nil
else
{
guard
let
session
=
IMAPSession
else
{
completionCallback
(
MailServerConnectionError
.
NoData
)
return
}
...
...
@@ -405,7 +405,7 @@
}
// First fetch -> get flags
let
requestKind
=
MCOIMAPMessagesRequestKind
(
rawValue
:
MCOIMAPMessagesRequestKind
.
headers
.
rawValue
|
MCOIMAPMessagesRequestKind
.
flags
.
rawValue
)
let
fetchOperation
:
MCOIMAPFetchMessagesOperation
=
se
lf
.
IMAPSe
ssion
!
.
fetchMessagesOperation
(
withFolder
:
folderPath
,
requestKind
:
requestKind
,
uids
:
uids
)
let
fetchOperation
:
MCOIMAPFetchMessagesOperation
=
session
.
fetchMessagesOperation
(
withFolder
:
folderPath
,
requestKind
:
requestKind
,
uids
:
uids
)
fetchOperation
.
extraHeaders
=
MailHandler
.
extraHeaders
fetchOperation
.
start
{[
unowned
self
]
(
err
,
msg
,
vanished
)
->
Void
in
...
...
@@ -566,27 +566,44 @@
}
private
func
initFolder
(
folderPath
:
String
,
completionCallback
:
@escaping
((
MailServerConnectionError
?)
->
()))
{
let
requestKind
=
MCOIMAPMessagesRequestKind
(
rawValue
:
MCOIMAPMessagesRequestKind
.
headers
.
rawValue
)
let
uids
=
MCOIndexSet
(
range
:
MCORangeMake
(
1
,
UINT64_MAX
))
let
toFetchIDs
=
MCOIndexSet
()
let
fetchOperation
:
MCOIMAPFetchMessagesOperation
=
self
.
IMAPSession
!.
fetchMessagesOperation
(
withFolder
:
folderPath
,
requestKind
:
requestKind
,
uids
:
uids
)
fetchOperation
.
start
{[
unowned
self
]
(
err
,
msg
,
vanished
)
->
Void
in
guard
err
==
nil
else
{
let
conerror
=
MailServerConnectionError
.
findErrorCode
(
error
:
err
!
)
guard
let
session
=
IMAPSession
else
{
self
.
errorhandling
(
error
:
.
ConnectionError
,
originalCall
:
{
self
.
initFolder
(
folderPath
:
folderPath
,
completionCallback
:
completionCallback
)},
completionCallback
:
completionCallback
)
return
}
session
.
folderStatusOperation
(
folderPath
)?
.
start
({
error
,
status
in
if
let
error
=
error
{
let
conerror
=
MailServerConnectionError
.
findErrorCode
(
error
:
error
)
self
.
errorhandling
(
error
:
conerror
,
originalCall
:
{
self
.
initFolder
(
folderPath
:
folderPath
,
completionCallback
:
completionCallback
)},
completionCallback
:
completionCallback
)
return
}
if
let
msgs
=
msg
{
FolderRecord
.
lastDate
(
folder
:
folderPath
,
date
:
Date
())
for
message
in
msgs
{
toFetchIDs
.
add
(
UInt64
(
message
.
uid
))
}
self
.
loadMessagesFromServer
(
toFetchIDs
,
folderPath
:
folderPath
,
maxLoad
:
50
,
completionCallback
:
completionCallback
)
}
else
{
guard
let
status
=
status
else
{
completionCallback
(
nil
)
return
}
}
let
requestKind
=
MCOIMAPMessagesRequestKind
(
rawValue
:
MCOIMAPMessagesRequestKind
.
headers
.
rawValue
)
let
min
=
max
(
status
.
uidNext
-
1000
,
1
)
let
uids
=
MCOIndexSet
(
range
:
MCORangeMake
(
UInt64
(
min
),
UInt64
(
status
.
uidNext
)))
let
toFetchIDs
=
MCOIndexSet
()
let
fetchOperation
:
MCOIMAPFetchMessagesOperation
=
session
.
fetchMessagesOperation
(
withFolder
:
folderPath
,
requestKind
:
requestKind
,
uids
:
uids
)
fetchOperation
.
start
{[
unowned
self
]
(
err
,
msg
,
vanished
)
->
Void
in
guard
err
==
nil
else
{
let
conerror
=
MailServerConnectionError
.
findErrorCode
(
error
:
err
!
)
self
.
errorhandling
(
error
:
conerror
,
originalCall
:
{
self
.
initFolder
(
folderPath
:
folderPath
,
completionCallback
:
completionCallback
)},
completionCallback
:
completionCallback
)
return
}
if
let
msgs
=
msg
{
FolderRecord
.
lastDate
(
folder
:
folderPath
,
date
:
Date
())
for
message
in
msgs
{
toFetchIDs
.
add
(
UInt64
(
message
.
uid
))
}
self
.
loadMessagesFromServer
(
toFetchIDs
,
folderPath
:
folderPath
,
maxLoad
:
50
,
completionCallback
:
completionCallback
)
}
else
{
completionCallback
(
nil
)
}
}
})
}
private
func
initInbox
(
completionCallback
:
@escaping
((
MailServerConnectionError
?)
->
()))
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment