mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-12-25 08:20:11 +01:00
merged folder branch
Change-Id: I57f3427b128e8b313572e7bc3734933f4d345d1c Signed-off-by: SJ <sj@acts.hu>
This commit is contained in:
commit
2ca7c9d30e
2
configure
vendored
2
configure
vendored
@ -4866,7 +4866,7 @@ echo; echo
|
||||
|
||||
CFLAGS="$static -O2 -Wall -g"
|
||||
LIBS="$antispam_libs $sunos_libs "
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o import_gui.o imap.o pop3.o extract.o mydomains.o $objs"
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o import_gui.o imap.o pop3.o extract.o folder.o mydomains.o $objs"
|
||||
|
||||
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile unit_tests/Makefile contrib/imap/Makefile"
|
||||
|
||||
|
@ -544,7 +544,7 @@ echo; echo
|
||||
|
||||
CFLAGS="$static -O2 -Wall -g"
|
||||
LIBS="$antispam_libs $sunos_libs "
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o import_gui.o imap.o pop3.o extract.o mydomains.o $objs"
|
||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o smtp.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o import_maildir.o import_mailbox.o import_pop3.o import_imap.o import_gui.o imap.o pop3.o extract.o folder.o mydomains.o $objs"
|
||||
|
||||
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile unit_tests/Makefile contrib/imap/Makefile])
|
||||
AC_OUTPUT
|
||||
|
@ -71,7 +71,7 @@ backlog=20
|
||||
|
||||
workdir=/var/piler/tmp
|
||||
|
||||
; whether to enable writing folder_message table (1) or not (0)
|
||||
; whether the daemon is enabled writing folder_message table (1) or not (0)
|
||||
enable_folders=0
|
||||
|
||||
; discard a message if it's shorter than this value (in bytes)
|
||||
|
@ -86,6 +86,14 @@ source att : base
|
||||
sql_attr_uint = mid
|
||||
}
|
||||
|
||||
source folder : base
|
||||
{
|
||||
sql_query_pre = SET NAMES utf8
|
||||
sql_query = select id, folder_id, message_id, uid FROM folder_message
|
||||
|
||||
sql_attr_uint = uid
|
||||
sql_attr_uint = folder_id
|
||||
}
|
||||
|
||||
index main1
|
||||
{
|
||||
@ -189,7 +197,7 @@ index note1
|
||||
index att1
|
||||
{
|
||||
source = att
|
||||
path = /var/piler/sphinx/att1
|
||||
path = LOCALSTATEDIR/piler/sphinx/att1
|
||||
docinfo = extern
|
||||
dict = keywords
|
||||
min_prefix_len = 6
|
||||
@ -198,6 +206,15 @@ index att1
|
||||
ngram_chars = U+1100..U+2FA1F
|
||||
}
|
||||
|
||||
index folder1
|
||||
{
|
||||
source = folder
|
||||
path = LOCALSTATEDIR/piler/sphinx/folder1
|
||||
docinfo = extern
|
||||
dict = keywords
|
||||
min_prefix_len = 6
|
||||
min_word_len = 1
|
||||
}
|
||||
|
||||
indexer
|
||||
{
|
||||
|
13
src/config.h
13
src/config.h
@ -83,6 +83,8 @@
|
||||
#define SQL_ARCHIVING_RULE_TABLE "archiving_rule"
|
||||
#define SQL_RETENTION_RULE_TABLE "retention_rule"
|
||||
#define SQL_FOLDER_RULE_TABLE "folder_rule"
|
||||
#define SQL_FOLDER_TABLE "folder"
|
||||
#define SQL_FOLDER_EMAIL_TABLE "folder_email"
|
||||
#define SQL_COUNTER_TABLE "counter"
|
||||
#define SQL_OPTION_TABLE "option"
|
||||
#define SQL_DOMAIN_TABLE "domain"
|
||||
@ -99,14 +101,16 @@
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_SPHINX_TABLE "INSERT INTO " SQL_SPHINX_TABLE " (`id`, `from`, `to`, `fromdomain`, `todomain`, `subject`, `body`, `arrived`, `sent`, `size`, `direction`, `folder`, `attachments`, `attachment_types`) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_META_TABLE "INSERT INTO " SQL_METADATA_TABLE " (`from`,`fromdomain`,`subject`,`spam`,`arrived`,`sent`,`retained`,`size`,`hlen`,`direction`,`attachments`,`piler_id`,`message_id`,`reference`,`digest`,`bodydigest`,`vcode`) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_ATTACHMENT_TABLE "INSERT INTO " SQL_ATTACHMENT_TABLE " (`piler_id`,`attachment_id`,`sig`,`name`,`type`,`size`,`ptr`) VALUES(?,?,?,?,?,?,?)"
|
||||
#define SQL_PREPARED_STMT_GET_ATTACHMENT_ID_BY_SIGNATURE "SELECT `id` FROM `" SQL_ATTACHMENT_TABLE "` WHERE `sig`=? AND `ptr`=0 AND `size`=?"
|
||||
#define SQL_PREPARED_STMT_GET_ATTACHMENT_ID_BY_SIGNATURE "SELECT `id`, `piler_id`, `attachment_id` FROM `" SQL_ATTACHMENT_TABLE "` WHERE `sig`=? AND `ptr`=0 AND `size`=?"
|
||||
#define SQL_PREPARED_STMT_GET_ATTACHMENT_POINTER "SELECT `piler_id`, `attachment_id` FROM " SQL_ATTACHMENT_TABLE " WHERE id=?"
|
||||
#define SQL_PREPARED_STMT_QUERY_ATTACHMENT "SELECT `attachment_id`, `ptr` FROM " SQL_ATTACHMENT_TABLE " WHERE piler_id=? ORDER BY attachment_id ASC"
|
||||
#define SQL_PREPARED_STMT_GET_FOLDER_ID "SELECT `id` FROM " SQL_FOLDER_TABLE " WHERE `name`=? AND `parent_id`=?"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE "INSERT INTO `" SQL_FOLDER_TABLE "` (`name`, `parent_id`) VALUES(?,?)"
|
||||
#define SQL_PREPARED_STMT_GET_FOLDER_ID "SELECT `id` FROM " SQL_FOLDER_TABLE " WHERE `name`=? AND `uid`=? AND `parent_id`=?"
|
||||
#define SQL_PREPARED_STMT_GET_FOLDER_UID_BY_EMAIL "SELECT `uid` FROM " SQL_FOLDER_EMAIL_TABLE " WHERE `email`=?"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE "INSERT INTO `" SQL_FOLDER_TABLE "` (`uid`, `name`, `parent_id`) VALUES(?,?,?)"
|
||||
#define SQL_PREPARED_STMT_INSERT_INTO_FOLDER_EMAIL_TABLE "INSERT INTO `" SQL_FOLDER_EMAIL_TABLE "` (`email`) VALUES(?)"
|
||||
#define SQL_PREPARED_STMT_UPDATE_METADATA_REFERENCE "UPDATE " SQL_METADATA_TABLE " SET reference=? WHERE message_id=? AND reference=''"
|
||||
#define SQL_PREPARED_STMT_GET_GUI_IMPORT_JOBS "SELECT id, type, username, password, server FROM " SQL_IMPORT_TABLE " WHERE started=0 ORDER BY id LIMIT 0,1"
|
||||
#define SQL_PREPARED_STMT_INSERT_FOLDER_MESSAGE "INSERT INTO " SQL_FOLDER_MESSAGE_TABLE " (`folder_id`, `id`) VALUES(?,?)"
|
||||
#define SQL_PREPARED_STMT_INSERT_FOLDER_MESSAGE "INSERT INTO " SQL_FOLDER_MESSAGE_TABLE " (`folder_id`, `message_id`, `uid`) VALUES(?,?,?)"
|
||||
|
||||
/* Error codes */
|
||||
|
||||
@ -135,4 +139,3 @@
|
||||
#define S_STATUS_ERROR "error"
|
||||
|
||||
#endif /* _CONFIG_H */
|
||||
|
||||
|
@ -63,6 +63,7 @@
|
||||
#define RULE_MATCH 1
|
||||
#define RULE_NO_MATCH -100
|
||||
|
||||
#define DEDUP_HINT_SIZE RND_STR_LEN+20
|
||||
|
||||
typedef void signal_func (int);
|
||||
|
||||
@ -83,6 +84,7 @@ struct attachment {
|
||||
char filename[TINYBUFSIZE];
|
||||
char internalname[TINYBUFSIZE];
|
||||
char digest[2*DIGEST_LENGTH+1];
|
||||
char dedup_hint[DEDUP_HINT_SIZE];
|
||||
char dumped;
|
||||
};
|
||||
|
||||
@ -284,6 +286,7 @@ struct memcached_server {
|
||||
struct import {
|
||||
char *extra_recipient;
|
||||
char *move_folder;
|
||||
char *email;
|
||||
int status;
|
||||
int total_messages;
|
||||
int processed_messages;
|
||||
@ -295,6 +298,7 @@ struct import {
|
||||
int keep_eml;
|
||||
int timeout;
|
||||
int cap_uidplus;
|
||||
int uid;
|
||||
long total_size;
|
||||
time_t started, updated, finished;
|
||||
};
|
||||
|
56
src/import.c
56
src/import.c
@ -93,6 +93,16 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
||||
}
|
||||
|
||||
rc = process_message(sdata, &state, data, cfg);
|
||||
|
||||
/*
|
||||
* if pilerimport was invoked with --email (then queried the matching uid!),
|
||||
* and this is a duplicate, then add it to the folder_extra table
|
||||
*/
|
||||
|
||||
if(rc == ERR_EXISTS && data->import->uid > 0){
|
||||
store_folder_id(sdata, data, sdata->duplicate_id);
|
||||
}
|
||||
|
||||
unlink(state.message_id_hash);
|
||||
}
|
||||
|
||||
@ -130,52 +140,6 @@ int import_message(char *filename, struct session_data *sdata, struct __data *da
|
||||
}
|
||||
|
||||
|
||||
int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id){
|
||||
int id=ERR_FOLDER;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_get_folder_id), SQL_PREPARED_STMT_GET_FOLDER_ID) == ERR) return id;
|
||||
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = foldername; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
data->sql[data->pos] = (char *)&parent_id; data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||
|
||||
if(p_exec_query(sdata, data->stmt_get_folder_id, data) == OK){
|
||||
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONG; data->len[data->pos] = sizeof(unsigned long); data->pos++;
|
||||
|
||||
p_store_results(data->stmt_get_folder_id, data);
|
||||
p_fetch_results(data->stmt_get_folder_id);
|
||||
p_free_results(data->stmt_get_folder_id);
|
||||
}
|
||||
|
||||
close_prepared_statement(data->stmt_get_folder_id);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id){
|
||||
int id=ERR_FOLDER;
|
||||
|
||||
if(foldername == NULL) return id;
|
||||
|
||||
if(prepare_sql_statement(sdata, &(data->stmt_insert_into_folder_table), SQL_PREPARED_STMT_INSERT_INTO_FOLDER_TABLE) == ERR) return id;
|
||||
|
||||
p_bind_init(data);
|
||||
data->sql[data->pos] = foldername; data->type[data->pos] = TYPE_STRING; data->pos++;
|
||||
data->sql[data->pos] = (char *)&parent_id; data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||
|
||||
if(p_exec_query(sdata, data->stmt_insert_into_folder_table, data) == OK){
|
||||
id = p_get_insert_id(data->stmt_insert_into_folder_table);
|
||||
}
|
||||
|
||||
close_prepared_statement(data->stmt_insert_into_folder_table);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
void update_import_job_stat(struct session_data *sdata, struct __data *data){
|
||||
char buf[SMALLBUFSIZE];
|
||||
|
||||
|
@ -140,6 +140,7 @@ void remove_recipients(struct session_data *sdata, uint64 id){
|
||||
|
||||
int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id){
|
||||
int rc = ERR;
|
||||
int uid0 = 0;
|
||||
|
||||
if(data->folder == ERR_FOLDER) return rc;
|
||||
|
||||
@ -149,6 +150,12 @@ int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id){
|
||||
|
||||
data->sql[data->pos] = (char *)&data->folder; data->type[data->pos] = TYPE_LONGLONG; data->pos++;
|
||||
data->sql[data->pos] = (char *)&id; data->type[data->pos] = TYPE_LONGLONG; data->pos++;
|
||||
if(sdata->import == 1){
|
||||
data->sql[data->pos] = (char *)&(data->import->uid); data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||
}
|
||||
else {
|
||||
data->sql[data->pos] = (char *)&uid0; data->type[data->pos] = TYPE_LONG; data->pos++;
|
||||
}
|
||||
|
||||
if(p_exec_query(sdata, data->stmt_insert_into_folder_message_table, data) == OK) rc = OK;
|
||||
close_prepared_statement(data->stmt_insert_into_folder_message_table);
|
||||
|
@ -43,6 +43,7 @@ int reimport_message(struct session_data *sdata, struct parser_state *state, str
|
||||
int store_file(struct session_data *sdata, char *filename, int len, struct __config *cfg);
|
||||
int remove_stored_message_files(struct session_data *sdata, struct parser_state *state, struct __config *cfg);
|
||||
int store_attachments(struct session_data *sdata, struct parser_state *state, struct __data *data, struct __config *cfg);
|
||||
int store_dedup_hint(struct session_data *sdata, struct parser_state *state, struct __config *cfg);
|
||||
int query_attachments(struct session_data *sdata, struct __data *data, struct ptr_array *ptr_arr);
|
||||
|
||||
struct __config read_config(char *configfile);
|
||||
@ -56,6 +57,9 @@ int file_from_archive_to_network(char *filename, int sd, int tls_enable, struct
|
||||
|
||||
int get_folder_id(struct session_data *sdata, struct __data *data, char *foldername, int parent_id);
|
||||
int add_new_folder(struct session_data *sdata, struct __data *data, char *foldername, int parent_id);
|
||||
void get_folder_uid_by_email(struct session_data *sdata, struct __data *data);
|
||||
|
||||
int store_folder_id(struct session_data *sdata, struct __data *data, uint64 id);
|
||||
|
||||
int store_index_data(struct session_data *sdata, struct parser_state *state, struct __data *data, uint64 id, struct __config *cfg);
|
||||
|
||||
|
@ -50,6 +50,7 @@ void usage(){
|
||||
printf(" -f <imap folder> IMAP folder name to import\n");
|
||||
printf(" -g <imap folder> Move email after import to this IMAP folder\n");
|
||||
printf(" -F <folder> Piler folder name to assign to this import\n");
|
||||
printf(" --email <email@address> Email address to assign to this import\n");
|
||||
printf(" -R Assign IMAP folder names as Piler folder names\n");
|
||||
printf(" -b <batch limit> Import only this many emails\n");
|
||||
printf(" -s <start position> Start importing POP3 emails from this position\n");
|
||||
@ -87,6 +88,8 @@ int main(int argc, char **argv){
|
||||
import.start_position = 1;
|
||||
import.download_only = 0;
|
||||
import.timeout = 30;
|
||||
import.uid = 0;
|
||||
import.email = NULL;
|
||||
|
||||
data.import = &import;
|
||||
|
||||
@ -113,6 +116,7 @@ int main(int argc, char **argv){
|
||||
{"skiplist", required_argument, 0, 'x' },
|
||||
{"folder", required_argument, 0, 'F' },
|
||||
{"folder_imap", required_argument, 0, 'f' },
|
||||
{"email", required_argument, 0, 'E' },
|
||||
{"add-recipient",required_argument, 0, 'a' },
|
||||
{"batch-limit", required_argument, 0, 'b' },
|
||||
{"timeout", required_argument, 0, 't' },
|
||||
@ -130,9 +134,9 @@ int main(int argc, char **argv){
|
||||
|
||||
int option_index = 0;
|
||||
|
||||
c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:GDRroqh?", long_options, &option_index);
|
||||
c = getopt_long(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:E:GDRroqh?", long_options, &option_index);
|
||||
#else
|
||||
c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:GDRroqh?");
|
||||
c = getopt(argc, argv, "c:m:M:e:d:i:K:u:p:P:x:F:f:a:b:t:s:g:E:GDRroqh?");
|
||||
#endif
|
||||
|
||||
if(c == -1) break;
|
||||
@ -177,6 +181,10 @@ int main(int argc, char **argv){
|
||||
username = optarg;
|
||||
break;
|
||||
|
||||
case 'E' :
|
||||
data.import->email = optarg;
|
||||
break;
|
||||
|
||||
case 'p' :
|
||||
password = optarg;
|
||||
break;
|
||||
@ -266,11 +274,6 @@ int main(int argc, char **argv){
|
||||
|
||||
cfg = read_config(configfile);
|
||||
|
||||
if((data.recursive_folder_names == 1 || folder) && cfg.enable_folders == 0){
|
||||
printf("please set enable_folders=1 in piler.conf to use the folder options\n");
|
||||
return ERR;
|
||||
}
|
||||
|
||||
/* make sure we don't discard messages without a valid Message-Id when importing manually */
|
||||
cfg.archive_emails_not_having_message_id = 1;
|
||||
|
||||
@ -293,7 +296,17 @@ int main(int argc, char **argv){
|
||||
memcached_init(&(data.memc), cfg.memcached_servers, 11211);
|
||||
#endif
|
||||
|
||||
if(folder || data.recursive_folder_names == 1){
|
||||
cfg.enable_folders = 1;
|
||||
|
||||
if(data.import->email){
|
||||
get_folder_uid_by_email(&sdata, &data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(folder){
|
||||
|
||||
data.folder = get_folder_id(&sdata, &data, folder, 0);
|
||||
|
||||
if(data.folder == ERR_FOLDER){
|
||||
@ -305,7 +318,6 @@ int main(int argc, char **argv){
|
||||
close_database(&sdata);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||
|
@ -272,35 +272,30 @@ create table if not exists `domain_user` (
|
||||
|
||||
|
||||
create table if not exists `folder` (
|
||||
`id` int not null auto_increment,
|
||||
`folder_id` int not null auto_increment,
|
||||
`parent_id` int default 0,
|
||||
`uid` int default 0,
|
||||
`name` char(64) not null,
|
||||
unique(`parent_id`, `name`),
|
||||
primary key (`id`)
|
||||
unique(`uid`, `name`),
|
||||
primary key (`folder_id`)
|
||||
) Engine=InnoDB;
|
||||
|
||||
|
||||
create table if not exists `folder_user` (
|
||||
`id` bigint unsigned not null,
|
||||
`uid` int unsigned not null,
|
||||
key `folder_user_idx` (`id`),
|
||||
key `folder_user_idx2` (`uid`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
create table if not exists `folder_extra` (
|
||||
`id` int unsigned not null auto_increment,
|
||||
`uid` int unsigned not null,
|
||||
`name` char(64) not null,
|
||||
unique(uid, name),
|
||||
key (`id`)
|
||||
create table if not exists `folder_email` (
|
||||
`uid` int unsigned not null auto_increment,
|
||||
`email` char(128) not null unique,
|
||||
key `folder_email_idx` (`uid`),
|
||||
key `folder_email_idx2` (`email`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
create table if not exists `folder_message` (
|
||||
folder_id bigint not null,
|
||||
id bigint not null,
|
||||
unique(folder_id, id)
|
||||
`id` bigint unsigned auto_increment not null,
|
||||
`folder_id` bigint not null,
|
||||
`message_id` bigint not null,
|
||||
`uid` int not null,
|
||||
unique(`message_id`, `uid`),
|
||||
key (`id`)
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
|
@ -209,6 +209,7 @@ $config['SPHINX_MAIN_INDEX'] = 'main1,dailydelta1,delta1';
|
||||
$config['SPHINX_ATTACHMENT_INDEX'] = 'att1';
|
||||
$config['SPHINX_TAG_INDEX'] = 'tag1';
|
||||
$config['SPHINX_NOTE_INDEX'] = 'note1';
|
||||
$config['SPHINX_FOLDER_INDEX'] = 'folder1';
|
||||
|
||||
$config['RELOAD_COMMAND'] = 'sudo -n /etc/init.d/rc.piler reload';
|
||||
$config['PILERIMPORT_IMAP_COMMAND'] = '/usr/local/bin/pilerimport -d /var/piler/imap -q -r';
|
||||
@ -341,7 +342,7 @@ define('TABLE_GROUP_USER', 'group_user');
|
||||
define('TABLE_GROUP_EMAIL', 'group_email');
|
||||
define('TABLE_FOLDER', 'folder');
|
||||
define('TABLE_FOLDER_USER', 'folder_user');
|
||||
define('TABLE_FOLDER_EXTRA', 'folder_extra');
|
||||
define('TABLE_FOLDER_EMAIL', 'folder_email');
|
||||
define('TABLE_FOLDER_MESSAGE', 'folder_message');
|
||||
define('TABLE_EMAIL', 'email');
|
||||
define('TABLE_META', 'metadata');
|
||||
|
@ -45,7 +45,7 @@ class ControllerSearchHelper extends Controller {
|
||||
|
||||
if($this->request->post['searchtype'] == 'expert'){
|
||||
|
||||
if(isset($this->request->post['search']) && preg_match("/(from|to|subject|body|direction|d|size|date1|date2|attachment|a|aname|tag|note|id)\:/", $this->request->post['search'])) {
|
||||
if(isset($this->request->post['search']) && preg_match("/(from|to|subject|body|direction|d|size|date1|date2|attachment|a|aname|tag|note|id|folder)\:/", $this->request->post['search'])) {
|
||||
$this->a = $this->model_search_search->preprocess_post_expert_request($this->request->post);
|
||||
}
|
||||
else {
|
||||
|
@ -41,8 +41,8 @@ class ControllerUserSettings extends Controller {
|
||||
|
||||
$auditgroups = preg_replace("/\n/", ", ", $this->model_group_group->get_groups_by_email($session->get("emails")));
|
||||
|
||||
$folders = $session->get("folders");
|
||||
|
||||
$folders = array_keys($session->get("folders"));
|
||||
|
||||
foreach ($folders as $r) {
|
||||
$auditfolders .= ', ' . $r;
|
||||
}
|
||||
|
@ -93,6 +93,21 @@ class ModelFolderFolder extends Model {
|
||||
}
|
||||
|
||||
|
||||
public function get_folder_names_for_user($email='') {
|
||||
$arr = array();
|
||||
|
||||
$query = $this->db->query("SELECT folder_id, name FROM `" . TABLE_FOLDER . "` WHERE uid IN (SELECT uid FROM `" . TABLE_FOLDER_EMAIL . "` WHERE email=?)", array($email));
|
||||
|
||||
if(isset($query->rows)) {
|
||||
foreach ($query->rows as $q) {
|
||||
$arr[$q['name']] = $q['folder_id'];
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
public function get_folder_id_array_for_user($uid = 0, $is_admin = 0) {
|
||||
$arr = array();
|
||||
|
||||
|
@ -30,6 +30,8 @@ class ModelSearchSearch extends Model {
|
||||
if($data['sort'] == "from") { $sort = "from"; }
|
||||
if($data['sort'] == "subj") { $sort = "subject"; }
|
||||
|
||||
if(isset($data['folder']) && $data['folder']) { $sort = "id"; }
|
||||
|
||||
if($data['order'] == 1) { $order = "ASC"; }
|
||||
|
||||
$sortorder = "ORDER BY `$sort` $order";
|
||||
@ -106,7 +108,6 @@ class ModelSearchSearch extends Model {
|
||||
|
||||
$session = Registry::get('session');
|
||||
|
||||
|
||||
$i = 0;
|
||||
while(list($k, $v) = each($data['match'])) {
|
||||
if($v == "@attachment_types") {
|
||||
@ -215,6 +216,19 @@ class ModelSearchSearch extends Model {
|
||||
$total_found = $query->total_found;
|
||||
$num_rows = $query->num_rows;
|
||||
}
|
||||
else if(isset($data['folder']) && $data['folder']) {
|
||||
$folder_id = 0;
|
||||
|
||||
$folders = $session->get("folders");
|
||||
|
||||
$data['folder'] = trim($data['folder']);
|
||||
|
||||
if(isset($folders[$data['folder']])) {
|
||||
$folder_id = $folders[$data['folder']];
|
||||
}
|
||||
|
||||
$query = $this->sphx->query("SELECT id FROM " . SPHINX_FOLDER_INDEX . " WHERE folder_id=$folder_id $sortorder LIMIT 0,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS);
|
||||
}
|
||||
else if(isset($data['tag']) && $data['tag']) {
|
||||
list ($total_found, $num_rows, $id_list) = $this->get_sphinx_id_list($data['tag'], SPHINX_TAG_INDEX, 'tag', $page);
|
||||
$query = $this->sphx->query("SELECT id FROM " . SPHINX_MAIN_INDEX . " WHERE $folders id IN ($id_list) $sortorder LIMIT 0,$pagelen OPTION max_matches=" . MAX_SEARCH_HITS);
|
||||
@ -332,6 +346,7 @@ class ModelSearchSearch extends Model {
|
||||
'folders' => '',
|
||||
'extra_folders' => '',
|
||||
'id' => '',
|
||||
'folder' => '',
|
||||
'match' => array()
|
||||
);
|
||||
|
||||
@ -366,6 +381,7 @@ class ModelSearchSearch extends Model {
|
||||
else if($v == 'note:') { $token = 'note'; continue; }
|
||||
else if($v == 'ref:') { $token = 'ref'; continue; }
|
||||
else if($v == 'id:') { $token = 'id'; continue; }
|
||||
else if($v == 'folder:') { $token = 'folder'; continue; }
|
||||
else if($token != 'date1' && $token != 'date2') {
|
||||
if(preg_match("/\d{4}\-\d{1,2}\-\d{1,2}/", $v) || preg_match("/\d{1,2}\/\d{1,2}\/\d{4}/", $v)) {
|
||||
$ndate++;
|
||||
@ -387,6 +403,7 @@ class ModelSearchSearch extends Model {
|
||||
else if($token == 'note') { $a['note'] .= ' ' . $v; }
|
||||
else if($token == 'ref') { $a['ref'] = ' ' . $v; }
|
||||
else if($token == 'id') { $a['id'] .= ' ' . $v; }
|
||||
else if($token == 'folder') { $a['folder'] .= ' ' . $v; }
|
||||
|
||||
else if($token == 'direction') {
|
||||
if($v == 'inbound') { $a['direction'] = "0"; }
|
||||
|
@ -15,6 +15,9 @@ class ModelUserAuth extends Model {
|
||||
$session->set("auditdomains", $data['auditdomains']);
|
||||
$session->set("emails", $data['emails']);
|
||||
|
||||
//$data['folders'] = $this->model_folder_folder->get_folder_id_array_for_user($query->row['uid'], $data['admin_user']);
|
||||
$data['folders'] = $this->model_folder_folder->get_folder_names_for_user($data['email']);
|
||||
|
||||
$session->set("folders", $data['folders']);
|
||||
}
|
||||
|
||||
@ -124,8 +127,6 @@ class ModelUserAuth extends Model {
|
||||
$extra_emails = $this->model_user_user->get_email_addresses_from_groups($data['emails']);
|
||||
$data['emails'] = array_merge($data['emails'], $extra_emails);
|
||||
|
||||
$data['folders'] = $this->model_folder_folder->get_folder_id_array_for_user($query->row['uid'], $data['admin_user']);
|
||||
|
||||
$session->set("auth_data", $data);
|
||||
|
||||
$this->is_ga_code_needed($username);
|
||||
|
@ -34,7 +34,7 @@
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<?php if(ENABLE_FOLDER_RESTRICTIONS == 1) { ?>
|
||||
<?php if($folders) { ?>
|
||||
|
||||
<tr>
|
||||
<td><?php print $text_folders; ?>:</td>
|
||||
|
Loading…
Reference in New Issue
Block a user