summaryrefslogtreecommitdiffstats
path: root/maildrop/rematchmsg.C
diff options
context:
space:
mode:
authorSam Varshavchik2013-08-19 16:39:41 -0400
committerSam Varshavchik2013-08-25 14:43:51 -0400
commit9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch)
tree7a81a04cb51efb078ee350859a64be2ebc6b8813 /maildrop/rematchmsg.C
parenta9520698b770168d1f33d6301463bb70a19655ec (diff)
downloadcourier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2
Initial checkin
Imported from subversion report, converted to git. Updated all paths in scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'maildrop/rematchmsg.C')
-rw-r--r--maildrop/rematchmsg.C86
1 files changed, 86 insertions, 0 deletions
diff --git a/maildrop/rematchmsg.C b/maildrop/rematchmsg.C
new file mode 100644
index 0000000..eabc2d3
--- /dev/null
+++ b/maildrop/rematchmsg.C
@@ -0,0 +1,86 @@
+#include "config.h"
+#include "rematchmsg.h"
+#include "message.h"
+#include <ctype.h>
+
+
+ReMatchMsg::ReMatchMsg(Message *m, int flag, int flag2)
+ : msg(m), header_only(flag), mergelines(flag2), eof(0),
+ lastc(0), end_headers(0)
+{
+ start=msg->tell();
+}
+
+ReMatchMsg::~ReMatchMsg()
+{
+}
+
+int ReMatchMsg::CurrentChar()
+{
+ if (eof) return (-1);
+ return (msg->peek());
+}
+
+int ReMatchMsg::NextChar()
+{
+ if (eof) return (-1);
+
+int c;
+
+ for (;;)
+ {
+ c=msg->get_c();
+
+ if (c < 0)
+ {
+ eof=1;
+ if (lastc != '\n')
+ {
+ c='\n';
+ lastc='\n';
+ }
+ return (c);
+ }
+
+ if (c == '\r') continue; // Eat carriage returns.
+
+ if (c == '\n')
+ {
+ int nextc=msg->peek();
+
+ if (nextc == '\r' || nextc == '\n')
+ {
+ if (mergelines)
+ end_headers=msg->tell();
+ mergelines=0;
+ if (header_only) eof=1;
+ return (c);
+ }
+ if (mergelines && isspace(nextc)) continue;
+ }
+ lastc=c;
+ return (c);
+ }
+}
+
+off_t ReMatchMsg::GetCurrentPos()
+{
+ return (msg->tell());
+}
+
+void ReMatchMsg::SetCurrentPos(off_t p)
+{
+ if (p < msg->tell()) eof=0;
+ if ( p < start || p == 0)
+ {
+ msg->seek(start);
+ lastc=0;
+ }
+ else
+ {
+ msg->seek(p-1);
+ lastc=msg->get_c();
+ }
+ if (p < end_headers) mergelines=1;
+ if (!mergelines && header_only) eof=1;
+}