-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getBody on null #30
Comments
After a few hours spent building my own solution to icloud mails I have found additional issues that you might want to look into considering this is a work in progress. If linebreaks are included in a mail sent from icloud they are split into one part per linebreak. So if I was to write the following. Update, the issues seems to stem from sending emails from a phone in combination with icloud, might use different ASCII for linebreak than a computer does. |
can I see the solution you built? I ran into this same problem... |
`public function hasNoParts(){ public function extractFromBody(){
public function getDecodedBody( $content ) { |
New to github, don't know why the supplied code spazzes out half way... |
use 3 backtics |
by the way, thank you very much, I really need to get this done tonight, and this was in the way |
No worries, there's way to little info on the google API for PHP anyway. |
I mean, thanks. There's no errors, but they're all null Am I using this right? Call extractfrombody? when looping through messages? Looking over it... |
you need to have the payload as a class variable to be able to extract data on it. I set the payload from the message as such: |
in the constructor of mail.php? |
aha! got it! Thanks! |
It's already set in the mail constructor of the dacastro4 mail.php class. As long as you instantiate the class it should work. However, I'm not sure it can be called statically like other methods. The class I made is not the same however, so you might run into issues. |
some small things, but I implemented it and pushed to production, you saved me man, I had a meeting tomorrow and I was going to tell them this part isn't working, thanks. |
no worries, you'll do the same for someone else some day :) |
This is an optional method that I have found works great for extracting the body of a message. It does not change any of your existing code. You simply call $message->extractBodyFrom . This was written by buckfuddey. See issue #30 It has worked reliably for me in production for 2 days now. Admittedly not the style you have, but it works to patch up some of the holes that keep creating this error. I propose you add it for now until at which point later you can clean it up, if you wish.
Hi, here is a simple but effective solution: $gmail = LaravelGmail::message()->preload()->all();
} |
This solution wont work if the body as "deeper parts", and you wont get attachments if the body is null. In your controller:
In the function you want to get the emails. In my case I want to get all the emails and attachments and store then, but for this example just the general idea
|
I found great use of your package however the function getBodyPart() in the file Services/Messages/mail.php line 350 has the option to return null to a function which later calls getBody() on the returned value. And if you call getBody on null it throws a fatal error.
I found that only messages from icloud causes this problem since gmail's own library sets the body (plaintext) in the payload object rather than in a part.
As you can see in the images below, one email object does not have parts, it was recieved from an icloud account and the second from a gmail account, however i have tried with yahoo, hotmail and privately hosted mail servers aswell, and those work.
A suggestion is to do a check first to see if the payload has parts to begin with, and if not extract the data from the payload body itself.
The text was updated successfully, but these errors were encountered: