summaryrefslogtreecommitdiffstats
path: root/rfc2045/rfc2045mkboundary.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 /rfc2045/rfc2045mkboundary.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 'rfc2045/rfc2045mkboundary.c')
-rw-r--r--rfc2045/rfc2045mkboundary.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/rfc2045/rfc2045mkboundary.c b/rfc2045/rfc2045mkboundary.c
new file mode 100644
index 0000000..2d7c159
--- /dev/null
+++ b/rfc2045/rfc2045mkboundary.c
@@ -0,0 +1,72 @@
+/*
+** Copyright 1998 - 2011 Double Precision, Inc. See COPYING for
+** distribution information.
+*/
+
+#if HAVE_CONFIG_H
+#include "rfc2045_config.h"
+#endif
+#include "rfc2045.h"
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include "numlib/numlib.h"
+
+
+#if HAS_GETHOSTNAME
+
+#else
+
+extern int gethostname(char *, size_t);
+#endif
+
+extern void rfc2045_enomem();
+
+char *rfc2045_mk_boundary(struct rfc2045 *s, struct rfc2045src *src)
+{
+char hostnamebuf[256];
+pid_t mypid;
+char pidbuf[NUMBUFSIZE];
+time_t mytime;
+char timebuf[NUMBUFSIZE];
+static size_t cnt=0;
+char cntbuf[NUMBUFSIZE];
+char *p;
+int rc;
+
+ hostnamebuf[sizeof(hostnamebuf)-1]=0;
+ if (gethostname(hostnamebuf, sizeof(hostnamebuf)-1))
+ hostnamebuf[0]=0;
+ mypid=getpid();
+ time(&mytime);
+ libmail_str_pid_t(mypid, pidbuf);
+ libmail_str_time_t(mytime, timebuf);
+ for (;;)
+ {
+ char tempbuf[NUMBUFSIZE];
+
+ libmail_str_size_t(++cnt, tempbuf);
+ sprintf(cntbuf, "%4s", tempbuf);
+ for (p=cntbuf; *p == ' '; *p++ = '0')
+ ;
+ p=malloc(strlen(hostnamebuf)+strlen(pidbuf)
+ +strlen(timebuf)+strlen(cntbuf)+11);
+ if (!p)
+ {
+ rfc2045_enomem();
+ return (NULL);
+ }
+
+ sprintf(p, "=_%-1.30s-%s-%s-%s", hostnamebuf,
+ pidbuf, timebuf, cntbuf);
+ if ((rc=rfc2045_try_boundary(s, src, p)) == 0)
+ break;
+ free(p);
+ if (rc < 0)
+ return (NULL);
+ }
+ return (p);
+}