/[drupal]/contributions/modules/mail_api/contrib/maildir_api/maildir_api.module
ViewVC logotype

Diff of /contributions/modules/mail_api/contrib/maildir_api/maildir_api.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Fri Oct 2 20:45:43 2009 UTC revision 1.1.2.1, Fri Oct 2 20:45:43 2009 UTC
# Line 0  Line 1 
1    <?php
2    
3    /**
4     * Implementation of the _init hook
5     */
6    function maildir_api_init() {
7    
8    
9    }
10    
11    /**
12     * Implementation of hook_help()
13     *
14     * @param unknown_type $path
15     * @param unknown_type $arg
16     * @return unknown
17     */
18    function maildir_api_help($path, $arg) {
19      switch($path) {
20        case 'admin/help#imap_api':
21         return '<p>'.t('Implements Maildir protocol used by Dovecot.');
22      }
23    }
24    
25    /**
26     * implementation of mail_api_protocols hook
27     *
28     * @return unknown
29     */
30    function maildir_api_mail_api_protocols() {
31      //echo "returning IMAP<br>\n";
32      return array('Maildir' => t('Maildir'));
33    }
34    
35    function maildir_api_mail_api_authenticate() {
36       drupal_set_message('maildir_api_mail_api_authenticate');
37    }
38    
39    /*
40    function imapwu_api_overview() {
41       drupal_set_message('imapwu_api_overview');
42    }
43    */
44    
45    function maildir_api_mail_api_overview($args) {
46    
47       drupal_set_message('maildir_api_mail_api_overview');
48    
49       $dir = '/home/admin/Maildir/cur';
50       if ($handle = opendir($dir)) {
51    
52          /* This is the correct way to loop over the directory. */
53          while (false !== ($file = readdir($handle))) {
54             if($file=='.' || $file=='..') continue;
55             //echo $file."<br>\n";
56             $headers[] = maildir_api_parse_message($dir.'/'.$file);
57          }
58    
59          closedir($handle);
60       }
61    
62       $dir = '/home/admin/Maildir/new';
63       if ($handle = opendir($dir)) {
64    
65          /* This is the correct way to loop over the directory. */
66          while (false !== ($file = readdir($handle))) {
67             if($file=='.' || $file=='..') continue;
68             //echo $file."<br>\n";
69             $headers[] = maildir_api_parse_message($dir.'/'.$file);
70          }
71    
72          closedir($handle);
73       }
74    
75       //print_r($headers);
76       return $headers;
77    }
78    
79    function maildir_api_parse_message($file) {
80    
81       //echo $file;
82    
83       //if(!file_exists($file)) return FALSE;
84    
85       $lines = file($file);
86    
87       foreach($lines as $index=>$line) {
88          if(preg_match("/To:/", $line)) {
89             list($junk, $to) = split(":", $line);
90          }
91    
92          if(preg_match("/Cc:/", $line)) {
93             list($junk, $cc) = split(":", $line);
94          }
95    
96          if(preg_match("/From:/", $line)) {
97             list($junk, $from) = split(":", $line);
98          }
99    
100          if(preg_match("/Subject:/", $line)) {
101             list($junk, $subject) = split(":", $line);
102          }
103    
104          if(preg_match("/Date:/", $line)) {
105             list($junk, $date) = split(":", $line, 2);
106          }
107    
108       }
109    
110       //drupal_set_message($date);
111    
112       $header = new stdClass();
113       $header -> message_id = $file;
114       $header -> folder = "INBOX";
115       $header -> to = trim($to);
116       $header -> cc = trim($cc);
117       $header -> from = trim($from);
118       $header -> subject = trim($subject);
119       $header -> date = strtotime($date);
120       $header -> size = filesize($file);
121    
122       //print_r($header);
123       return $header;
124    }
125    ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2