File: applefile.c

package info (click to toggle)
emil 2.1.0-beta9-5
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,160 kB
  • ctags: 587
  • sloc: ansic: 10,358; yacc: 412; makefile: 329; sh: 182
file content (222 lines) | stat: -rw-r--r-- 5,265 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
** 
** Copyright (C) 1993 Swedish University Network (SUNET)
** 
** 
** This program is developed by UDAC, Uppsala University by commission
** of the Swedish University Network (SUNET). 
** 
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
** 
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITTNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
** 
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
** 
** 
**                                           Martin.Wendel@its.uu.se
** 				             Torbjorn.Wictorin@its.uu.se
** 
**                                           ITS	
**                                           P.O. Box 887
**                                           S-751 08 Uppsala
**                                           Sweden
** 
*/
#include "emil.h"
int
fix_applefile(struct message *m)
{
  struct message *mt;
#ifdef DEBUG
  if (edebug)
    fprintf(stderr, "*  fix_applefile: ");
#endif
  if (check_apple_target(m->sd) == OK)
    {
#ifdef DEBUG
      if (edebug)
	fprintf(stderr, "keeping.\n");
#endif
      return(NOK);
    }
#ifdef DEBUG
  if (edebug)
    fprintf(stderr, "processing... ");
#endif

  if (to_applefile(m) != OK)
    {
#ifdef DEBUG
      if (edebug)
	fprintf(stderr, "FAILED.\n");
#endif
      m->sd->applefile = 0;
      return(NOK);
    }
  switch(target->iapple)
    {
    case ABINHEX:
      if (encode_binhex(m) != OK)
	return(NOK);
      break;
    case ASINGLE:
      if (put_applesingle(m) != OK)
	return(NOK);
      break;
    case ADOUBLE:
      if (put_appledouble(m) != OK)
	return(NOK);
      mt = (struct message *)Yalloc(sizeof(struct message));
      mt->sd = m->sd;
      mt->td = m->td;
      mt->sdl = m->sdl;
      mt->tdl = m->tdl;
      mt->level = m->level + 1;
      
      m->sd = (struct data *)Yalloc(sizeof(struct data));
      m->sd->encoding = EMULTI;
      m->td = m->sd;
      m->child = mt;
      mt->parent = m;
      m->child = (struct message *)split_data_list(m->child);
      m->child->sibling->sd->type = m->child->sd->type;
      m->child->sibling->sd->name = m->child->sd->name;
      m->child->sd->name = (char *)Yalloc(strlen(m->child->sd->name) + 2);
      sprintf(m->child->sd->name, "%%%s", m->child->sibling->sd->name);
      m->sd->type = NEWSTR("MULTIPART");
      m->sd->applefile = AMDOUBLE;
      m->child->sd->type = NEWSTR("APPLESINGLE");
      break;
    default:
#ifdef DEBUG
      if (edebug)
	fprintf(stderr, "FAILED.\n");
#endif
      return(NOK);
      break;
    }
#ifdef DEBUG
  if (edebug)
    fprintf(stderr, "SUCCEEDED.\n");
#endif
  return(OK);
}

int
to_applefile(struct message *m)
{
  struct data *d;
  switch(m->sd->applefile)
    {
    case ABINHEX:
      if (decode_binhex(m) == OK)
	return(OK);
      else
	return(NOK);
      break;
    case AMDOUBLE:
      if (decode_double(m->child) != OK)
	return(NOK);
      if (get_appledouble_binary(m->child) != OK)
	return(NOK);
      m->td = m->child->sibling->td;
      m->td->next = m->child->td;
      m->sd->applefile = AFILE;
      m->sd->appletype = m->child->sd->appletype;
      m->sd->name = m->child->sd->name;
      m->td->next->applefile = ARESOURCE;
      m->child = NULL;
      return(OK);
      break;
    case ADOUBLE:
      if (decode_double(m) != OK)
	return(NOK);
      if (get_appledouble_binary(m) != OK)
	return(NOK);
      d = m->td;
      m->td = m->sibling->td;
      m->td->next = d;
      m->td->applefile = AFILE;
      m->td->next->applefile = ARESOURCE;
      m->sibling = m->sibling->sibling;
      return(OK);
      break;
    case ASINGLE:
      if (decode_enc(m) != OK)
	return(NOK);
      if (get_applesingle_binary(m) != OK)
	return(NOK);
      else
	return(OK);
      break;
    case AFILE:
      return(OK);
      break;
    case AMFILE:
      m->td = m->child->sibling->td;
      m->td->next = m->child->td;
      m->td->applefile = AFILE;
      m->td->next->applefile = ARESOURCE;
      m->child = NULL;
      return(OK);
      break;
    default:
#ifdef DEBUG
      if (edebug)
	fprintf(stderr, "UNKNOWN applefile type.\n");
#endif
      return(NOK);
      break;
    }
  return(NOK);
}

int
decode_double(struct message *m)
{
#ifdef DEBUG
  if (edebug)
    fprintf(stderr, "*   decode_double\n");
#endif
  if (m->sibling == NULL)

    return(NOK);

  if (decode_enc(m) != OK)
    return(NOK);
  if (decode_enc(m->sibling) != OK)
    return(NOK);
  return(OK);
}

int
decode_enc(struct message *m)
{
  m->td->offset = m->td->bodystart;
  switch(m->td->encoding)
    {
    case EUUENCODE:
      return(decode_uuencode(m));
      break;
    case EBASE64:
      return(decode_base64(m));
      break;
    case EBINHEX:
      return(decode_binhex(m));
      break;
    case EQP:
      return(decode_quoted_printable(m));
      break;
    default:
      return(NOK);
    }
}