/* Copyright 2001-2005 The Apache Software Foundation or its licensors, as * applicable. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* This is a module which will present an mbox file stored locally to the * world in a nice format. * * This Apache-2.x module is dependent upon mbox_parse.c and mbox_thread.c. * Most of the logic for storing and retrieving data about the mbox is * located in mbox_parse.c. The logic for determining threading information * is located in mbox_thread.c. * * All presentation logic for the mbox is stored here in the module. * * By placing the appropriate AddHandler configuration in httpd.conf * (mbox-handler), you can then access the list of messages of any mbox * file by accessing it like the following: * http://www.example.com/foo/bar.mbox/ * * Direct link to raw messages are also available: * http://www.example.com/foo/bar.mbox/raw?%3c12345@example.com%3e * * Please note that the actual indexing of the messages does not occur * here in the module, but in the "generate_index" standalone program. */ #include "mod_mbox.h" /* Register module hooks. */ static void mbox_register_hooks(apr_pool_t *p) { ap_hook_handler(mbox_file_handler, NULL, NULL, APR_HOOK_MIDDLE); ap_hook_handler(mbox_index_handler, NULL, NULL, APR_HOOK_FIRST); ap_hook_handler(mbox_search_handler, NULL, NULL, APR_HOOK_MIDDLE); } /* Module configuration management. */ static void *mbox_create_dir_config(apr_pool_t *p, char *x) { mbox_dir_cfg_t *conf; conf = apr_pcalloc(p, sizeof(mbox_dir_cfg_t)); conf->enabled = 0; conf->hide_empty = 0; conf->root_path = NULL; conf->search_path = NULL; conf->style_path = NULL; conf->script_path = NULL; return conf; } static void *mbox_merge_dir_config(apr_pool_t *p, void *basev, void *addv) { mbox_dir_cfg_t *from = (mbox_dir_cfg_t *)basev; mbox_dir_cfg_t *merge = (mbox_dir_cfg_t *)addv; mbox_dir_cfg_t *to; to = apr_palloc(p, sizeof(mbox_dir_cfg_t)); /* Update 'enabled' */ if (merge->enabled == 1) { to->enabled = 1; } else { to->enabled = from->enabled; } /* Update 'hide_empty' */ if (merge->hide_empty == 1) { to->hide_empty = 1; } else { to->hide_empty = from->hide_empty; } /* Update 'antispam' */ if (merge->antispam == 1) { to->antispam = 1; } else { to->antispam = from->antispam; } /* Update 'root_path' */ if (merge->root_path != NULL) { to->root_path = apr_pstrdup(p, merge->root_path); } else if (from->root_path != NULL) { to->root_path = apr_pstrdup(p, from->root_path); } else { to->root_path = NULL; } /* Update 'search_path' */ if (merge->search_path != NULL) { to->search_path = apr_pstrdup(p, merge->search_path); } else if (from->search_path != NULL) { to->search_path = apr_pstrdup(p, from->search_path); } else { to->search_path = NULL; } /* Update 'style_path' */ if (merge->style_path != NULL) { to->style_path = apr_pstrdup(p, merge->style_path); } else if (from->style_path != NULL) { to->style_path = apr_pstrdup(p, from->style_path); } else { to->style_path = NULL; } /* Update 'style_path' */ if (merge->script_path != NULL) { to->script_path = apr_pstrdup(p, merge->script_path); } else if (from->script_path != NULL) { to->script_path = apr_pstrdup(p, from->script_path); } else { to->script_path = NULL; } return to; } /* Wrap text to MBOX_WRAP_TO. Changes passed string. */ char *mbox_wrap_text(char *str) { int i, pos; if (!str || (strlen(str) < MBOX_WRAP_TO)) return str; for (i=0, pos=0; i= MBOX_WRAP_TO) && ((str[i] == ' ') || (str[i] == '\t'))) { str[i] = '\n'; pos = 0; } } return str; } /* Returns the archives base path */ char *get_base_path(request_rec *r) { char *baseURI, *temp; baseURI = get_base_uri(r); temp = strstr(baseURI, ".mbox"); if (!temp) { return NULL; } temp = temp-7; *temp = 0; return baseURI; } /* Returns the base URI, stripping the path_info */ char *get_base_uri(request_rec *r) { char *baseURI, *temp; baseURI = apr_pstrdup(r->pool, r->uri); temp = strstr(baseURI, r->path_info); *temp = '\0'; return baseURI; } static const command_rec mbox_cmds[] ={ AP_INIT_FLAG("mboxindex", ap_set_flag_slot, (void *)APR_OFFSETOF(mbox_dir_cfg_t, enabled), OR_INDEXES, "Enable mod_mbox to create directory listings of .mbox files."), AP_INIT_FLAG("mboxantispam", ap_set_flag_slot, (void *)APR_OFFSETOF(mbox_dir_cfg_t, antispam), OR_INDEXES, "Enable mod_mbox email obfuscation."), AP_INIT_TAKE1("mboxsearch", ap_set_string_slot, (void *)APR_OFFSETOF(mbox_dir_cfg_t, search_path), OR_INDEXES, "Set the Directory that contains Search Data"), AP_INIT_TAKE1("mboxrootpath", ap_set_string_slot, (void *)APR_OFFSETOF(mbox_dir_cfg_t, root_path), OR_INDEXES, "Set the path to the site index."), AP_INIT_TAKE1("mboxstyle", ap_set_string_slot, (void *)APR_OFFSETOF(mbox_dir_cfg_t, style_path), OR_INDEXES, "Set the path to Css stylesheet file."), AP_INIT_TAKE1("mboxscript", ap_set_string_slot, (void *)APR_OFFSETOF(mbox_dir_cfg_t, script_path), OR_INDEXES, "Set the path to the Javascript file."), AP_INIT_FLAG("mboxhideempty", ap_set_flag_slot, (void *)APR_OFFSETOF(mbox_dir_cfg_t, hide_empty), OR_INDEXES, "Whether to display empty mboxes in index listing."), {NULL} }; module mbox_module = { STANDARD20_MODULE_STUFF, mbox_create_dir_config, /* per-directory config creator */ mbox_merge_dir_config, /* dir config merger */ NULL, /* server config creator */ NULL, /* server config merger */ mbox_cmds, /* command table */ mbox_register_hooks /* set up other request processing hooks */ };