Open cris-m opened 1 month ago
If you don't need to access older messages, you could use folder's method since
to get smaller batch of messages, see example:
$messages = $folder->query()
->since('01.01.2024')
->all();
I hope someone will come with better solution to read ALL messages in chunks without heavy memory impact.
I still getting the same error. if there a way to handle an account with multiple messages?
I had a memory problem when fetching messages with large attachments? I fixed the memory-issue with this solution: #457 Maybe it can help you to.
I had to increase memory_limit
in php.ini
to 512M but loading all the message throw :
Webklex\ PHPIMAP\ Exceptions\ GetMessagesFailedException
Trailing data
I tried the following:
public function index(Request $request)
{
$credentials = decrypt(session('imap_credentials'));
$config = config('imap.accounts.default');
$config['username'] = $credentials['email'];
$config['password'] = $credentials['password'];
$client = Client::make($config);
if (!$client->isConnected()) {
try {
$client->checkConnection();
} catch (\Exception $e) {
Auth::logout();
$request->session()->invalidate();
return redirect()->route('login')->with('alert', [
'type' => 'danger',
'message' => 'Failed to connect to the email server. You have been logged out. Please log in again.',
]);
}
}
$folders = [];
$mailFolders = $client->getFolders($hierarchical = false);
foreach ($mailFolders as $folder) {
$folder_name = $folder->name;
// Get unread message count
$folders[$folder_name]['unread_count'] = $folder->messages()->unseen()->count();
// Fetch messages from the folder
$folders[$folder_name]['messages'] = $folder->messages()->all()->fetchOrderDesc()->get();
}
return view('office.emails.test', compact('folders'));
}
I was trying to load emails. it work on other email but I get issue with email account with multiple messages.
here is the code:
I get the following issue in laravel:
Is there a better way to load all message?