Jump to content

mark107

Members
  • Posts

    113
  • Joined

  • Last visited

Recent Profile Visitors

2,387 profile views

mark107's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. Does anyone know how I can fetch 20 emails when I am using imap???????
  2. any idea how i can fetch 20 emails using imap_fetch_overview??
  3. Hi all, I need your help. I am working on my code as I want to set the limit to 25 as I want to fetch 25 emails from gmail using imap. When I try this: <?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); // Load Composer's autoloader require_once "Mail.php"; require_once "Mail/mime.php"; require_once('Mail/IMAPv2.php'); $username = 'myusername@gmail.com'; $password = 'mypassword'; $server = '{imap.gmail.com:993/imap/ssl/ssl}INBOX'; $inbox = imap_open($server, $username, $password); $test = listMessages($inbox); print_r($test); function listMessages($inbox) { $page = 1; $per_page = 25; $sort = null; $limit = ($per_page * $page); $start = ($limit - $per_page) + 1; $start = ($start < 1) ? 1 : $start; $limit = (($limit - $start) != ($per_page-1)) ? ($start + ($per_page-1)) : $limit; $info = imap_check($inbox); $limit = ($info->Nmsgs < $limit) ? $info->Nmsgs : $limit; $msgs = ''; $result = ''; $perPage = 25; $start = $page == 1 ? 0 : $page * $perPage - ($perPage - 1); $order = 0; $by = SORTDATE; if (is_array($sort)) { $order = $this->sortBy['order'][$sort[0]]; $by = $this->sortBy['by'][$sort[1]]; } $sorted = imap_sort($inbox, $by, $order); $mails = array_chunk($sorted, $perPage); $mails = $mails[$page - 1]; print_r($mails); return $return; } ?> It will fetch and display 77,500 emails which is too much so I need to reduce it. How I can fetch 25 emails from gmail using imap when I connect to my gmail inbox?
  4. The problem I am having is I am getting the size of the database but without the KB, MB and GB which I need it. How I can use the code to select the bytes in the database?
  5. Oh right, well I just copied the code from other site so I must have got it wrong. I want to query the select of the byte values so I can convert it to MB easily. Could you please show me how I can use the code to select the bytes in example code? I did look on the link you sent you, but I need to query the byte values first then format them into kb, mb or gb using with PHP.
  6. Hi all. I need some help with my PHP code. I have got a problem with the code, because it did not come with MB, KB or GB as the return output. I'm only getting which it is "60.1" as the return output. Here is the code: $db_name = "dbuser_table"; $mailbox = $link->prepare("SELECT table_schema,ROUND(SUM(data_length + index_length) *1024, 2) AS dbsize FROM information_schema.TABLES WHERE table_schema = '$db_name'"); $mailbox->execute(); $data = $mailbox->fetch(PDO::FETCH_ASSOC); $db_size = $data['dbsize']; echo $db_size; Here is what I want to achieve as the return output: 60.1MB The only way I can do is convert it to byte, but I cant convert to byte because I'm keep getting "60.1" as the return output. Do you know how I can get the return output of the database size with kb, mb or gb? What do I need to use to get the return output of the DB size with the kb, mb or gb? Thanks in advance.
  7. Hi all, I need your help with my PHP coding. I'm working on the snippet to calculating on the two folders and the database to get the used size, then I'm calculating on the used size with the percent to make the width size. <?php //Connect to the database require_once('../config.php'); $db_name = "db_user"; $mailbox = $link->prepare("SELECT table_schema,SUM( data_length + index_length ) / 1024 AS dbsize FROM information_schema.TABLES WHERE table_schema = '$db_name'"); $mailbox->execute(); $data = $mailbox->fetch(PDO::FETCH_ASSOC); $db_size = $data['dbsize']; $SIZE_LIMIT = 1073741824; // 1 GB $upload_folder = foldersize('../uploads/'); $attachments_folder = foldersize('../u/attachments/'); $bytes = $upload_folder + $attachments_folder; $disk_used = $bytes + $db_size; $disk_remaining = $SIZE_LIMIT - $disk_used; $free_space = convertToReadableSize($disk_remaining); $total = $SIZE_LIMIT; $free = $SIZE_LIMIT - $disk_used; $percentage = ($free / $total) * 100; $width_size = 100 - round($percentage); echo "width_size.............." . $width_size . '%'; ?> I want to make the width size with percent that start from 0% to 100% when I calculate on the two folders and the database to get the disk size and then calculate on the percent. On my code, it show that I have used 8% of the disk size when the disk used size is 144MB and the limit size I can use is 1GB. I'm not sure if I have wrote the code correctly. Is that the correct way to calculate to make the total size and take away the disk used size then work out the percent or if I have done it wrong?
  8. Yes I do but I will use sa-learn to scan my spam / junk folders in my mail directory later on. I will let the cron job to do the work automatically. It sounds like to me I would need to call imap to move the emails to junk folder and let the cron job to run sa-learn later to scan these spam messages in the mail directory, is that correct??
  9. Yes this is what I am doing right now to move the emails to spam folder when I mark them as spam. I know that it can be easily be done by insert the data into Spam DB and delete the emails from any DB table. I need to inform sa-learn to let them know that I have mark the emails as spam and I know that I don't need to use sa-learn later when I report the emails as spam or revoke as ham. When I report the emails as spam and not spam, I have got two choice to do this. 1. Create a file to output the header in the file and run the sa-learn to scan these spam messages. 2. Call imap to move the emails to junk folder and run the sa-learn to scan these spam messages. As I can see the files have already been created in "/home/username/mail/mydomain.com/myaccount/.spam/" so there is no need to create the same file with the same output. It will save my disk space from being waste. It sounds like to me I would need to call imap using with uid to move the emails to junk folder and run the sa-learn later on to scan the emails automatically to train the filter, is that correct?
  10. What do you mean what I'm doing that is unnecessary? Yes, I am using the class, but I can also run shell_exec which it works the same way as the class I use which it can be done by using this: $output = shell_exec('/usr/local/cpanel/3rdparty/bin/sa-learn -p /home/username/.spamassassin/user_prefs --spam /home/username/public_html/test/{new}'); echo "<pre>$output</pre>"; I have been using it as it works great, but there is a problem. I need to create a new file in order to run the command. If I report 2 emails as spam and then report one of these emails as not spam, how would sa-learn suppose to know which emails I report is not spam if I use the same filename that I created in the /home/username/public_html/test/new folder??
  11. Oh right, if I use this: Update_bayes.php <?php ini_set('display_errors', '1'); ini_set('display_startup_errors', '1'); error_reporting(E_ALL); require_once('../Spamassassin/Client.php'); require_once('../Spamassassin/Client/Exception.php'); require_once('../Spamassassin/Client/Result.php'); $spam_mailbox = $link->prepare("SELECT count(*) FROM `Spam` WHERE readtype = ?"); $spam_mailbox->execute([$unread]); $row = spam_mailbox->fetch(PDO::FETCH_ASSOC); $header = $row['header']; $fp = fopen('/home/user/myfolder/spam.txt', 'w'); fwrite($fp, $header); fclose($fp); $message = @file_get_contents('spam.txt'); $params = array( "hostname" => "localhost", "port" => "783", "user" => "root"); $sa = new Spamassassin\Client($params); if ($isSpam == 'Spam') { $sa->report($email_content); } else if ($isSpam == 'Not Spam') { $sa->revoke($email_content); } ?> To run on cron job, example: /usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/public_html/username/myfolder/update_bayes.php Would it work to get the Bayes database update if I run PHP script on cron job so the sa-learn could scan my emails and learn from it?? But what if the server goes offline would the sa-learn lose the information before the server get back online??
  12. Great. I have been told that I need to create the file to output the email header included the body for sa-learn to scan the email and then update the bayes database??
  13. Hi all, I wonder if any of you could help me with this. I'm storing the source emails in a database after I have fetching the emails from imap. I'm running the cron job in every 24 hours to monitor for spam emails in the spam folder so the Bayes database can get update. Here is what I use to run on cron job: /usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/mail/mydomain.com/myaccount/.spam/{cur,new As I'm using to store the emails in a database, can I run the PHP on cron job to get the Bayes database update? Example: /usr/local/cpanel/3rdparty/bin/sa-learn -p ~/.spamassassin/user_prefs --spam ~/public_html/username/myfolder/update_bayes.php Would it ever work to get the Bayes database update so the spamassassin could learn from it??
  14. Oh right, what command do you use to put in the cron job to get it to run in every 24 hours?? How do you call the spamassassin to add the rules when you mark the emails as spam? Do you use the same API as I use?
  15. How do you use your PHP to run sa-learn to train the emails as junk?? I need to see it how you did it so I can run for a test, if you dont show it I won't know how you did it.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.