コード例 #1
0
ファイル: status.c プロジェクト: weechatter/simplemail
static char *status_get_time_str(void)
{
	static char time_buf[64];
	int time = estimate_calc_remaining(&gauge_est,gauge_value/1024);

	if (time < 60) sm_snprintf(time_buf,sizeof(time_buf),_("%d s"),time);
	else sm_snprintf(time_buf,sizeof(time_buf),_("%d min %d s"),time/60,time%60);

	return time_buf;
}
コード例 #2
0
ファイル: archdebug.c プロジェクト: weechatter/simplemail
/**
 * Turns the backtrace into a string that can be displayed
 *
 * @param bt
 * @return
 */
char *arch_debug_bt2string(struct bt *bt)
{
#if defined(__SASC) && defined(DEBUG_RESTRACK)
	string str;
	char buf[120];
	int i;
	int last_line = -1;
	char *last_file = NULL;

	if (!bt) return NULL;

	if (!(string_initialize(&str,200)))
		return NULL;

	/* Load debug infos if not done yet */
	arch_debug_load();

	string_append(&str,"Backtrace\n");

	for (i=0;i<bt->addr_used;i++)
	{
		ULONG offset = (ULONG)bt->addr[i] - (ULONG)__code_base;

		sm_snprintf(buf,sizeof(buf),"\t\t%p (offset %p",bt->addr[i],offset);
		string_append(&str,buf);


		if (debug_info_count > 0)
		{
			struct debug_info *di;
			int offset = (ULONG)bt->addr[i] - (ULONG)__code_base;

			BIN_SEARCH(debug_info_array, 0, debug_info_count-1,
					(debug_info_array[m].offset <= offset) ?
					(offset < debug_info_array[m+1].offset?0:(1)):(-1),
					di);

			if (di && (di->filename != last_file || di->line != last_line))
			{
				string_append(&str,", ");
				sm_snprintf(buf,sizeof(buf),"%s/%d",di->filename,di->line);
				string_append(&str,buf);
				last_file = di->filename;
				last_line = di->line;
			}
		}

		string_append(&str,")\n");
	}

	return str.str;
#else
	return NULL;
#endif
}
コード例 #3
0
ファイル: status.c プロジェクト: weechatter/simplemail
/******************************************************************
 Returns the status text
*******************************************************************/
static char *status_get_status(char *msg)
{
	static char buf[128];
	static char time_buf[64];

	int time = estimate_calc_remaining(&gauge_est,gauge_value/1024);
	if (time < 60) sm_snprintf(time_buf,sizeof(time_buf),_("%d s"),time);
	else sm_snprintf(time_buf,sizeof(time_buf),_("%d min %d s"),time/60,time%60);

	if (msg) sm_snprintf(buf,sizeof(buf),"%s\n%s %s",msg,_("Time remaining:"),time_buf);
	else return time_buf;
	return buf;
}
コード例 #4
0
ファイル: text2html.c プロジェクト: sba1/simplemail
static int write_unicode(utf8 *src, string *str)
{
	int len;
	char buf[16];

	len = strlen(src);

	while (len > 0)
	{
		unsigned char c;

		c = *src;

		if (c > 127)
		{
			unsigned int iso = 0;
			int advance = utf8tochar(src, &iso, user.config.default_codeset);
			if (iso == 0) iso = '_';

			sm_snprintf(buf,sizeof(buf),"&#%d;",iso);
			string_append(str,buf);

			len -= advance;
			src += advance;
		} else
		{
			string_append_part(str,(char*)&c,1);
			src++;
			len--;
		}
	}
	return 1;
}
コード例 #5
0
ファイル: arexx.c プロジェクト: sba1/simplemail
/**
 * Returns the version of SimpleMail.
 *
 * @param rxmsg the message defining the ARexx context
 * @param args the command's arguments
 */
static void arexx_version(struct RexxMsg *rxmsg, STRPTR args)
{
	APTR arg_handle;

	struct
	{
		ULONG date;
	} version_arg;
	char buf[24];

	memset(&version_arg,0,sizeof(version_arg));

	if ((arg_handle = ParseTemplate("DATE/S",args,&version_arg)))
	{
		if (version_arg.date)
		{
			arexx_set_result(rxmsg, SIMPLEMAIL_DATE);
		} else
		{
			sm_snprintf(buf,sizeof(buf), "%d.%d",VERSION,REVISION);
			arexx_set_result(rxmsg, buf);
		}
		FreeTemplate(arg_handle);
	}
}
コード例 #6
0
ファイル: status.c プロジェクト: weechatter/simplemail
/******************************************************************
 Sets the gauge current value
*******************************************************************/
void status_set_gauge(int value)
{
	static char status_buf[100];
	static char gauge_buf[256];
	static int last_seconds;
	int seconds = sm_get_current_seconds();

	gauge_value = value;

	if (last_seconds == seconds) return;

	sm_snprintf(gauge_buf,sizeof(gauge_buf),_("%d KB / %d KB (time left: %s)"), gauge_value / 1024, gauge_maximal / 1024, status_get_time_str());

	statuswnd_set_gauge(value);
	statuswnd_set_gauge_text(gauge_buf);

	sm_snprintf(status_buf,sizeof(status_buf),_("Processing mail %d (%d KB) of %d"),mail_current,mail_current_size / 1024, mail_maximal);
	statuswnd_set_status(status_buf);

	last_seconds = seconds;
}
コード例 #7
0
ファイル: readwnd.c プロジェクト: sba1/simplemail
int read_window_open(const char *folder, struct mail_info *mail, int window)
{
	int w, h;
	char buf[256];

	getmaxyx(stdscr, h, w);
	h -= 2;

	if (!read_wnd)
	{
		read_wnd = newwin(h, w, 0, 0);
		read_panel = new_panel(read_wnd);
		show_panel(read_panel);
	} else
	{
		show_panel(read_panel);
		update_panels();
		doupdate();
	}

	gui_add_resize_listener(&resize_listener, read_window_resize, NULL);
	resize_listener_added = 1;

	if (read_current_mail)
	{
		mail_complete_free(read_current_mail);
	}

	getcwd(buf, sizeof(buf));
	chdir(folder);

	if ((read_current_mail = mail_complete_create_from_file(NULL, mail->filename)))
	{
		struct mail_complete *initial;
		mail_read_contents(NULL,read_current_mail);
		if ((initial = mail_find_initial(read_current_mail)))
		{
			char buf[380];
			utf8 *from_phrase = mail_info_get_from_phrase(read_current_mail->info);
			utf8 *from_addr = mail_info_get_from_addr(read_current_mail->info);
			if (from_phrase)
			{
				sm_snprintf(buf, sizeof(buf), "%s: %s <%s>", _("From"), from_phrase, from_addr);
			} else
			{
				sm_snprintf(buf, sizeof(buf), "%s: %s", _("From"), from_addr);
			}
			gadgets_init_simple_text_label(&from_label, buf);

			sm_snprintf(buf, sizeof(buf), "%s: %s", _("Date"), sm_get_date_str(read_current_mail->info->seconds));
			gadgets_init_simple_text_label(&date_label, buf);

			sm_snprintf(buf, sizeof(buf), "%s: %s", _("Subject"), read_current_mail->info->subject);
			gadgets_init_simple_text_label(&subject_label, buf);

			mail_decode(initial);

			gadgets_init_group(&read_group);
			gadgets_init_text_view(&text_view, initial->decoded_data);

			gadgets_add(&read_group, &from_label.tl.g);
			gadgets_add(&read_group, &date_label.tl.g);
			gadgets_add(&read_group, &subject_label.tl.g);
			gadgets_add(&read_group, &text_view.tl.tl.g);

			read_window_layout();

			gadgets_display(read_wnd, &read_group.g);
		}
	} else
	{
		SM_DEBUGF(20, ("Unable to create mail \"%s\"\n", mail->filename));
	}

	chdir(buf);

	gui_add_key_listener(&close_listener, 'c', "Close", read_window_close_current);
	refresh();

	wrefresh(read_wnd);

	return 1;
}
コード例 #8
0
ファイル: text2html.c プロジェクト: sba1/simplemail
char *text2html(unsigned char *buffer, int buffer_len, int flags, const char *fonttag)
{
	unsigned char *saved_buffer = buffer;
	string str;

	if (string_initialize(&str,1024))
	{
		char buf[512];
		int last_color = 0; /* the color of the current line */
		int eval_color = 2; /* recheck the color */
		int initial_color = 1;
		int level = 0;
		int line = 0; /* the type of the line */

		if (flags & TEXT2HTML_BODY_TAG)
		{
			sm_snprintf(buf,sizeof(buf),"<BODY BGCOLOR=\"#%06x\" TEXT=\"#%06x\" LINK=\"#%06x\">",user.config.read_background,user.config.read_text,user.config.read_link);
			string_append(&str,buf);
		}
		string_append(&str,fonttag); /* accepts NULL pointer */

		/* check for >0, otherwise we'll be in an endless loop if buffer_len becomes <0 */
		while (buffer_len > 0)
		{
			if (eval_color)
			{
				int new_level = 0;
				int buffer2_len = buffer_len;
				unsigned char *buffer2 = buffer;
				int new_color = 0;

				/* Determine the citation level. Afterwards, buffer2 will point to the end of the citation symbols. */
				while (buffer2_len)
				{
					unsigned char c = *buffer2;
					if (c == '>')
					{
						new_level++;
						if (new_color == 1) new_color = 2;
						else new_color = 1;
					} else
					{
						if (c != ' ') break;
						if (c == ' ' && !new_level) break;
					}
					buffer2_len--;
					buffer2++;
				}

				if (user.config.read_graphical_quote_bar)
				{
					/* When graphical quote bar is enabled we skip all quotation symbols */
					buffer = buffer2;
					buffer_len = buffer2_len;

					if (level != new_level)
					{
						const char *begin_quote_string = "<TABLE BGCOLOR=\"#%06x\" WIDTH=\"100%%\" STYLE=\"border-left: 3px solid #%06x; border-right: 3px solid #%06x;\"><TD><FONT COLOR=\"#%06x\">";
						const char *end_quote_string = "</FONT></TD></TABLE>";

						/* If new level is larger */
						for (;level < new_level; level++)
						{
							unsigned int color = level%2?user.config.read_quoted:user.config.read_old_quoted;
							sm_snprintf(buf,sizeof(buf),begin_quote_string,user.config.read_quoted_background,color,color,color);
							string_append(&str,buf);
						}

						/* If new level is lower */
						for (;level > new_level; level--)
							string_append(&str,end_quote_string);
					}
				} else
				{
					if (last_color != new_color)
					{
						const char *begin_quote_string = "<FONT COLOR=\"#%x\">";
						const char *end_quote_string = "</FONT>";

						if (!initial_color) string_append(&str,end_quote_string);
						if (new_color == 1)
						{
							sm_snprintf(buf,sizeof(buf),begin_quote_string,user.config.read_quoted);
							string_append(&str,buf);
						}
						else if (new_color == 2)
						{
							sm_snprintf(buf,sizeof(buf),begin_quote_string,user.config.read_old_quoted);
							string_append(&str,buf);
						}
						last_color = new_color;
						if (new_color) initial_color = 0;
						else initial_color = 1;
					}
				}
				eval_color = 0;
			}

			if (!mystrnicmp("http:",(char*)buffer,5)) write_uri(&buffer, &buffer_len, &str);
			else if (!mystrnicmp("mailto:",(char*)buffer,7)) write_uri(&buffer, &buffer_len, &str);
			else if (!mystrnicmp("ftp:",(char*)buffer,4)) write_uri(&buffer, &buffer_len, &str);
			else if (!mystrnicmp("https:",(char*)buffer,6)) write_uri(&buffer, &buffer_len, &str);
			else
			{
				unsigned char c;

				c = *buffer;

				if ((c == '@') && (buffer > saved_buffer))
				{
					/* A @ has been encountered, check if this belongs to an email adresse by traversing back
           * within the string */

					unsigned char *buffer2 = buffer - 1;
					unsigned char *buffer3;
					unsigned char c2;
					int buffer2_len = buffer_len + 1;
					char *address;

					while ((c2 = *buffer2) && buffer2 > saved_buffer)
					{
						static const char noaliaschars[] = {
							" ()<>@,;:\\\"[]\n\r"};

						if (strchr(noaliaschars,c2))
						{
							buffer2++;
							break;
						}
						buffer2_len++;
						buffer2--;
					}

					if ((buffer3 = (unsigned char*)parse_addr_spec((char*)buffer2, &address)))
					{
						int email_len;

						/* crop the string to the beginning of the email address */
						string_crop(&str,0,str.len - (buffer - buffer2));

						buffer_len += buffer - buffer2;
						buffer -= buffer - buffer2;
						email_len = buffer3 - buffer;
						buffer_len -= email_len;

						buffer = buffer3;

						sm_snprintf(buf,sizeof(buf),"<A HREF=\"mailto:%s\"%s>",address, user.config.read_link_underlined?"":" STYLE=\"TEXT-DECORATION: none\"");
						string_append(&str,buf);
						write_unicode(address,&str);
						string_append(&str,"</A>");
						free(address);
						continue;
					}
				}

		  	if (user.config.read_smilies)
		  	{
		  		unsigned int i;
		  		int smily_used = 0;
			  	/* No look into the smily table, this is slow and needs to be improved */
		  		for (i=0;i<sizeof(smily)/sizeof(struct smily);i++)
		  		{
		  			if (!strncmp(smily[i].ascii,(char*)buffer,strlen(smily[i].ascii)))
		  			{
		  				buffer += strlen(smily[i].ascii);
		  				buffer_len -= strlen(smily[i].ascii);
		  				sm_snprintf(buf,sizeof(buf),"<IMG SRC=\"PROGDIR:Images/%s\" VALIGN=\"middle\" ALT=\"%s\">",smily[i].gfx,smily[i].ascii);
		  				string_append(&str,buf);
		  				smily_used = 1;
		  			}
		  		}
		  		if (smily_used) continue;
		  	}

				if (!strncmp("\n<sb>",(char*)buffer,5))
				{
					if (line) string_append(&str,"<BR></TD><TD WIDTH=\"50%\"><HR></TD></TR></TABLE>");
					line = 1;
					buffer += 5;
					buffer_len -= 5;

					string_append(&str,"<TABLE WIDTH=\"100%\" BORDER=\"0\"><TR><TD VALIGN=\"middle\" WIDTH=\"50%\"><HR></TD><TD>");
					continue;
				}

				if (!strncmp("\n<tsb>",(char*)buffer,6))
				{
					if (line) string_append(&str,"<BR></TD><TD WIDTH=\"50%\"><HR></TD></TR></TABLE>");
					line = 2;
					buffer += 6;
					buffer_len -= 6;

					string_append(&str,"<TABLE WIDTH=\"100%\" BORDER=\"0\"><TR><TD VALIGN=\"middle\" WIDTH=\"50%\"><HR></TD><TD>");
					continue;
				}

				if (c < 128)
				{
					buffer++;
					buffer_len--;
					if (c== '<') string_append(&str,"&lt;");
					else if (c== '>') string_append(&str,"&gt;");
					else if (c== '&') string_append(&str,"&amp;");
					else if (c == 10)
					{
						eval_color = 1;
						string_append(&str,"<BR>\n");
						if (line)
						{
							string_append(&str,"</TD><TD WIDTH=\"50%\"><HR></TD></TR></TABLE>");
							line = 0;
						}
					} else
					{
						if (c == 32) {
							if (*buffer == 32 || (flags & TEXT2HTML_NOWRAP)) string_append(&str,"&nbsp;");
							else string_append(&str," ");
						} else {
						  if (c)
						  {
						  	string_append_part(&str,(char*)&c,1);
						  }
						}
					}
				} else
				{
					unsigned int unicode;
					int len = 0;
					/* check if it really could be a utf8 char */
					if (utf8islegal((utf8*)buffer, (utf8*)(buffer+buffer_len)))
					{
						len = utf8tochar((utf8*)buffer, &unicode, user.config.default_codeset);
					}
					if ((len == 0) || (len > buffer_len))
					{
						/* something wrong with that utf8 sequence */
						unicode = '?';
						len = 1;
					}
					buffer_len -= len;
					buffer += len;

					if (unicode == 0) unicode = '_';
					sm_snprintf(buf,sizeof(buf),"&#%d;",unicode);
					string_append(&str,buf);
				}
			}
		}

		if (fonttag) string_append(&str,"</FONT>");

		if (flags & TEXT2HTML_ENDBODY_TAG) string_append(&str,"</BODY>");

		SM_DEBUGF(20,("%s\n",str.str));

		return str.str;
	}
	return NULL;
}
コード例 #9
0
ファイル: status.c プロジェクト: weechatter/simplemail
/******************************************************************
 Set the status line for connecting to a server
*******************************************************************/
void status_set_connect_to_server(char *server)
{
	static char buf[80];
	sm_snprintf(buf,sizeof(buf),_("Connecting to server %s..."),server);
	statuswnd_set_status(buf);
}