ctlfile doesn't seem to support a seekp() method that can jump to the end of the file.
Attached is a patch which adds and uses such a method. I can now modify the control file from a courierfilter without corrupting the file.
diff -ru courier-0.48.2.orig/afx/afx.h courier-0.48.2/afx/afx.h
--- courier-0.48.2.orig/afx/afx.h 2001-08-07 17:53:30.000000000 -0700
+++ courier-0.48.2/afx/afx.h 2005-01-26 11:18:46.019909831 -0800
@@ -375,6 +375,7 @@
void close();
void seekg(std::streampos);
void seekp(std::streampos);
+ void seekp(std::streamoff off, std::ios::seekdir dir);
int handle() { return (fd); }
void handle(int f);
int sync();
@@ -392,6 +393,7 @@
void close() { fd_.close(); }
void seekg(std::streampos p) { fd_.seekg(p); }
void seekp(std::streampos p) { fd_.seekp(p); }
+ void seekp(std::streamoff off, std::ios::seekdir dir) { fd_.seekp(off, dir); }
int fd() { return (fd_.handle()); }
void fd(int f) { fd_.handle(f); }
void sync() { fd_.sync(); }
@@ -405,6 +407,7 @@
void close() { fd_.close(); }
void seekg(std::streampos p) { fd_.seekg(p); }
void seekp(std::streampos p) { fd_.seekp(p); }
+ void seekp(std::streamoff off, std::ios::seekdir dir) { fd_.seekp(off, dir); }
int fd() { return (fd_.handle()); }
void fd(int f) { fd_.handle(f); }
void sync() { fd_.sync(); }
@@ -418,6 +421,7 @@
void close() { fd_.close(); }
void seekg(std::streampos p) { fd_.seekg(p); }
void seekp(std::streampos p) { fd_.seekp(p); }
+ void seekp(std::streamoff off, std::ios::seekdir dir) { fd_.seekp(off, dir); }
int fd() { return (fd_.handle()); }
void fd(int f) { fd_.handle(f); }
void sync() { fd_.sync(); }
diff -ru courier-0.48.2.orig/afx/afxpipe.C courier-0.48.2/afx/afxpipe.C
--- courier-0.48.2.orig/afx/afxpipe.C 2001-08-05 13:00:33.000000000 -0700
+++ courier-0.48.2/afx/afxpipe.C 2005-01-26 11:19:40.829108003 -0800
@@ -56,6 +56,17 @@
setg(buffer, buffer+sizeof(buffer), buffer+sizeof(buffer));
}
+void afxpipestreambuf::seekp(std::streamoff off, std::ios::seekdir dir)
+{
+ if (sync())
+ return;
+
+ if (lseek(fd, off, dir) < 0 && iosp)
+ iosp->setstate(std::ios::badbit);
+ else
+ setg(buffer, buffer+sizeof(buffer), buffer+sizeof(buffer));
+}
+
int afxpipestreambuf::sync()
{
if (fd < 0)
diff -ru courier-0.48.2.orig/courier/submit2.C courier-0.48.2/courier/submit2.C
--- courier-0.48.2.orig/courier/submit2.C 2005-01-26 10:03:49.318271000 -0800
+++ courier-0.48.2/courier/submit2.C 2005-01-26 11:24:10.878229077 -0800
@@ -945,6 +945,9 @@
&SubmitFile::get_msgid_for_filtering, &voidp))
return (1);
+ /* seek to end of file in case file was modified. */
+ ctlfile.seekp(0, std::ios::end);
+
if (!mime || strcmp(mime, "none"))
{
if (mime && strcmp(mime, "7bit") == 0)
