aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/nntp/camel-nntp-newsrc.c
diff options
context:
space:
mode:
authorChris Toshok <toshok@helixcode.com>2000-09-01 08:57:20 +0800
committerChris Toshok <toshok@src.gnome.org>2000-09-01 08:57:20 +0800
commit3cf4f0d243e0c84b519fe027a3299a925e7075fb (patch)
tree666af08cf25c07ea8c2da1235c4ab512f30193ce /camel/providers/nntp/camel-nntp-newsrc.c
parent65d4250703d68534210c57f4ed413f95b24390d3 (diff)
downloadgsoc2013-evolution-3cf4f0d243e0c84b519fe027a3299a925e7075fb.tar
gsoc2013-evolution-3cf4f0d243e0c84b519fe027a3299a925e7075fb.tar.gz
gsoc2013-evolution-3cf4f0d243e0c84b519fe027a3299a925e7075fb.tar.bz2
gsoc2013-evolution-3cf4f0d243e0c84b519fe027a3299a925e7075fb.tar.lz
gsoc2013-evolution-3cf4f0d243e0c84b519fe027a3299a925e7075fb.tar.xz
gsoc2013-evolution-3cf4f0d243e0c84b519fe027a3299a925e7075fb.tar.zst
gsoc2013-evolution-3cf4f0d243e0c84b519fe027a3299a925e7075fb.zip
make this a bit more robust. try to create an empty .newsrc file for the
2000-08-31 Chris Toshok <toshok@helixcode.com> * providers/nntp/camel-nntp-newsrc.c (camel_nntp_newsrc_read_for_server): make this a bit more robust. try to create an empty .newsrc file for the server if we can't open it for reading. also, don't allocate everything until we've opened the file. * providers/nntp/camel-nntp-utils.c (get_OVER_headers): make use of our overview field indices. (camel_nntp_get_headers): only call get_OVER_headers if the extension is present. warn if it's not - since get_HEAD_headers needs work before it works. * providers/nntp/camel-nntp-store.c (camel_nntp_store_get_extensions): new function - query the server for it's extensions. (camel_nntp_store_get_overview_fmt): new function - query the server for the overview format and build our table of the indices we care about. support the "full" suffix on fields. (nntp_store_connect): call camel_nntp_store_get_extensions and camel_nntp_store_get_overview_fmt. * providers/nntp/camel-nntp-store.h: add codes for extensions found on news.mozilla.org. only one that we care about is OVER. also, add CamelNNTPOverField and an enum of the overview fields that we care about. svn path=/trunk/; revision=5152
Diffstat (limited to 'camel/providers/nntp/camel-nntp-newsrc.c')
-rw-r--r--camel/providers/nntp/camel-nntp-newsrc.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/camel/providers/nntp/camel-nntp-newsrc.c b/camel/providers/nntp/camel-nntp-newsrc.c
index 81594d3dcd..9510fe5bfa 100644
--- a/camel/providers/nntp/camel-nntp-newsrc.c
+++ b/camel/providers/nntp/camel-nntp-newsrc.c
@@ -26,6 +26,8 @@
#include <string.h>
#include <stdlib.h>
#include <glib.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "camel-nntp-newsrc.h"
typedef struct {
@@ -440,17 +442,33 @@ camel_nntp_newsrc_read_for_server (const char *server)
{
FILE *fp;
char buf[BUFFER_LENGTH];
- CamelNNTPNewsrc *newsrc = g_new0(CamelNNTPNewsrc, 1);
+ char *filename = g_strdup_printf ("%s/.newsrc-%s", g_get_home_dir(), server);
+ CamelNNTPNewsrc *newsrc;
+
+ if ((fp = fopen(filename, "r")) == NULL) {
+ int fd;
+
+ g_warning ("~/.newsrc-%s not present. creating empty file\n", server);
+
+ if ((fd = open (filename, O_CREAT, O_TRUNC, O_WRONLY, 0777)) < 0) {
+ g_warning ("unable to create ~/.newsrc-%s file\n", server);
+ g_free (filename);
+ return NULL;
+ }
+ close (fd);
- newsrc->filename = g_strdup_printf ("%s/.newsrc-%s", g_get_home_dir(), server);
+ if ((fp = fopen(filename, "r")) == NULL) {
+ g_warning ("unable to open ~/.newsrc-%s file on second try.\n", server);
+ g_free (filename);
+ return NULL;
+ }
+ }
+
+ newsrc = g_new0(CamelNNTPNewsrc, 1);
+ newsrc->filename = filename;
newsrc->groups = g_hash_table_new (g_str_hash, g_str_equal);
newsrc->subscribed_groups = g_hash_table_new (g_str_hash, g_str_equal);
- if ((fp = fopen(newsrc->filename, "r")) == NULL) {
- g_free (newsrc->filename);
- g_free (newsrc);
- return NULL;
- }
while (fgets(buf, MAX_LINE_LENGTH, fp) != NULL) {
/* we silently ignore (and lose!) lines longer than 20 * 1500 chars.