2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
26 * $TOG: Editor.C /main/11 1998/07/24 16:06:00 mgreess $
28 * RESTRICTED CONFIDENTIAL INFORMATION:
30 * The information in this document is subject to special
31 * restrictions in a confidential disclosure agreement between
32 * HP, IBM, Sun, USL, SCO and Univel. Do not distribute this
33 * document outside HP, IBM, Sun, USL, SCO, or Univel without
34 * Sun's specific written approval. This document and all copies
35 * and derivative works thereof must be returned or destroyed at
38 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
43 #include <Xm/RowColumn.h>
44 #include <EUSCompat.h>
53 #include "str_utils.h"
56 : UIComponent("Editor")
65 AbstractEditorParent::AbstractEditorParent() {
66 _attachmentPopupMenu = NULL;
67 _textPopupMenu = NULL;
69 _menuPopupText = NULL;
72 AbstractEditorParent::~AbstractEditorParent()
75 delete _menuPopupText;
79 Editor::set_message(DtMail::Message * msg,
80 char ** status_string,
81 HeaderFormat header_format,
83 BracketFormat brackets)
86 DtMail::Session *m_session = theRoamApp.session()->session();
87 DtMail::MailRc * mail_rc = m_session->mailRc(error);
89 *status_string = NULL;
91 DtMail::Envelope *env = msg->getEnvelope(error);
93 DtMailHeaderHandle hdr_hnd;
97 // Here is not the place for getting the indent string
98 // but it'll do for now.
99 const char *indent_str = NULL;
100 mail_rc->getValue(error, "indentprefix", &indent_str);
102 indent_str = strdup("> ");
108 if (format == IF_BRACKETED) {
112 ins_bracket = GETMSG(DT_catd, 1, 195, "------------- Begin Forwarded Message -------------\n\n");
117 ins_bracket = GETMSG(DT_catd, 1, 196, "------------- Begin Included Message -------------\n\n");
121 append_to_contents(ins_bracket, strlen(ins_bracket));
124 // Code from MsgScrollingList - display_message().
125 // We're trying to reduce heap size by not allocating and
126 // deleting space in every loop iteration. So just have a
127 // fixed size buffer initially.
130 // Initial line size. When not enough, allocate more.
131 int line_size = 1024;
133 char *line = new char[line_size];
136 if (header_format != HF_NONE) {
137 for ( hdr_hnd = env->getFirstHeader(
141 hdr_hnd && !error.isSet();
142 hdr_hnd = env->getNextHeader(
146 value), hdr_num++ ) {
149 if ((header_format == HF_ABBREV)
150 && (hdr_num != 0 || strcmp(name, "From") != 0)) {
152 if (mail_rc->ignore(ierror, name)) {
159 for ( int val = 0; val < value.length(); val++ ) {
160 tmp_count = strlen(name) +
161 strlen(*(value[val])) +
164 if ( tmp_count > line_size ) { // Need to increase line size.
166 line_size = tmp_count;
167 line = new char[line_size];
169 memset(line, 0, line_size);
170 if (format == IF_INDENTED) {
171 strcpy(line, indent_str);
177 if (hdr_num != 0 || strcmp(name, "From") != 0) {
184 strcat(line, *(value[val]));
186 append_to_contents(line, strlen(line));
192 // Don't delete line yet, because it's used below.
194 if (format == IF_INDENTED) {
195 append_to_contents(indent_str, strlen(indent_str));
198 if (header_format != HF_NONE) {
199 append_to_contents("\n", 1);
202 DtMail::BodyPart *bp = msg->getFirstBodyPart(error);
205 DtMailBoolean firstBPHandled = DTM_FALSE;
207 bp->getContents(error, NULL, NULL, &type, NULL, NULL, NULL);
209 char *attr = DtDtsDataTypeToAttributeValue(
213 if ((attr && strcasecmp(attr, "true") == 0)
214 || strcoll(type, DtDTS_DT_UNKNOWN) == 0 ) {
215 const void *contents;
217 bp->lockContents(error, DtMailLockRead);
218 bp->getContents(error, &contents, &size, NULL, NULL, NULL, NULL);
220 if (format == IF_INDENTED) {
222 int content_count = (int) size;
223 const char *last = NULL, *content_ptr = NULL;
224 // Parse the result of getContents().
225 // Spit out indent string with each line.
226 // Is contents NULL terminated???
227 for ( last = (const char *)contents,
228 content_ptr = (const char *)contents;
233 if ((*content_ptr == '\n') ||
234 (content_count == 1) ) {
235 // 2 for null terminator and new line.
236 tmp_count = strlen(indent_str) + byte_count + 2;
237 if ( tmp_count > line_size ) {
238 // Need to increase line size.
240 line_size = tmp_count;
241 line = new char[line_size];
243 memset(line, 0, line_size);
244 strcpy(line, indent_str);
245 strncat(line, last, byte_count + 1);
246 // Copy the '\n' also
247 append_to_contents(line, strlen(line));
248 last = content_ptr + 1;
253 append_to_contents((const char *)contents, size);
255 bp->unlockContents(error);
256 firstBPHandled = DTM_TRUE;
258 DtDtsFreeAttributeValue(attr);
264 // DLP: We will turn off this test for now. We need to study the problem
265 // of text checksums more.
267 //if (bp->checksum(error) == DtMailCheckBad) {
268 // *status_string = GETMSG(DT_catd, 1, -1, "Digital signature did not match.");
273 if (format == IF_BRACKETED) {
277 ins_bracket = GETMSG(DT_catd, 1, 197, "------------- End Forwarded Message -------------\n\n");
282 ins_bracket = GETMSG(DT_catd, 1, 198, "------------- End Included Message -------------\n\n");
286 append_to_contents(ins_bracket, strlen(ins_bracket));
291 if (NULL != indent_str)
292 free((void*) indent_str);
294 return(firstBPHandled);
298 Editor::append_newline_to_contents()
300 append_to_contents("\n", strlen("\n"));
305 Editor::set_attachment(
306 DtMail::BodyPart *bp,
308 BracketFormat brackets)
311 DtMail::Session *m_session = theRoamApp.session()->session();
312 DtMail::MailRc * mail_rc = m_session->mailRc(error);
313 DtMailValueSeq value;
315 char *input, *name, *dttype, *description, *mimetype;
316 const char *indent_str = NULL;
319 if (format == IF_INDENTED)
321 mail_rc->getValue(error, "indentprefix", &indent_str);
323 indent_str = strdup("> ");
327 if ((format == IF_BRACKETED) && (brackets == BF_INCLUDE))
332 "------------- Begin Included Attachment -------------\n\n");
334 append_to_contents(ins_bracket, strlen(ins_bracket));
336 else if (format == IF_INDENTED)
338 append_to_contents(indent_str, strlen(indent_str));
339 append_newline_to_contents();
342 bp->getContents(error, NULL, &len, &dttype, &name, NULL, &description);
344 if ((NULL != name) && (0 != strlen(name)))
346 if (NULL != indent_str)
347 append_to_contents(indent_str, strlen(indent_str));
348 input = GETMSG(DT_catd, 1, 251, " Attachment Name: ");
349 append_to_contents(input, strlen(input));
350 append_to_contents(name, strlen(name));
351 append_newline_to_contents();
354 if ((NULL != dttype) && (0 != strlen(dttype)))
356 if (NULL != indent_str)
357 append_to_contents(indent_str, strlen(indent_str));
358 input = GETMSG(DT_catd, 1, 252, " Attachment DtType: ");
359 append_to_contents(input, strlen(input));
360 append_to_contents(dttype, strlen(dttype));
361 append_newline_to_contents();
364 bp->getContentType(error, &mimetype);
365 if ((NULL != mimetype) && (0 != strlen(mimetype)))
367 if (NULL != indent_str)
368 append_to_contents(indent_str, strlen(indent_str));
369 input = GETMSG(DT_catd, 1, 253, "Attachment ContentType: ");
370 append_to_contents(input, strlen(input));
371 append_to_contents(mimetype, strlen(mimetype));
372 append_newline_to_contents();
375 if ((NULL != description) && (0 != strlen(description)))
377 if (NULL != indent_str)
378 append_to_contents(indent_str, strlen(indent_str));
379 input = GETMSG(DT_catd, 1, 254, "Attachment Description: ");
380 append_to_contents(input, strlen(input));
381 append_to_contents(description, strlen(description));
382 append_newline_to_contents();
385 if ((format == IF_BRACKETED) && (brackets == BF_INCLUDE))
390 "------------- End Included Attachment -------------\n\n");
392 append_to_contents(ins_bracket, strlen(ins_bracket));
394 else if (format == IF_INDENTED)
396 append_to_contents(indent_str, strlen(indent_str));
397 append_newline_to_contents();
401 if (NULL != indent_str)
402 free((void*) indent_str);
406 free((void*) dttype);
407 if (NULL != mimetype)
408 free((void*) mimetype);
409 if (NULL != description)
410 free((void*) description);
414 Editor::update_display_from_props(void)
418 DtMail::Session * d_session = theRoamApp.session()->session();
419 DtMail::MailRc * mailrc = d_session->mailRc(error);
420 const char * value = NULL;
422 mailrc->getValue(error, "popuplines", &value);
424 value = strdup("24");
426 rows = (int) strtol(value, NULL, 10);
431 // If toolcols is set, overwrite the column width with "toolcols" value.
432 // Otherwise, default resource value will be used.
435 mailrc->getValue(error, "toolcols", &value);
437 cols = (int) strtol(value, NULL, 10);
441 * MB_CUR_MAX == 1 : SingleByteLanguage
442 * MB_CUR_MAX > 1 : MultiByteLanguage
444 if ( MB_CUR_MAX == 1 )
454 AbstractEditorParent::postAttachmentPopup(XEvent *event)
456 XmMenuPosition(_attachmentPopupMenu, (XButtonEvent *)event);
457 XtManageChild(_attachmentPopupMenu);
461 AbstractEditorParent::postTextPopup(XEvent *event)
463 if (_textPopupMenu == NULL)
466 XmMenuPosition(_textPopupMenu, (XButtonEvent *)event);
467 XtManageChild(_textPopupMenu);