Esempio n. 1
0
File: CDoc.cpp Progetto: diversys/pe
CDoc::CDoc(const char* mimetype, BLooper *target, const entry_ref *doc)
	: fDocIO(NULL)
	, fSavePanel(NULL)
	, fMimeType(mimetype ? mimetype : "")
	, fDirty(false)
	, fReadOnly(false)
	, fEncoding(B_UNICODE_UTF8)
	, fLineEndType(kle_LF)
{
	fDocIO = new CLocalDocIO(this, doc, target);
	FailNil(fDocIO);
	if (doc)
	{
		BEntry e;
		FailOSErr(e.SetTo(doc, true));
		FailOSErr(e.GetParent(&gCWD));

		BNode node;
		FailOSErr(node.SetTo(doc));

		struct stat st;
		FailOSErr(node.GetStat(&st));

		fReadOnly = !((gUid == st.st_uid && (S_IWUSR & st.st_mode))
						||	(gGid == st.st_gid && (S_IWGRP & st.st_mode))
						||	(S_IWOTH & st.st_mode));

		char s[NAME_MAX];
		if (BNodeInfo(&node).GetType(s) == B_OK)
			fMimeType = s;
	}
	sfDocList.push_back(this);
}
Esempio n. 2
0
File: CDoc.cpp Progetto: diversys/pe
void CDoc::SetMimeType(const char *type, bool updateOnDisk)
{
	fMimeType = type;

	if (updateOnDisk && EntryRef())
	{
		BNode node;
		FailOSErr(node.SetTo(EntryRef()));
		FailOSErr(BNodeInfo(&node).SetType(type));
	}
}
Esempio n. 3
0
/*
AttributeDumper::AttributeDumper(node_ref* nref) {

		BDirectory *fDir = new BDirectory(nref);
		fNode = fDir;
}
*/
AttributeDumper::AttributeDumper(entry_ref* ref,bool asdir){

	fNode = NULL;
	
	//new name
	BString filename;
	filename << real_time_clock_usecs();
	//
		
	BDirectory dir(ref);

	fPath.SetTo(&dir,NULL);
	fPath.Append(filename.String());
	
	if(!asdir)
	{

		BFile *fFile = new BFile(fPath.Path(),B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
		fNode = fFile;
		
		BNodeInfo(fNode).SetType(MIME_ITEM);
		
		get_ref_for_path(fPath.Path(),&fRef);
	}
	else
	{
		BDirectory *fDir = new BDirectory(dir);
		dir.CreateDirectory(fPath.Path(),fDir);
		fNode = fDir;
		
		BNodeInfo(fNode).SetType(MIME_CHANNEL);
		
		printf("New directory Path [%s]\n",fPath.Path());
		
		get_ref_for_path(fPath.Path(),&fRef);
	}
	
	
}
Esempio n. 4
0
bool
BPrinter::IsValid() const
{
	BDirectory spoolDir(&fPrinterEntryRef);
	if (spoolDir.InitCheck() != B_OK)
		return false;

	BNode node(spoolDir);
	char type[B_MIME_TYPE_LENGTH];
	BNodeInfo(&node).GetType(type);

	if (strcmp(type, PSRV_PRINTER_MIMETYPE) != 0)
		return false;

	return true;
}
Esempio n. 5
0
void
DeskbarView::_CreateNewMailQuery(BEntry& query)
{
	BFile file(&query, B_READ_WRITE | B_CREATE_FILE);
	if (file.InitCheck() != B_OK)
		return;

	BString string("((" B_MAIL_ATTR_READ "<2)&&((BEOS:TYPE=="
		"\"text/x-email\")||(BEOS:TYPE==\"text/x-partial-email\")))");
	file.WriteAttrString("_trk/qrystr", &string);
	file.WriteAttrString("_trk/qryinitstr", &string);
	int32 mode = 'Fbyq';
	file.WriteAttr("_trk/qryinitmode", B_INT32_TYPE, 0, &mode, sizeof(int32));
	string = "E-mail";
	file.WriteAttrString("_trk/qryinitmime", &string);
	BNodeInfo(&file).SetType("application/x-vnd.Be-query");
}
Esempio n. 6
0
bool
DeskbarView::_CreateMenuLinks(BDirectory& directory, BPath& path)
{
	status_t status = directory.SetTo(path.Path());
	if (status == B_OK)
		return true;

	// Check if the directory has to be created (and do it in this case,
	// filling it with some standard links).  Normally the installer will
	// create the directory and fill it with links, so normally this doesn't
	// get used.

	BEntry entry(path.Path());
	if (status != B_ENTRY_NOT_FOUND
		|| entry.GetParent(&directory) < B_OK
		|| directory.CreateDirectory(path.Leaf(), NULL) < B_OK
		|| directory.SetTo(path.Path()) < B_OK)
		return false;

	BPath targetPath;
	find_directory(B_USER_DIRECTORY, &targetPath);
	targetPath.Append("mail/in");

	directory.CreateSymLink("Open Inbox Folder", targetPath.Path(), NULL);
	targetPath.GetParent(&targetPath);
	directory.CreateSymLink("Open Mail Folder", targetPath.Path(), NULL);

	// create the draft query

	BFile file;
	if (directory.CreateFile("Open Draft", &file) < B_OK)
		return true;

	BString string("MAIL:draft==1");
	file.WriteAttrString("_trk/qrystr", &string);
	string = "E-mail";
	file.WriteAttrString("_trk/qryinitmime", &string);
	BNodeInfo(&file).SetType("application/x-vnd.Be-query");

	return true;
}
Esempio n. 7
0
void CMimeBox::MessageReceived(BMessage *msg)
{
	char t[NAME_MAX];
		
	if (msg->WasDropped())
	{
		if (msg->HasString("mimeSignature"))
		{
			const char *m;
			ssize_t s;
			
			msg->FindData("mimeSignature", B_STRING_TYPE, (const void**)&m, &s);
			strncpy(t, m, s);
			t[s] = 0;
			AddType(t);
		}
		else if (msg->HasRef("refs"))
		{
			entry_ref ref;
			int32 i = 0;
			
			while (msg->FindRef("refs", i++, &ref) == B_OK)
			{
				BNode n(&ref);
				BNodeInfo(&n).GetType(t);
				AddType(t);
			}
		}
	}
	
	switch (msg->what)
	{
		case msg_MimeChanged:
		{
			bool valid = BMimeType::IsValid(fEdit->Text());
			fAdd->SetEnabled(valid);
			fChange->SetEnabled(valid);
			break;
		}

		case msg_MimeFind:
			if (fPanel) fPanel->Show();
			else
			{
				fPanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(this),
					NULL, B_FILE_NODE, true, new BMessage(msg_MimeFound));
				fPanel->SetButtonLabel(B_DEFAULT_BUTTON, "Pick");
				fPanel->Show();
			}
			break;

		case msg_MimeFound:
		{
			delete fPanel;
			fPanel = NULL;
			
			entry_ref ref;
			int32 i = 0;
			
			while (msg->FindRef("refs", i++, &ref) == B_OK)
			{
				BNode n(&ref);
				BNodeInfo(&n).GetType(t);
				AddType(t);
			}
			break;
		}

		default:
			CListBox::MessageReceived(msg);
			break;
	}
} /* CMimeBox::MessageReceived */
Esempio n. 8
0
status_t
BEmailMessage::RenderToRFC822(BPositionIO *file)
{
	if (_body == NULL)
		return B_MAIL_INVALID_MAIL;

	// Do real rendering

	if (From() == NULL) {
		// set the "From:" string
		SendViaAccount(_account_id);
	}

	BList recipientList;
	get_address_list(recipientList, To(), extract_address);
	get_address_list(recipientList, CC(), extract_address);
	get_address_list(recipientList, _bcc, extract_address);

	BString recipients;
	for (int32 i = recipientList.CountItems(); i-- > 0;) {
		char *address = (char *)recipientList.RemoveItem((int32)0);

		recipients << '<' << address << '>';
		if (i)
			recipients << ',';

		free(address);
	}

	// add the date field
	int32 creationTime = time(NULL);
	{
		char date[128];
		struct tm tm;
		localtime_r(&creationTime, &tm);

		size_t length = strftime(date, sizeof(date),
			"%a, %d %b %Y %H:%M:%S", &tm);

		// GMT offsets are full hours, yes, but you never know :-)
		snprintf(date + length, sizeof(date) - length, " %+03d%02d",
			tm.tm_gmtoff / 3600, (tm.tm_gmtoff / 60) % 60);

		SetHeaderField("Date", date);
	}

	// add a message-id

	// empirical evidence indicates message id must be enclosed in
	// angle brackets and there must be an "at" symbol in it
	BString messageID;
	messageID << "<";
	messageID << system_time();
	messageID << "-BeMail@";

	char host[255];
	if (gethostname(host, sizeof(host)) < 0 || !host[0])
		strcpy(host, "zoidberg");

	messageID << host;
	messageID << ">";

	SetHeaderField("Message-Id", messageID.String());

	status_t err = BMailComponent::RenderToRFC822(file);
	if (err < B_OK)
		return err;

	file->Seek(-2, SEEK_CUR);
		// Remove division between headers

	err = _body->RenderToRFC822(file);
	if (err < B_OK)
		return err;

	// Set the message file's attributes.  Do this after the rest of the file
	// is filled in, in case the daemon attempts to send it before it is ready
	// (since the daemon may send it when it sees the status attribute getting
	// set to "Pending").

	if (BFile *attributed = dynamic_cast <BFile *>(file)) {
		BNodeInfo(attributed).SetType(B_MAIL_TYPE);

		attributed->WriteAttrString(B_MAIL_ATTR_RECIPIENTS,&recipients);

		BString attr;

		attr = To();
		attributed->WriteAttrString(B_MAIL_ATTR_TO,&attr);
		attr = CC();
		attributed->WriteAttrString(B_MAIL_ATTR_CC,&attr);
		attr = Subject();
		attributed->WriteAttrString(B_MAIL_ATTR_SUBJECT,&attr);
		attr = ReplyTo();
		attributed->WriteAttrString(B_MAIL_ATTR_REPLY,&attr);
		attr = From();
		attributed->WriteAttrString(B_MAIL_ATTR_FROM,&attr);
		if (Priority() != 3 /* Normal is 3 */) {
			sprintf (attr.LockBuffer (40), "%d", Priority());
			attr.UnlockBuffer(-1);
			attributed->WriteAttrString(B_MAIL_ATTR_PRIORITY,&attr);
		}
		attr = "Pending";
		attributed->WriteAttrString(B_MAIL_ATTR_STATUS, &attr);
		attr = "1.0";
		attributed->WriteAttrString(B_MAIL_ATTR_MIME, &attr);

		attributed->WriteAttr(B_MAIL_ATTR_ACCOUNT, B_INT32_TYPE, 0,
			&_account_id, sizeof(int32));

		attributed->WriteAttr(B_MAIL_ATTR_WHEN, B_TIME_TYPE, 0, &creationTime,
			sizeof(int32));
		int32 flags = B_MAIL_PENDING | B_MAIL_SAVE;
		attributed->WriteAttr(B_MAIL_ATTR_FLAGS, B_INT32_TYPE, 0, &flags,
			sizeof(int32));

		attributed->WriteAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0,
			&_account_id, sizeof(int32));
	}

	return B_OK;
}