mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 21:51:59 +01:00
finalized google free apps support
This commit is contained in:
parent
14ef68ed98
commit
f2dd3b669a
@ -73,6 +73,7 @@ installdirs: mkinstalldirs
|
||||
|
||||
$(INSTALL) -d -m 0755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) $(DESTDIR)$(localstatedir)/run/piler
|
||||
$(INSTALL) -d -m 0700 -o $(RUNNING_USER) -g $(RUNNING_GROUP) $(DESTDIR)$(localstatedir)/piler/store
|
||||
$(INSTALL) -d -m 0700 -o $(RUNNING_USER) -g $(RUNNING_GROUP) $(DESTDIR)$(localstatedir)/piler/imap
|
||||
$(INSTALL) -d -m 0755 -o $(RUNNING_USER) -g $(RUNNING_GROUP) $(DESTDIR)$(localstatedir)/piler/stat
|
||||
$(INSTALL) -d -m 0711 -o $(RUNNING_USER) -g $(RUNNING_GROUP) $(DESTDIR)$(localstatedir)/piler/tmp
|
||||
$(INSTALL) -d -m 0700 -o $(RUNNING_USER) -g $(RUNNING_GROUP) $(DESTDIR)$(localstatedir)/piler/sphinx
|
||||
|
@ -98,8 +98,6 @@ ENDE:
|
||||
|
||||
switch(rc) {
|
||||
case OK:
|
||||
//printf("imported: %s\n", filename);
|
||||
|
||||
bzero(&counters, sizeof(counters));
|
||||
counters.c_size += sdata->tot_len;
|
||||
update_counters(sdata, data, &counters, cfg);
|
||||
@ -107,7 +105,6 @@ ENDE:
|
||||
break;
|
||||
|
||||
case ERR_EXISTS:
|
||||
//printf("discarding duplicate message: %s\n", filename);
|
||||
rc = OK;
|
||||
break;
|
||||
|
||||
|
@ -28,6 +28,8 @@ extern char *optarg;
|
||||
extern int optind;
|
||||
|
||||
int quiet=0;
|
||||
int remove_after_successful_import = 0;
|
||||
|
||||
|
||||
int connect_to_imap_server(int sd, int *seq, char *imapserver, char *username, char *password);
|
||||
int list_folders(int sd, int *seq, char *folders, int foldersize);
|
||||
@ -211,6 +213,8 @@ int import_from_maildir(char *directory, struct session_data *sdata, struct __da
|
||||
if(rc == OK) (*tot_msgs)++;
|
||||
else ret = ERR;
|
||||
|
||||
if(remove_after_successful_import == 1 && ret != ERR) unlink(fname);
|
||||
|
||||
i++;
|
||||
|
||||
if(quiet == 0) printf("processed: %7d\r", *tot_msgs); fflush(stdout);
|
||||
@ -293,7 +297,7 @@ int import_from_imap_server(char *imapserver, char *username, char *password, st
|
||||
|
||||
|
||||
void usage(){
|
||||
printf("usage: pilerimport [-c <config file>] -e <eml file> | -m <mailbox file> | -d <directory> | -i <imap server> -u <imap username> -p <imap password> [-F <foldername>] [-R]\n");
|
||||
printf("usage: pilerimport [-c <config file>] -e <eml file> | -m <mailbox file> | -d <directory> | -i <imap server> -u <imap username> -p <imap password> [-F <foldername>] [-R] [-r] [-q]\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@ -328,16 +332,18 @@ int main(int argc, char **argv){
|
||||
{"password", required_argument, 0, 'p' },
|
||||
{"skiplist", required_argument, 0, 'x' },
|
||||
{"folder", required_argument, 0, 'F' },
|
||||
{"quiet", required_argument, 0, 'q' },
|
||||
{"recursive", required_argument, 0, 'R' },
|
||||
{"remove-after-import", required_argument, 0, 'r' },
|
||||
{"help", no_argument, 0, 'h' },
|
||||
{0,0,0,0}
|
||||
};
|
||||
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "c:m:M:e:d:i:u:p:x:F:Rh?", long_options, &option_index);
|
||||
c = getopt_long(argc, argv, "c:m:M:e:d:i:u:p:x:F:Rrqh?", long_options, &option_index);
|
||||
#else
|
||||
c = getopt(argc, argv, "c:m:M:e:d:i:u:p:x:F:Rh?");
|
||||
c = getopt(argc, argv, "c:m:M:e:d:i:u:p:x:F:Rrqh?");
|
||||
#endif
|
||||
|
||||
if(c == -1) break;
|
||||
@ -393,6 +399,14 @@ int main(int argc, char **argv){
|
||||
data.recursive_folder_names = 1;
|
||||
break;
|
||||
|
||||
case 'r' :
|
||||
remove_after_successful_import = 1;
|
||||
break;
|
||||
|
||||
case 'q' :
|
||||
quiet = 1;
|
||||
break;
|
||||
|
||||
case 'h' :
|
||||
case '?' :
|
||||
usage();
|
||||
|
59
util/gmail-imap-import.php
Normal file
59
util/gmail-imap-import.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
$webuidir = "";
|
||||
|
||||
if(isset($_SERVER['argv'][1])) { $webuidir = $_SERVER['argv'][1]; }
|
||||
|
||||
require_once($webuidir . "/config.php");
|
||||
|
||||
ini_set("session.save_path", DIR_TMP);
|
||||
|
||||
require(DIR_SYSTEM . "/startup.php");
|
||||
|
||||
require_once 'Zend/Mail/Protocol/Imap.php';
|
||||
require_once 'Zend/Mail/Storage/Imap.php';
|
||||
|
||||
$request = new Request();
|
||||
Registry::set("request", $request);
|
||||
|
||||
|
||||
session_start();
|
||||
|
||||
Registry::set('document', new Document());
|
||||
|
||||
|
||||
$loader = new Loader();
|
||||
Registry::set('load', $loader);
|
||||
|
||||
|
||||
$language = new Language();
|
||||
Registry::set('language', $language);
|
||||
|
||||
|
||||
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE, DB_PREFIX);
|
||||
Registry::set('DB_DATABASE', DB_DATABASE);
|
||||
|
||||
Registry::set('db', $db);
|
||||
|
||||
Registry::set('DB_DRIVER', DB_DRIVER);
|
||||
|
||||
|
||||
$loader->model('user/google');
|
||||
$loader->model('google/google');
|
||||
|
||||
openlog("piler-gmail-import", LOG_PID, LOG_MAIL);
|
||||
|
||||
$ug = new ModelUserGoogle();
|
||||
$g = new ModelGoogleGoogle();
|
||||
|
||||
|
||||
|
||||
$query = $db->query("SELECT email FROM " . TABLE_GOOGLE);
|
||||
if(isset($query->rows)) {
|
||||
foreach($query->rows as $q) {
|
||||
$access_token = $ug->refresh_access_token($q['email']);
|
||||
$g->download_users_emails($q['email'], $access_token);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -65,10 +65,11 @@ define('DIR_APPLICATION', DIR_BASE . 'controller/');
|
||||
define('DIR_THEME', DIR_BASE . 'view/theme/');
|
||||
define('DIR_REPORT', DIR_BASE . 'reports/');
|
||||
define('DIR_LOG', DIR_BASE . 'log/');
|
||||
define('DIR_TMP', DIR_BASE . 'tmp/');
|
||||
|
||||
define('DIR_STORE', '/var/piler/store');
|
||||
define('DIR_STAT', '/var/piler/stat');
|
||||
define('DIR_IMAP', '/var/piler/imap');
|
||||
define('DIR_TMP', '/var/piler/tmp');
|
||||
|
||||
define('DECRYPT_BINARY', '/usr/local/bin/pilerget');
|
||||
define('DECRYPT_BUFFER_LENGTH', 65536);
|
||||
@ -176,7 +177,7 @@ define('CGI_INPUT_FIELD_WIDTH', 50);
|
||||
define('CGI_INPUT_FIELD_HEIGHT', 7);
|
||||
|
||||
define('MEMCACHED_PREFIX', '_piler:');
|
||||
define('MEMCACHED_TTL', 3600);
|
||||
define('MEMCACHED_TTL', 600);
|
||||
|
||||
$memcached_servers = array(
|
||||
array('127.0.0.1', 11211)
|
||||
|
@ -48,6 +48,7 @@ class ModelGoogleGoogle extends Model {
|
||||
public function download_users_emails($email, $accessToken) {
|
||||
$last_msg_id = -1;
|
||||
$from = 1;
|
||||
$downloaded = 0;
|
||||
|
||||
if(!$email || !$accessToken) { return 0; }
|
||||
|
||||
@ -82,11 +83,15 @@ class ModelGoogleGoogle extends Model {
|
||||
while(list($k, $v) = each($messages)) {
|
||||
$uuid = $storage->getUniqueId($k);
|
||||
|
||||
$tmpname = DIR_TMP . "piler-" . $email . "-" . $k . "-" . $uuid . ".eml";
|
||||
$f = fopen($tmpname, "w+");
|
||||
$tmpname = "piler-" . $email . "-" . $k . "-" . $uuid . ".eml";
|
||||
$f = fopen(DIR_TMP . "/" . $tmpname, "w+");
|
||||
if($f){
|
||||
fwrite($f, $v['RFC822.HEADER'] . $v['RFC822.TEXT']);
|
||||
fclose($f);
|
||||
|
||||
rename(DIR_TMP . "/" . $tmpname, DIR_IMAP . "/" . $tmpname);
|
||||
|
||||
$downloaded++;
|
||||
}
|
||||
//print "k: $k\n";
|
||||
}
|
||||
@ -97,7 +102,7 @@ class ModelGoogleGoogle extends Model {
|
||||
}
|
||||
|
||||
|
||||
|
||||
syslog(LOG_INFO, "downloaded $downloaded messages for $email");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -80,6 +80,31 @@ class ModelUserGoogle extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function refresh_access_token($email = '') {
|
||||
if($email == '') { return ''; }
|
||||
|
||||
$query = $this->db->query("SELECT refresh_token FROM " . TABLE_GOOGLE . " WHERE email=?", array($email));
|
||||
|
||||
if(!isset($query->row['refresh_token'])) { return ''; }
|
||||
|
||||
$client = new apiClient();
|
||||
$client->setApplicationName(GOOGLE_APPLICATION_NAME);
|
||||
|
||||
$client->setClientId(GOOGLE_CLIENT_ID);
|
||||
$client->setClientSecret(GOOGLE_CLIENT_SECRET);
|
||||
$client->setRedirectUri(GOOGLE_REDIRECT_URL);
|
||||
$client->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
|
||||
|
||||
$client->refreshToken($query->row['refresh_token']);
|
||||
$s = $client->getAccessToken();
|
||||
$a = json_decode($s);
|
||||
|
||||
if(isset($a->{'access_token'})) { return $a->{'access_token'}; }
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user