Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2011
    Posts
    407
    Thanks
    18
    Thanked 26 Times in 26 Posts

    Question Handling gmail emails with imap

    I have set up a script that loops about every 30 seconds to check a gmail account I have setup for emails. The email account isn't used for other things except a few, so It's usually getting emails form the same site.

    The issue I have with my script is I can't figure out how to fully delete an email. I have tried moving it to the trash, using imap_delete and also moving it to the trash then using imap_delete on all the emails in the trash after.

    When I move it to the trash, it stays there (to be deleted after 30 days, which I'd rather have it delete immediately). If I use the imap_delete, the message disappears from folders and the trash, but I can still see it in the view all folder (not the inbox). When I move it to the trash and then do imap_delete, the same thing happens. Does anyone know of a working way to delete emails from gmail permanently?

  • #2
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    407
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Quote Originally Posted by Arcticwarrio View Post
    Well that would help if I was writing this in C# or visual basic, but I'm using php. Try checking your sources next time. Plus I already mentioned that I tried moving it to the trash and then deleting the messages in the trash can, it didn't work.

  • #4
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    sorry, didnt realise.have you tried opening a support ticket with google?
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #5
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    the only thing i can find is expunge

    PHP Code:
    deletes all tagged messagesi.e.:
    for (
    $i 0$i $num$i++) {
      
    imap_delete($box$i);
    }
    imap_expunge($box); 
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  • #6
    Regular Coder
    Join Date
    Sep 2011
    Posts
    407
    Thanks
    18
    Thanked 26 Times in 26 Posts
    Quote Originally Posted by Arcticwarrio View Post
    the only thing i can find is expunge

    PHP Code:
    deletes all tagged messagesi.e.:
    for (
    $i 0$i $num$i++) {
      
    imap_delete($box$i);
    }
    imap_expunge($box); 
    I never heard of this function so I tried it, but with no luck. Right now I'm just moving the emails to the trash for deletion until I can find a working method (if there is any). If anyone else has any other tips that might work, please don't hesitate to post.

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    expunge is definitely what you need.
    When you issue a delete, it flags the mail as to delete, but doesn't actually delete it until you've expunged it (or closed with CL_EXPUNGE).
    Are you sure your resources are correct? The stream used for the imap_expunge should be the same as that used for the imap_delete. Since you don't have any code here yourself, $box was provided but that may not be what you are calling yours. It should also be provided immediately before closing (think of it as tagging for deletion, and when you're all done you simply delete them all).
    Assuming that gmail obeys, which it should, that should delete anything you tagged for deletion. If its ending up in trash though, it is possible that gmail simply moves to trash instead since you are not using their client directly. I don't know why they would do that, but I suppose they could.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •